@@ -23,23 +23,37 @@ def assert_option_strings(self, parser, *option_strings_list):
23
23
for action in parser ._actions ]), \
24
24
"%s not found" % option_strings
25
25
26
- def test_set_parser_server_options_create_a_parser_if_needed (self ):
27
- parser = cli_utils .set_parser_server_options ()
26
+ def test_add_parser_options_create_a_parser_if_needed (self ):
27
+ parser = cli_utils .add_parser_options ()
28
28
self .assert_option_strings (parser , * ALL_PARAMETERS )
29
29
assert len (parser ._actions ) == 8
30
30
31
- def test_set_parser_server_options_adds_arguments_on_existing_parser (self ):
31
+ def test_add_parser_options_adds_arguments_on_existing_parser (self ):
32
32
parser = argparse .ArgumentParser (prog = "importer" )
33
33
parser .add_argument ('-t' , '--type' , help = 'File type' ,
34
34
type = str , default = 'xml' )
35
35
36
- parser = cli_utils .set_parser_server_options (parser )
36
+ parser = cli_utils .add_parser_options (parser )
37
37
self .assert_option_strings (parser , ['-t' , '--type' ],
38
38
* ALL_PARAMETERS )
39
39
assert len (parser ._actions ) == 9
40
40
41
+ def test_add_parser_options_can_ignore_bucket_and_collection (self ):
42
+ parser = cli_utils .add_parser_options (
43
+ include_bucket = False , include_collection = False )
44
+ parameters = [
45
+ ['-h' , '--help' ],
46
+ ['-s' , '--server' ],
47
+ ['-a' , '--auth' ],
48
+ ['-v' , '--verbose' ],
49
+ ['-q' , '--quiet' ],
50
+ ['-D' , '--debug' ],
51
+ ]
52
+ self .assert_option_strings (parser , * parameters )
53
+ assert len (parser ._actions ) == 6
54
+
41
55
def test_can_change_default_values (self ):
42
- parser = cli_utils .set_parser_server_options (
56
+ parser = cli_utils .add_parser_options (
43
57
default_server = "https://firefox.settings.services.mozilla.com/" ,
44
58
default_bucket = "blocklists" ,
45
59
default_collection = "certificates" ,
@@ -71,7 +85,7 @@ def test_get_auth_can_split_user_and_password(self):
71
85
assert password == "password"
72
86
73
87
def test_get_auth_is_called_by_argparse (self ):
74
- parser = cli_utils .set_parser_server_options (
88
+ parser = cli_utils .add_parser_options (
75
89
default_server = "https://firefox.settings.services.mozilla.com/" ,
76
90
default_bucket = "blocklists" ,
77
91
default_collection = "certificates" )
@@ -81,21 +95,38 @@ def test_get_auth_is_called_by_argparse(self):
81
95
82
96
class ClientFromArgsTest (unittest .TestCase ):
83
97
84
- def setUp (self ):
85
- parser = cli_utils .set_parser_server_options (
98
+ @mock .patch ('kinto_client.cli_utils.Client' )
99
+ def test_create_client_from_args_build_a_client (self , mocked_client ):
100
+ parser = cli_utils .add_parser_options (
86
101
default_server = "https://firefox.settings.services.mozilla.com/" ,
87
102
default_bucket = "blocklists" ,
88
103
default_collection = "certificates" ,
89
104
default_auth = ('user' , 'password' )
90
105
)
91
106
92
- self . args = parser .parse_args ([])
107
+ args = parser .parse_args ([])
93
108
94
- @mock .patch ('kinto_client.cli_utils.Client' )
95
- def test_create_client_from_args_build_a_client (self , mocked_client ):
96
- cli_utils .create_client_from_args (self .args )
109
+ cli_utils .create_client_from_args (args )
97
110
mocked_client .assert_called_with (
98
111
server_url = 'https://firefox.settings.services.mozilla.com/' ,
99
112
auth = ('user' , 'password' ),
100
113
bucket = 'blocklists' ,
101
114
collection = 'certificates' )
115
+
116
+ @mock .patch ('kinto_client.cli_utils.Client' )
117
+ def test_create_client_from_args_default_bucket_and_collection_to_none (
118
+ self , mocked_client ):
119
+ parser = cli_utils .add_parser_options (
120
+ default_server = "https://firefox.settings.services.mozilla.com/" ,
121
+ default_auth = ('user' , 'password' ),
122
+ include_bucket = False , include_collection = False
123
+ )
124
+
125
+ args = parser .parse_args ([])
126
+
127
+ cli_utils .create_client_from_args (args )
128
+ mocked_client .assert_called_with (
129
+ server_url = 'https://firefox.settings.services.mozilla.com/' ,
130
+ auth = ('user' , 'password' ),
131
+ bucket = None ,
132
+ collection = None )
0 commit comments