Skip to content

Commit bc29ec3

Browse files
committed
add subnet edit tests
1 parent a8a5058 commit bc29ec3

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

SoftLayer/fixtures/SoftLayer_Network_Subnet.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,16 @@
2525
}
2626
],
2727
'hardware': [],
28-
'usableIpAddressCount': 22
28+
'usableIpAddressCount': 22,
29+
'note': 'test note',
30+
'tagReferences': [
31+
{'id': 1000123,
32+
'resourceTableId': 1234,
33+
'tag': {'id': 100123,
34+
'name': 'subnet: test tag'},
35+
}
36+
]
2937
}
38+
39+
editNote = True
40+
setTags = True

tests/CLI/modules/subnet_tests.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ def test_detail(self):
3636
'private_ip': '10.0.1.2'
3737
}
3838
],
39-
'hardware': 'none',
40-
'usable ips': 22
39+
'hardware': None,
40+
'usable ips': 22,
41+
'note': 'test note',
42+
'tags': [
43+
'subnet: test tag'
44+
],
4145
},
4246
json.loads(result.output))
4347

@@ -134,3 +138,35 @@ def test_create_subnet_static_ipv6(self, confirm_mock):
134138
]
135139

136140
self.assertEqual(output, json.loads(result.output))
141+
142+
@mock.patch('SoftLayer.CLI.subnet.edit.click')
143+
def test_subnet_set_tags(self, click):
144+
result = self.run_command(['subnet', 'edit', '1234', '--tags=tag1,tag2'])
145+
click.secho.assert_called_with('Set tags successfully', fg='green')
146+
self.assert_no_fail(result)
147+
self.assert_called_with('SoftLayer_Network_Subnet', 'setTags', identifier=1234, args=("tag1,tag2",))
148+
149+
@mock.patch('SoftLayer.CLI.subnet.edit.click')
150+
def test_subnet_edit_note(self, click):
151+
result = self.run_command(['subnet', 'edit', '1234', '--note=test'])
152+
click.secho.assert_called_with('Edit note successfully', fg='green')
153+
self.assert_no_fail(result)
154+
self.assert_called_with('SoftLayer_Network_Subnet', 'editNote', identifier=1234, args=("test",))
155+
156+
@mock.patch('SoftLayer.CLI.subnet.edit.click')
157+
def test_subnet_set_tags_failure(self, click):
158+
mock = self.set_mock('SoftLayer_Network_Subnet', 'setTags')
159+
mock.return_value = False
160+
result = self.run_command(['subnet', 'edit', '1234', '--tags=tag1,tag2'])
161+
click.secho.assert_called_with('Failed to set tags', fg='red')
162+
self.assert_no_fail(result)
163+
self.assert_called_with('SoftLayer_Network_Subnet', 'setTags', identifier=1234, args=("tag1,tag2",))
164+
165+
@mock.patch('SoftLayer.CLI.subnet.edit.click')
166+
def test_edit_note_failure(self, click):
167+
mock = self.set_mock('SoftLayer_Network_Subnet', 'editNote')
168+
mock.return_value = False
169+
result = self.run_command(['subnet', 'edit', '1234', '--note=test'])
170+
click.secho.assert_called_with('Failed to edit note', fg='red')
171+
self.assert_no_fail(result)
172+
self.assert_called_with('SoftLayer_Network_Subnet', 'editNote', identifier=1234, args=("test",))

tests/managers/network_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ def test_cancel_subnet(self):
158158
self.assert_called_with('SoftLayer_Billing_Item', 'cancelService',
159159
identifier=1056)
160160

161+
def test_set_tags_subnet(self):
162+
subnet_id = 1234
163+
tags = 'tags1,tag2'
164+
result = self.network.set_tags_subnet(subnet_id, tags)
165+
166+
self.assertEqual(result, True)
167+
self.assert_called_with('SoftLayer_Network_Subnet', 'setTags',
168+
identifier=subnet_id,
169+
args=(tags,))
170+
171+
def test_edit_note_subnet(self):
172+
subnet_id = 1234
173+
note = 'test note'
174+
result = self.network.edit_note_subnet(subnet_id, note)
175+
176+
self.assertEqual(result, True)
177+
self.assert_called_with('SoftLayer_Network_Subnet', 'editNote',
178+
identifier=subnet_id,
179+
args=(note,))
180+
161181
def test_create_securitygroup(self):
162182
result = self.network.create_securitygroup(name='foo',
163183
description='bar')

0 commit comments

Comments
 (0)