@@ -208,13 +208,19 @@ def setUp(self):
208208 super (TestDeleteFloatingIPNetwork , self ).setUp ()
209209
210210 self .network .delete_ip = mock .Mock (return_value = None )
211- self .network .find_ip = (
212- network_fakes .FakeFloatingIP .get_floating_ips (self .floating_ips ))
213211
214212 # Get the command object to test
215213 self .cmd = floating_ip .DeleteFloatingIP (self .app , self .namespace )
216214
217- def test_floating_ip_delete (self ):
215+ @mock .patch (
216+ "openstackclient.tests.unit.network.v2.test_floating_ip." +
217+ "floating_ip._find_floating_ip"
218+ )
219+ def test_floating_ip_delete (self , find_floating_ip_mock ):
220+ find_floating_ip_mock .side_effect = [
221+ (self .floating_ips [0 ], []),
222+ (self .floating_ips [1 ], []),
223+ ]
218224 arglist = [
219225 self .floating_ips [0 ].id ,
220226 ]
@@ -225,12 +231,24 @@ def test_floating_ip_delete(self):
225231
226232 result = self .cmd .take_action (parsed_args )
227233
228- self .network .find_ip .assert_called_once_with (
229- self .floating_ips [0 ].id , ignore_missing = False )
234+ find_floating_ip_mock .assert_called_once_with (
235+ mock .ANY ,
236+ [],
237+ self .floating_ips [0 ].id ,
238+ ignore_missing = False ,
239+ )
230240 self .network .delete_ip .assert_called_once_with (self .floating_ips [0 ])
231241 self .assertIsNone (result )
232242
233- def test_multi_floating_ips_delete (self ):
243+ @mock .patch (
244+ "openstackclient.tests.unit.network.v2.test_floating_ip." +
245+ "floating_ip._find_floating_ip"
246+ )
247+ def test_floating_ip_delete_multi (self , find_floating_ip_mock ):
248+ find_floating_ip_mock .side_effect = [
249+ (self .floating_ips [0 ], []),
250+ (self .floating_ips [1 ], []),
251+ ]
234252 arglist = []
235253 verifylist = []
236254
@@ -243,13 +261,37 @@ def test_multi_floating_ips_delete(self):
243261
244262 result = self .cmd .take_action (parsed_args )
245263
264+ calls = [
265+ call (
266+ mock .ANY ,
267+ [],
268+ self .floating_ips [0 ].id ,
269+ ignore_missing = False ,
270+ ),
271+ call (
272+ mock .ANY ,
273+ [],
274+ self .floating_ips [1 ].id ,
275+ ignore_missing = False ,
276+ ),
277+ ]
278+ find_floating_ip_mock .assert_has_calls (calls )
279+
246280 calls = []
247281 for f in self .floating_ips :
248282 calls .append (call (f ))
249283 self .network .delete_ip .assert_has_calls (calls )
250284 self .assertIsNone (result )
251285
252- def test_multi_floating_ips_delete_with_exception (self ):
286+ @mock .patch (
287+ "openstackclient.tests.unit.network.v2.test_floating_ip." +
288+ "floating_ip._find_floating_ip"
289+ )
290+ def test_floating_ip_delete_multi_exception (self , find_floating_ip_mock ):
291+ find_floating_ip_mock .side_effect = [
292+ (self .floating_ips [0 ], []),
293+ exceptions .CommandError ,
294+ ]
253295 arglist = [
254296 self .floating_ips [0 ].id ,
255297 'unexist_floating_ip' ,
@@ -260,21 +302,24 @@ def test_multi_floating_ips_delete_with_exception(self):
260302 ]
261303 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
262304
263- find_mock_result = [self .floating_ips [0 ], exceptions .CommandError ]
264- self .network .find_ip = (
265- mock .Mock (side_effect = find_mock_result )
266- )
267-
268305 try :
269306 self .cmd .take_action (parsed_args )
270307 self .fail ('CommandError should be raised.' )
271308 except exceptions .CommandError as e :
272309 self .assertEqual ('1 of 2 floating_ips failed to delete.' , str (e ))
273310
274- self .network .find_ip .assert_any_call (
275- self .floating_ips [0 ].id , ignore_missing = False )
276- self .network .find_ip .assert_any_call (
277- 'unexist_floating_ip' , ignore_missing = False )
311+ find_floating_ip_mock .assert_any_call (
312+ mock .ANY ,
313+ [],
314+ self .floating_ips [0 ].id ,
315+ ignore_missing = False ,
316+ )
317+ find_floating_ip_mock .assert_any_call (
318+ mock .ANY ,
319+ [],
320+ 'unexist_floating_ip' ,
321+ ignore_missing = False ,
322+ )
278323 self .network .delete_ip .assert_called_once_with (
279324 self .floating_ips [0 ]
280325 )
@@ -534,7 +579,12 @@ def setUp(self):
534579 # Get the command object to test
535580 self .cmd = floating_ip .ShowFloatingIP (self .app , self .namespace )
536581
537- def test_floating_ip_show (self ):
582+ @mock .patch (
583+ "openstackclient.tests.unit.network.v2.test_floating_ip." +
584+ "floating_ip._find_floating_ip"
585+ )
586+ def test_floating_ip_show (self , find_floating_ip_mock ):
587+ find_floating_ip_mock .return_value = (self .floating_ip , [])
538588 arglist = [
539589 self .floating_ip .id ,
540590 ]
@@ -545,9 +595,11 @@ def test_floating_ip_show(self):
545595
546596 columns , data = self .cmd .take_action (parsed_args )
547597
548- self .network .find_ip .assert_called_once_with (
598+ find_floating_ip_mock .assert_called_once_with (
599+ mock .ANY ,
600+ [],
549601 self .floating_ip .id ,
550- ignore_missing = False
602+ ignore_missing = False ,
551603 )
552604 self .assertEqual (self .columns , columns )
553605 self .assertEqual (self .data , data )
0 commit comments