22
22
from functions_framework ._cli import _cli
23
23
24
24
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
-
37
25
def test_cli_no_arguments ():
38
26
runner = CliRunner ()
39
27
result = runner .invoke (_cli )
@@ -43,63 +31,101 @@ def test_cli_no_arguments():
43
31
44
32
45
33
@pytest .mark .parametrize (
46
- "args, env, create_app_calls, run_calls " ,
34
+ "args, env, create_app_calls, app_run_calls, wsgi_server_run_calls " ,
47
35
[
48
36
(
49
37
["--target" , "foo" ],
50
38
{},
51
39
[pretend .call ("foo" , None , "http" )],
52
- [pretend .call ("0.0.0.0" , 8080 , False )],
40
+ [],
41
+ [pretend .call ("0.0.0.0" , 8080 )],
53
42
),
54
43
(
55
44
[],
56
45
{"FUNCTION_TARGET" : "foo" },
57
46
[pretend .call ("foo" , None , "http" )],
58
- [pretend .call ("0.0.0.0" , 8080 , False )],
47
+ [],
48
+ [pretend .call ("0.0.0.0" , 8080 )],
59
49
),
60
50
(
61
51
["--target" , "foo" , "--source" , "/path/to/source.py" ],
62
52
{},
63
53
[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 )],
65
56
),
66
57
(
67
58
[],
68
59
{"FUNCTION_TARGET" : "foo" , "FUNCTION_SOURCE" : "/path/to/source.py" },
69
60
[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 )],
71
63
),
72
64
(
73
65
["--target" , "foo" , "--signature-type" , "event" ],
74
66
{},
75
67
[pretend .call ("foo" , None , "event" )],
76
- [pretend .call ("0.0.0.0" , 8080 , False )],
68
+ [],
69
+ [pretend .call ("0.0.0.0" , 8080 )],
77
70
),
78
71
(
79
72
[],
80
73
{"FUNCTION_TARGET" : "foo" , "FUNCTION_SIGNATURE_TYPE" : "event" },
81
74
[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
+ [],
83
84
),
84
- (["--target" , "foo" , "--dry-run" ], {}, [pretend .call ("foo" , None , "http" )], []),
85
85
(
86
86
[],
87
87
{"FUNCTION_TARGET" : "foo" , "DRY_RUN" : "True" },
88
88
[pretend .call ("foo" , None , "http" )],
89
89
[],
90
+ [],
90
91
),
91
92
(
92
93
["--target" , "foo" , "--host" , "127.0.0.1" ],
93
94
{},
94
95
[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
+ [],
96
112
),
97
113
],
98
114
)
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
+
100
125
runner = CliRunner (env = env )
101
126
result = runner .invoke (_cli , args )
102
127
103
128
assert result .exit_code == 0
104
129
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