2222from functions_framework ._cli import _cli
2323
2424
25- @pytest .fixture
26- def run ():
27- return pretend .call_recorder (lambda * a , ** kw : None )
28-
29-
30- @pytest .fixture
31- def create_app (monkeypatch , run ):
32- create_app = pretend .call_recorder (lambda * a , ** kw : pretend .stub (run = run ))
33- monkeypatch .setattr (functions_framework ._cli , "create_app" , create_app )
34- return create_app
35-
36-
3725def test_cli_no_arguments ():
3826 runner = CliRunner ()
3927 result = runner .invoke (_cli )
@@ -43,63 +31,101 @@ def test_cli_no_arguments():
4331
4432
4533@pytest .mark .parametrize (
46- "args, env, create_app_calls, run_calls " ,
34+ "args, env, create_app_calls, app_run_calls, wsgi_server_run_calls " ,
4735 [
4836 (
4937 ["--target" , "foo" ],
5038 {},
5139 [pretend .call ("foo" , None , "http" )],
52- [pretend .call ("0.0.0.0" , 8080 , False )],
40+ [],
41+ [pretend .call ("0.0.0.0" , 8080 )],
5342 ),
5443 (
5544 [],
5645 {"FUNCTION_TARGET" : "foo" },
5746 [pretend .call ("foo" , None , "http" )],
58- [pretend .call ("0.0.0.0" , 8080 , False )],
47+ [],
48+ [pretend .call ("0.0.0.0" , 8080 )],
5949 ),
6050 (
6151 ["--target" , "foo" , "--source" , "/path/to/source.py" ],
6252 {},
6353 [pretend .call ("foo" , "/path/to/source.py" , "http" )],
64- [pretend .call ("0.0.0.0" , 8080 , False )],
54+ [],
55+ [pretend .call ("0.0.0.0" , 8080 )],
6556 ),
6657 (
6758 [],
6859 {"FUNCTION_TARGET" : "foo" , "FUNCTION_SOURCE" : "/path/to/source.py" },
6960 [pretend .call ("foo" , "/path/to/source.py" , "http" )],
70- [pretend .call ("0.0.0.0" , 8080 , False )],
61+ [],
62+ [pretend .call ("0.0.0.0" , 8080 )],
7163 ),
7264 (
7365 ["--target" , "foo" , "--signature-type" , "event" ],
7466 {},
7567 [pretend .call ("foo" , None , "event" )],
76- [pretend .call ("0.0.0.0" , 8080 , False )],
68+ [],
69+ [pretend .call ("0.0.0.0" , 8080 )],
7770 ),
7871 (
7972 [],
8073 {"FUNCTION_TARGET" : "foo" , "FUNCTION_SIGNATURE_TYPE" : "event" },
8174 [pretend .call ("foo" , None , "event" )],
82- [pretend .call ("0.0.0.0" , 8080 , False )],
75+ [],
76+ [pretend .call ("0.0.0.0" , 8080 )],
77+ ),
78+ (
79+ ["--target" , "foo" , "--dry-run" ],
80+ {},
81+ [pretend .call ("foo" , None , "http" )],
82+ [],
83+ [],
8384 ),
84- (["--target" , "foo" , "--dry-run" ], {}, [pretend .call ("foo" , None , "http" )], []),
8585 (
8686 [],
8787 {"FUNCTION_TARGET" : "foo" , "DRY_RUN" : "True" },
8888 [pretend .call ("foo" , None , "http" )],
8989 [],
90+ [],
9091 ),
9192 (
9293 ["--target" , "foo" , "--host" , "127.0.0.1" ],
9394 {},
9495 [pretend .call ("foo" , None , "http" )],
95- [pretend .call ("127.0.0.1" , 8080 , False )],
96+ [],
97+ [pretend .call ("127.0.0.1" , 8080 )],
98+ ),
99+ (
100+ ["--target" , "foo" , "--debug" ],
101+ {},
102+ [pretend .call ("foo" , None , "http" )],
103+ [pretend .call ("0.0.0.0" , 8080 , True )],
104+ [],
105+ ),
106+ (
107+ [],
108+ {"FUNCTION_TARGET" : "foo" , "DEBUG" : "True" },
109+ [pretend .call ("foo" , None , "http" )],
110+ [pretend .call ("0.0.0.0" , 8080 , True )],
111+ [],
96112 ),
97113 ],
98114)
99- def test_cli_arguments (create_app , run , args , env , create_app_calls , run_calls ):
115+ def test_cli (
116+ monkeypatch , args , env , create_app_calls , app_run_calls , wsgi_server_run_calls ,
117+ ):
118+ wsgi_server = pretend .stub (run = pretend .call_recorder (lambda * a , ** kw : None ))
119+ wsgi_app = pretend .stub (run = pretend .call_recorder (lambda * a , ** kw : None ))
120+ create_app = pretend .call_recorder (lambda * a , ** kw : wsgi_app )
121+ monkeypatch .setattr (functions_framework ._cli , "create_app" , create_app )
122+ create_server = pretend .call_recorder (lambda * a , ** kw : wsgi_server )
123+ monkeypatch .setattr (functions_framework ._cli , "create_server" , create_server )
124+
100125 runner = CliRunner (env = env )
101126 result = runner .invoke (_cli , args )
102127
103128 assert result .exit_code == 0
104129 assert create_app .calls == create_app_calls
105- assert run .calls == run_calls
130+ assert wsgi_app .run .calls == app_run_calls
131+ assert wsgi_server .run .calls == wsgi_server_run_calls
0 commit comments