forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobalip_tests.py
More file actions
68 lines (52 loc) · 2.34 KB
/
globalip_tests.py
File metadata and controls
68 lines (52 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
SoftLayer.tests.CLI.modules.globalip_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
"""
import mock
from SoftLayer.CLI import exceptions
from SoftLayer import testing
import json
class DnsTests(testing.TestCase):
def test_ip_assign(self):
result = self.run_command(['globalip', 'assign', '1', '127.0.0.1'])
self.assert_no_fail(result)
self.assertEqual(result.output, "")
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
def test_ip_cancel(self, no_going_back_mock):
# Test using --really flag
result = self.run_command(['--really', 'globalip', 'cancel', '1'])
self.assert_no_fail(result)
self.assertEqual(result.output, "")
# Test with confirmation
no_going_back_mock.return_value = True
result = self.run_command(['globalip', 'cancel', '1'])
self.assert_no_fail(result)
self.assertEqual(result.output, "")
# Test with confirmation and responding negatively
no_going_back_mock.return_value = False
result = self.run_command(['globalip', 'cancel', '1'])
self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.CLIAbort)
def test_ip_list(self):
result = self.run_command(['globalip', 'list', '--ip-version=v4'])
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
[{'assigned': 'Yes',
'id': '200',
'ip': '127.0.0.1',
'target': '127.0.0.1 (example.com)'},
{'assigned': 'Yes',
'id': '201',
'ip': '127.0.0.1',
'target': '127.0.0.1 (example.com)'}])
result = self.run_command(['globalip', 'list', '--ip-version=v6'])
self.assertEqual(json.loads(result.output),
[{'assigned': 'Yes',
'id': '200',
'ip': '127.0.0.1',
'target': '127.0.0.1 (example.com)'},
{'assigned': 'Yes',
'id': '201',
'ip': '127.0.0.1',
'target': '127.0.0.1 (example.com)'}])