forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_tests.py
More file actions
155 lines (119 loc) · 5.51 KB
/
image_tests.py
File metadata and controls
155 lines (119 loc) · 5.51 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"""
SoftLayer.tests.managers.image_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
"""
import SoftLayer
from SoftLayer import testing
IMAGE_SERVICE = 'SoftLayer_Virtual_Guest_Block_Device_Template_Group'
class ImageTests(testing.TestCase):
def set_up(self):
self.image = SoftLayer.ImageManager(self.client)
self.vgbdtg = self.client['']
self.account = self.client['Account']
def test_get_image(self):
result = self.image.get_image(100)
self.assertEqual(result['id'], 100)
self.assertEqual(result['name'], 'test_image')
self.assertEqual(result['accountId'], 1234)
self.assert_called_with(IMAGE_SERVICE, 'getObject', identifier=100)
def test_delete_image(self):
self.image.delete_image(100)
self.assert_called_with(IMAGE_SERVICE, 'deleteObject', identifier=100)
def test_list_private_images(self):
results = self.image.list_private_images()
self.assertEqual(len(results), 2)
self.assert_called_with('SoftLayer_Account',
'getPrivateBlockDeviceTemplateGroups')
def test_list_private_images_with_filters(self):
results = self.image.list_private_images(
guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name')
self.assertEqual(len(results), 2)
_filter = {
'privateBlockDeviceTemplateGroups': {
'globalIdentifier': {
'operation': '_= 0FA9ECBD-CF7E-4A1F-1E36F8D27C2B'},
'name': {'operation': '_= name'}}
}
self.assert_called_with('SoftLayer_Account',
'getPrivateBlockDeviceTemplateGroups',
filter=_filter)
def test_list_public_images(self):
results = self.image.list_public_images()
self.assertEqual(len(results), 2)
self.assert_called_with(IMAGE_SERVICE, 'getPublicImages')
def test_list_public_images_with_filters(self):
results = self.image.list_public_images(
guid='0FA9ECBD-CF7E-4A1F-1E36F8D27C2B', name='name')
_filter = {
'globalIdentifier': {
'operation': '_= 0FA9ECBD-CF7E-4A1F-1E36F8D27C2B'},
'name': {'operation': '_= name'}
}
self.assertEqual(len(results), 2)
self.assert_called_with(IMAGE_SERVICE, 'getPublicImages',
filter=_filter)
def test_resolve_ids_guid(self):
result = self.image.resolve_ids('3C1F3C68-0B67-4F5E-8907-D0FC84BF3F12')
self.assertEqual(['3C1F3C68-0B67-4F5E-8907-D0FC84BF3F12'], result)
def test_resolve_ids_name_public(self):
public_mock = self.set_mock(IMAGE_SERVICE, 'getPublicImages')
public_mock.return_value = [{'id': 100}]
private_mock = self.set_mock('SoftLayer_Account',
'getPrivateBlockDeviceTemplateGroups')
private_mock.return_value = []
self.account.getPrivateBlockDeviceTemplateGroups.return_value = []
result = self.image.resolve_ids('image_name')
self.assertEqual([100], result)
def test_resolve_ids_name_private(self):
public_mock = self.set_mock(IMAGE_SERVICE, 'getPublicImages')
public_mock.return_value = []
private_mock = self.set_mock('SoftLayer_Account',
'getPrivateBlockDeviceTemplateGroups')
private_mock.return_value = [{'id': 100}]
result = self.image.resolve_ids('private_image_name')
self.assertEqual([100], result)
def test_resolve_ids_not_found(self):
public_mock = self.set_mock(IMAGE_SERVICE, 'getPublicImages')
public_mock.return_value = []
private_mock = self.set_mock('SoftLayer_Account',
'getPrivateBlockDeviceTemplateGroups')
private_mock.return_value = []
result = self.image.resolve_ids('unknown_name')
self.assertEqual([], result)
def test_edit_tags(self):
# Test updating tags
self.image.edit(1, tag="tag1,tag2")
self.assert_called_with(IMAGE_SERVICE, 'setTags',
identifier=1,
args=("tag1,tag2",))
def test_edit_blank(self):
# Test a blank edit
result = self.image.edit(1)
self.assertEqual(result, False)
self.assertEqual(self.calls(IMAGE_SERVICE, 'setTags'), [])
def test_edit_full(self):
# Finally test a full edit
self.image.edit(1, name='abc', note='xyz')
self.assert_called_with(IMAGE_SERVICE, 'editObject',
identifier=1,
args=({'name': 'abc', 'note': 'xyz'},))
def test_import_image(self):
self.image.import_image_from_uri(name='test_image',
note='testimage',
uri='someuri',
os_code='UBUNTU_LATEST')
self.assert_called_with(
IMAGE_SERVICE,
'createFromExternalSource',
args=({'name': 'test_image',
'note': 'testimage',
'uri': 'someuri',
'operatingSystemReferenceCode': 'UBUNTU_LATEST'},))
def test_export_image(self):
self.image.export_image_to_uri(1234, 'someuri')
self.assert_called_with(
IMAGE_SERVICE,
'copyToExternalSource',
args=({'uri': 'someuri'},),
identifier=1234)