23
23
24
24
25
25
@pytest .fixture
26
- def create_app (monkeypatch ):
27
- create_app = pretend .call_recorder (
28
- lambda * a , ** kw : pretend .stub (run = pretend .call_recorder (lambda * a , ** kw : None ))
29
- )
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 ))
30
33
monkeypatch .setattr (functions_framework .cli , "create_app" , create_app )
31
34
return create_app
32
35
@@ -40,38 +43,57 @@ def test_cli_no_arguments():
40
43
41
44
42
45
@pytest .mark .parametrize (
43
- "args, env, call " ,
46
+ "args, env, create_app_calls, run_calls " ,
44
47
[
45
- (["--target" , "foo" ], {}, pretend .call ("foo" , None , "http" )),
46
- ([], {"FUNCTION_TARGET" : "foo" }, pretend .call ("foo" , None , "http" )),
48
+ (
49
+ ["--target" , "foo" ],
50
+ {},
51
+ [pretend .call ("foo" , None , "http" )],
52
+ [pretend .call ("0.0.0.0" , 8080 , False )],
53
+ ),
54
+ (
55
+ [],
56
+ {"FUNCTION_TARGET" : "foo" },
57
+ [pretend .call ("foo" , None , "http" )],
58
+ [pretend .call ("0.0.0.0" , 8080 , False
8000
)],
59
+ ),
47
60
(
48
61
["--target" , "foo" , "--source" , "/path/to/source.py" ],
49
62
{},
50
- pretend .call ("foo" , "/path/to/source.py" , "http" ),
63
+ [pretend .call ("foo" , "/path/to/source.py" , "http" )],
64
+ [pretend .call ("0.0.0.0" , 8080 , False )],
51
65
),
52
66
(
53
67
[],
54
68
{"FUNCTION_TARGET" : "foo" , "FUNCTION_SOURCE" : "/path/to/source.py" },
55
- pretend .call ("foo" , "/path/to/source.py" , "http" ),
69
+ [pretend .call ("foo" , "/path/to/source.py" , "http" )],
70
+ [pretend .call ("0.0.0.0" , 8080 , False )],
56
71
),
57
72
(
58
73
["--target" , "foo" , "--signature-type" , "event" ],
59
74
{},
60
- pretend .call ("foo" , None , "event" ),
75
+ [pretend .call ("foo" , None , "event" )],
76
+ [pretend .call ("0.0.0.0" , 8080 , False )],
61
77
),
62
78
(
63
79
[],
64
80
{"FUNCTION_TARGET" : "foo" , "FUNCTION_SIGNATURE_TYPE" : "event" },
65
- pretend .call ("foo" , None , "event" ),
81
+ [pretend .call ("foo" , None , "event" )],
82
+ [pretend .call ("0.0.0.0" , 8080 , False )],
83
+ ),
84
+ (["--target" , "foo" , "--dry-run" ], {}, [pretend .call ("foo" , None , "http" )], []),
85
+ (
86
+ [],
87
+ {"FUNCTION_TARGET" : "foo" , "DRY_RUN" : "True" },
88
+ [pretend .call ("foo" , None , "http" )],
89
+ [],
66
90
),
67
91
],
68
92
)
69
- def test_cli_arguments (create_app , args , env , call ):
93
+ def test_cli_arguments (create_app , run , args , env , create_app_calls , run_calls ):
70
94
runner = CliRunner (env = env )
71
95
result = runner .invoke (cli , args )
72
96
73
- if result .output :
74
- print (result .output )
75
-
76
97
assert result .exit_code == 0
77
- assert create_app .calls == [call ]
98
+ assert create_app .calls == create_app_calls
99
+ assert run .calls == run_calls
0 commit comments