@@ -230,14 +230,14 @@ class TestDeleteFloatingIPNetwork(TestFloatingIPNetwork):
230230 def setUp (self ):
231231 super (TestDeleteFloatingIPNetwork , self ).setUp ()
232232
233+ self .network .find_ip = mock .Mock ()
233234 self .network .delete_ip = mock .Mock (return_value = None )
234235
235236 # Get the command object to test
236237 self .cmd = fip .DeleteFloatingIP (self .app , self .namespace )
237238
238- @mock .patch .object (fip , '_find_floating_ip' )
239- def test_floating_ip_delete (self , find_floating_ip_mock ):
240- find_floating_ip_mock .side_effect = [
239+ def test_floating_ip_delete (self ):
240+ self .network .find_ip .side_effect = [
241241 self .floating_ips [0 ],
242242 self .floating_ips [1 ],
243243 ]
@@ -251,17 +251,15 @@ def test_floating_ip_delete(self, find_floating_ip_mock):
251251
252252 result = self .cmd .take_action (parsed_args )
253253
254- find_floating_ip_mock .assert_called_once_with (
255- mock .ANY ,
254+ self .network .find_ip .assert_called_once_with (
256255 self .floating_ips [0 ].id ,
257256 ignore_missing = False ,
258257 )
259258 self .network .delete_ip .assert_called_once_with (self .floating_ips [0 ])
260259 self .assertIsNone (result )
261260
262- @mock .patch .object (fip , '_find_floating_ip' )
263- def test_floating_ip_delete_multi (self , find_floating_ip_mock ):
264- find_floating_ip_mock .side_effect = [
261+ def test_floating_ip_delete_multi (self ):
262+ self .network .find_ip .side_effect = [
265263 self .floating_ips [0 ],
266264 self .floating_ips [1 ],
267265 ]
@@ -279,27 +277,24 @@ def test_floating_ip_delete_multi(self, find_floating_ip_mock):
279277
280278 calls = [
281279 call (
282- mock .ANY ,
283280 self .floating_ips [0 ].id ,
284281 ignore_missing = False ,
285282 ),
286283 call (
287- mock .ANY ,
288284 self .floating_ips [1 ].id ,
289285 ignore_missing = False ,
290286 ),
291287 ]
292- find_floating_ip_mock .assert_has_calls (calls )
288+ self . network . find_ip .assert_has_calls (calls )
293289
294290 calls = []
295291 for f in self .floating_ips :
296292 calls .append (call (f ))
297293 self .network .delete_ip .assert_has_calls (calls )
298294 self .assertIsNone (result )
299295
300- @mock .patch .object (fip , '_find_floating_ip' )
301- def test_floating_ip_delete_multi_exception (self , find_floating_ip_mock ):
302- find_floating_ip_mock .side_effect = [
296+ def test_floating_ip_delete_multi_exception (self ):
297+ self .network .find_ip .side_effect = [
303298 self .floating_ips [0 ],
304299 exceptions .CommandError ,
305300 ]
@@ -319,13 +314,11 @@ def test_floating_ip_delete_multi_exception(self, find_floating_ip_mock):
319314 except exceptions .CommandError as e :
320315 self .assertEqual ('1 of 2 floating_ips failed to delete.' , str (e ))
321316
322- find_floating_ip_mock .assert_any_call (
323- mock .ANY ,
317+ self .network .find_ip .assert_any_call (
324318 self .floating_ips [0 ].id ,
325319 ignore_missing = False ,
326320 )
327- find_floating_ip_mock .assert_any_call (
328- mock .ANY ,
321+ self .network .find_ip .assert_any_call (
329322 'unexist_floating_ip' ,
330323 ignore_missing = False ,
331324 )
@@ -590,9 +583,7 @@ def setUp(self):
590583 # Get the command object to test
591584 self .cmd = fip .ShowFloatingIP (self .app , self .namespace )
592585
593- @mock .patch .object (fip , '_find_floating_ip' )
594- def test_floating_ip_show (self , find_floating_ip_mock ):
595- find_floating_ip_mock .return_value = self .floating_ip
586+ def test_floating_ip_show (self ):
596587 arglist = [
597588 self .floating_ip .id ,
598589 ]
@@ -603,8 +594,7 @@ def test_floating_ip_show(self, find_floating_ip_mock):
603594
604595 columns , data = self .cmd .take_action (parsed_args )
605596
606- find_floating_ip_mock .assert_called_once_with (
607- mock .ANY ,
597+ self .network .find_ip .assert_called_once_with (
608598 self .floating_ip .id ,
609599 ignore_missing = False ,
610600 )
@@ -636,14 +626,7 @@ def setUp(self):
636626 # Get the command object to test
637627 self .cmd = fip .SetFloatingIP (self .app , self .namespace )
638628
639- @mock .patch (
640- "openstackclient.tests.unit.network.v2.test_floating_ip_network." +
641- "fip._find_floating_ip"
642- )
643- def test_port_option (self , find_floating_ip_mock ):
644- find_floating_ip_mock .side_effect = [
645- self .floating_ip ,
646- ]
629+ def test_port_option (self ):
647630 arglist = [
648631 self .floating_ip .id ,
649632 '--port' , self .floating_ip .port_id ,
@@ -660,23 +643,15 @@ def test_port_option(self, find_floating_ip_mock):
660643 'port_id' : self .floating_ip .port_id ,
661644 }
662645
663- find_floating_ip_mock .assert_called_once_with (
664- mock .ANY ,
646+ self .network .find_ip .assert_called_once_with (
665647 self .floating_ip .id ,
666648 ignore_missing = False ,
667649 )
668650
669651 self .network .update_ip .assert_called_once_with (
670652 self .floating_ip , ** attrs )
671653
672- @mock .patch (
673- "openstackclient.tests.unit.network.v2.test_floating_ip_network." +
674- "fip._find_floating_ip"
675- )
676- def test_fixed_ip_option (self , find_floating_ip_mock ):
677- find_floating_ip_mock .side_effect = [
678- self .floating_ip ,
679- ]
654+ def test_fixed_ip_option (self ):
680655 arglist = [
681656 self .floating_ip .id ,
682657 '--port' , self .floating_ip .port_id ,
@@ -695,24 +670,16 @@ def test_fixed_ip_option(self, find_floating_ip_mock):
695670 'port_id' : self .floating_ip .port_id ,
696671 'fixed_ip_address' : self .floating_ip .fixed_ip_address ,
697672 }
698- find_floating_ip_mock .assert_called_once_with (
699- mock .ANY ,
673+ self .network .find_ip .assert_called_once_with (
700674 self .floating_ip .id ,
701675 ignore_missing = False ,
702676 )
703677 self .network .update_ip .assert_called_once_with (
704678 self .floating_ip , ** attrs )
705679
706- @mock .patch (
707- "openstackclient.tests.unit.network.v2.test_floating_ip_network." +
708- "fip._find_floating_ip"
709- )
710- def test_port_and_qos_policy_option (self , find_floating_ip_mock ):
680+ def test_port_and_qos_policy_option (self ):
711681 qos_policy = network_fakes .FakeNetworkQosPolicy .create_one_qos_policy ()
712682 self .network .find_qos_policy = mock .Mock (return_value = qos_policy )
713- find_floating_ip_mock .side_effect = [
714- self .floating_ip ,
715- ]
716683 arglist = [
717684 "--qos-policy" , qos_policy .id ,
718685 '--port' , self .floating_ip .port_id ,
@@ -731,22 +698,14 @@ def test_port_and_qos_policy_option(self, find_floating_ip_mock):
731698 'qos_policy_id' : qos_policy .id ,
732699 'port_id' : self .floating_ip .port_id ,
733700 }
734- find_floating_ip_mock .assert_called_once_with (
735- mock .ANY ,
701+ self .network .find_ip .assert_called_once_with (
736702 self .floating_ip .id ,
737703 ignore_missing = False ,
738704 )
739705 self .network .update_ip .assert_called_once_with (
740706 self .floating_ip , ** attrs )
741707
742- @mock .patch (
743- "openstackclient.tests.unit.network.v2.test_floating_ip_network." +
744- "fip._find_floating_ip"
745- )
746- def test_port_and_no_qos_policy_option (self , find_floating_ip_mock ):
747- find_floating_ip_mock .side_effect = [
748- self .floating_ip ,
749- ]
708+ def test_port_and_no_qos_policy_option (self ):
750709 arglist = [
751710 "--no-qos-policy" ,
752711 '--port' , self .floating_ip .port_id ,
@@ -765,8 +724,7 @@ def test_port_and_no_qos_policy_option(self, find_floating_ip_mock):
765724 'qos_policy_id' : None ,
766725 'port_id' : self .floating_ip .port_id ,
767726 }
768- find_floating_ip_mock .assert_called_once_with (
769- mock .ANY ,
727+ self .network .find_ip .assert_called_once_with (
770728 self .floating_ip .id ,
771729 ignore_missing = False ,
772730 )
@@ -796,14 +754,7 @@ def setUp(self):
796754 # Get the command object to test
797755 self .cmd = fip .UnsetFloatingIP (self .app , self .namespace )
798756
799- @mock .patch (
800- "openstackclient.tests.unit.network.v2.test_floating_ip_network." +
801- "fip._find_floating_ip"
802- )
803- def test_floating_ip_unset_port (self , find_floating_ip_mock ):
804- find_floating_ip_mock .side_effect = [
805- self .floating_ip ,
806- ]
757+ def test_floating_ip_unset_port (self ):
807758 arglist = [
808759 self .floating_ip .id ,
809760 "--port" ,
@@ -819,8 +770,7 @@ def test_floating_ip_unset_port(self, find_floating_ip_mock):
819770 attrs = {
820771 'port_id' : None ,
821772 }
822- find_floating_ip_mock .assert_called_once_with (
823- mock .ANY ,
773+ self .network .find_ip .assert_called_once_with (
824774 self .floating_ip .id ,
825775 ignore_missing = False ,
826776 )
@@ -829,14 +779,7 @@ def test_floating_ip_unset_port(self, find_floating_ip_mock):
829779
830780 self .assertIsNone (result )
831781
832- @mock .patch (
833- "openstackclient.tests.unit.network.v2.test_floating_ip_network." +
834- "fip._find_floating_ip"
835- )
836- def test_floating_ip_unset_qos_policy (self , find_floating_ip_mock ):
837- find_floating_ip_mock .side_effect = [
838- self .floating_ip ,
839- ]
782+ def test_floating_ip_unset_qos_policy (self ):
840783 arglist = [
841784 self .floating_ip .id ,
842785 "--qos-policy" ,
@@ -852,8 +795,7 @@ def test_floating_ip_unset_qos_policy(self, find_floating_ip_mock):
852795 attrs = {
853796 'qos_policy_id' : None ,
854797 }
855- find_floating_ip_mock .assert_called_once_with (
856- mock .ANY ,
798+ self .network .find_ip .assert_called_once_with (
857799 self .floating_ip .id ,
858800 ignore_missing = False ,
859801 )
0 commit comments