@@ -158,8 +158,7 @@ def test_object_table(self):
158158 'None' : None ,
159159 'Bool' : True }
160160
161- result = self .run_command (['call-api' , 'Service' , 'method' ],
162- fmt = 'table' )
161+ result = self .run_command (['call-api' , 'Service' , 'method' ], fmt = 'table' )
163162
164163 self .assert_no_fail (result )
165164 # NOTE(kmcdonald): Order is not guaranteed
@@ -179,8 +178,7 @@ def test_object_nested(self):
179178 result = self .run_command (['call-api' , 'Service' , 'method' ])
180179
181180 self .assert_no_fail (result )
182- self .assertEqual (json .loads (result .output ),
183- {'this' : {'is' : [{'pretty' : 'nested' }]}})
181+ self .assertEqual (json .loads (result .output ), {'this' : {'is' : [{'pretty' : 'nested' }]}})
184182
185183 def test_list (self ):
186184 mock = self .set_mock ('SoftLayer_Service' , 'method' )
@@ -208,8 +206,7 @@ def test_list_table(self):
208206 'None' : None ,
209207 'Bool' : True }]
210208
211- result = self .run_command (['call-api' , 'Service' , 'method' ],
212- fmt = 'table' )
209+ result = self .run_command (['call-api' , 'Service' , 'method' ], fmt = 'table' )
213210
214211 self .assert_no_fail (result )
215212 self .assertEqual (result .output ,
@@ -224,12 +221,10 @@ def test_parameters(self):
224221 mock = self .set_mock ('SoftLayer_Service' , 'method' )
225222 mock .return_value = {}
226223
227- result = self .run_command (['call-api' , 'Service' , 'method' ,
228- 'arg1' , '1234' ])
224+ result = self .run_command (['call-api' , 'Service' , 'method' , 'arg1' , '1234' ])
229225
230226 self .assert_no_fail (result )
231- self .assert_called_with ('SoftLayer_Service' , 'method' ,
232- args = ('arg1' , '1234' ))
227+ self .assert_called_with ('SoftLayer_Service' , 'method' , args = ('arg1' , '1234' ))
233228
234229 def test_fixture_not_implemented (self ):
235230 service = 'SoftLayer_Test'
@@ -264,3 +259,42 @@ def test_fixture_exception(self):
264259 self .assertIsInstance (result .exception , SoftLayerAPIError )
265260 output = '%s::%s fixture is not implemented' % (call_service , call_method )
266261 self .assertIn (output , result .exception .faultString )
262+
263+ def test_json_filter_validation (self ):
264+ json_filter = '{"test":"something"}'
265+ result = call_api ._validate_filter (None , None , json_filter )
266+ self .assertEqual (result ['test' ], 'something' )
267+
268+ # Valid JSON, but we expect objects, not simple types
269+ with pytest .raises (exceptions .CLIAbort ):
270+ call_api ._validate_filter (None , None , '"test"' )
271+
272+ # Invalid JSON
273+ with pytest .raises (exceptions .CLIAbort ):
274+ call_api ._validate_filter (None , None , 'test' )
275+
276+ # Empty Request
277+ result = call_api ._validate_filter (None , None , None )
278+ self .assertEqual (None , result )
279+
280+ def test_json_parameters_validation (self ):
281+ json_params = ('{"test":"something"}' , 'String' , 1234 , '[{"a":"b"}]' , '{funky non [ Json' )
282+ result = call_api ._validate_parameters (None , None , json_params )
283+ self .assertEqual (result [0 ], {"test" : "something" })
284+ self .assertEqual (result [1 ], "String" )
285+ self .assertEqual (result [2 ], 1234 )
286+ self .assertEqual (result [3 ], [{"a" : "b" }])
287+ self .assertEqual (result [4 ], "{funky non [ Json" )
288+
289+ def test_filter_with_filter (self ):
290+ result = self .run_command (['call-api' , 'Account' , 'getObject' , '--filter=nested.property=5432' ,
291+ '--json-filter={"test":"something"}' ])
292+ self .assertEqual (2 , result .exit_code )
293+ self .assertEqual (result .exception .message , "--filter and --json-filter cannot be used together." )
294+ self .assertIsInstance (result .exception , exceptions .CLIAbort )
295+
296+ def test_json_filter (self ):
297+ pass
298+ result = self .run_command (['call-api' , 'Account' , 'getObject' , '--json-filter={"test":"something"}' ])
299+ self .assert_no_fail (result )
300+ self .assert_called_with ('SoftLayer_Account' , 'getObject' , filter = {"test" : "something" })
0 commit comments