-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_https_fn.py
More file actions
69 lines (50 loc) · 1.55 KB
/
test_https_fn.py
File metadata and controls
69 lines (50 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Tests for the https module.
"""
import unittest
from unittest.mock import Mock
from flask import Flask, Request
from werkzeug.test import EnvironBuilder
from firebase_functions import core, https_fn
class TestHttps(unittest.TestCase):
"""
Tests for the http module.
"""
def test_on_request_calls_init_function(self):
app = Flask(__name__)
hello = None
@core.init
def init():
nonlocal hello
hello = "world"
func = Mock(__name__="example_func")
with app.test_request_context("/"):
environ = EnvironBuilder(
method="POST",
json={
"data": {"test": "value"},
},
).get_environ()
request = Request(environ)
decorated_func = https_fn.on_request()(func)
decorated_func(request)
self.assertEqual(hello, "world")
def test_on_call_calls_init_function(self):
app = Flask(__name__)
hello = None
@core.init
def init():
nonlocal hello
hello = "world"
func = Mock(__name__="example_func")
with app.test_request_context("/"):
environ = EnvironBuilder(
method="POST",
json={
"data": {"test": "value"},
},
).get_environ()
request = Request(environ)
decorated_func = https_fn.on_call()(func)
decorated_func(request)
self.assertEqual("world", hello)