1212import json
1313
1414
15- class DnsTests (testing .TestCase ):
15+ class GlobalIpTests (testing .TestCase ):
1616
17- def test_ip_assign (self ):
18- result = self .run_command (['globalip' , 'assign' , '1' ])
19-
20- self .assert_no_fail (result )
21- self .assertEqual (result .output , "" )
22-
23- @mock .patch ('SoftLayer.CLI.formatting.no_going_back' )
17+ @mock .patch ('SoftLayer.CLI.formatting.confirm' )
2418 def test_ip_cancel (self , no_going_back_mock ):
2519 # Test using --really flag
2620 result = self .run_command (['--really' , 'globalip' , 'cancel' , '1' ])
@@ -39,7 +33,7 @@ def test_ip_cancel(self, no_going_back_mock):
3933 no_going_back_mock .return_value = False
4034 result = self .run_command (['globalip' , 'cancel' , '1' ])
4135
42- self .assertEqual (result .exit_code , 0 )
36+ self .assertEqual (result .exit_code , 2 )
4337
4438 def test_ip_list (self ):
4539 result = self .run_command (['globalip' , 'list' , '--ip-version=v4' ])
@@ -84,6 +78,31 @@ def test_ip_unassign(self):
8478 result = self .run_command (['globalip' , 'unassign' , '1' ])
8579 self .assert_no_fail (result )
8680 self .assertEqual (result .output , "" )
81+ self .assert_called_with ('SoftLayer_Network_Subnet' , 'clearRoute' , identifier = 9988 )
82+
83+ def test_ip_assign (self ):
84+ result = self .run_command (['globalip' , 'assign' , '1' , '999' ])
85+ self .assert_no_fail (result )
86+ self .assertEqual (result .output , "" )
87+ service = 'SoftLayer_Network_Subnet_IpAddress'
88+ self .assert_called_with ('SoftLayer_Network_Subnet' , 'route' , identifier = 9988 , args = (service , '999' ))
89+
90+ def test_ip_assign_target (self ):
91+ result = self .run_command (['globalip' , 'assign' , '1' , '--target-id=8123' ])
92+ self .assert_no_fail (result )
93+ self .assertEqual (result .output , "" )
94+ service = 'SoftLayer_Network_Subnet_IpAddress'
95+ self .assert_called_with ('SoftLayer_Network_Subnet' , 'route' , identifier = 9988 , args = (service , '8123' ))
96+
97+ def test_ip_assign_ip (self ):
98+ mock_api = self .set_mock ('SoftLayer_Account' , 'getGlobalIpRecords' )
99+ mock_api .return_value = [{"id" : 112233 }]
100+ result = self .run_command (['globalip' , 'assign' , '192.168.1.1' , '1.2.3.4' ])
101+ self .assert_no_fail (result )
102+ self .assertEqual (result .output , "" )
103+ service = 'SoftLayer_Network_Subnet_IpAddress'
104+ self .assert_called_with (f"{ service } _Global" , "getObject" , identifier = 112233 )
105+ self .assert_called_with ('SoftLayer_Network_Subnet' , 'route' , identifier = 9988 , args = (service , '1.2.3.4' ))
87106
88107 def test_ip_cancel_force (self ):
89108 result = self .run_command (['globalip' , 'cancel' , '1' , '--force' ])
0 commit comments