File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -438,7 +438,7 @@ def on_request_wrapped(request: Request) -> Response:
438438 return _cross_origin (
439439 methods = options .cors .cors_methods ,
440440 origins = options .cors .cors_origins ,
441- )(func )(request )
441+ )(_core . _with_init ( func ) )(request )
442442 return _core ._with_init (func )(request )
443443
444444 _util .set_func_endpoint_attr (
Original file line number Diff line number Diff line change 99from werkzeug .test import EnvironBuilder
1010
1111from firebase_functions import core , https_fn
12+ from firebase_functions .options import CorsOptions
1213
1314
1415class TestHttps (unittest .TestCase ):
@@ -42,6 +43,34 @@ def init():
4243
4344 self .assertEqual (hello , "world" )
4445
46+ def test_on_request_calls_init_function_with_cors (self ):
47+ app = Flask (__name__ )
48+
49+ hello = None
50+
51+ @core .init
52+ def init ():
53+ nonlocal hello
54+ hello = "world"
55+
56+ func = Mock (__name__ = "example_func" , return_value = "OK" )
57+
58+ with app .test_request_context ("/" ):
59+ environ = EnvironBuilder (
60+ method = "POST" ,
61+ json = {
62+ "data" : {"test" : "value" },
63+ },
64+ ).get_environ ()
65+ request = Request (environ )
66+ decorated_func = https_fn .on_request (
67+ cors = CorsOptions (cors_origins = "*" , cors_methods = "GET" )
68+ )(func )
69+
70+ decorated_func (request )
71+
72+ self .assertEqual (hello , "world" )
73+
4574 def test_on_call_calls_init_function (self ):
4675 app = Flask (__name__ )
4776
You can’t perform that action at this time.
0 commit comments