|
11 | 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
12 | 12 | # License for the specific language governing permissions and limitations |
13 | 13 | # under the License. |
14 | | -# |
15 | 14 |
|
16 | | -import copy |
17 | 15 | import random |
18 | 16 | from unittest import mock |
19 | 17 | import uuid |
20 | 18 |
|
21 | 19 | from openstack.image.v2 import image |
22 | 20 | from openstack.image.v2 import member |
23 | | -from osc_lib.cli import format_columns |
24 | 21 |
|
25 | 22 | from openstackclient.tests.unit import fakes |
26 | 23 | from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes |
27 | 24 | from openstackclient.tests.unit import utils |
28 | 25 |
|
29 | 26 | image_id = '0f41529e-7c12-4de8-be2d-181abb825b3c' |
30 | 27 | image_name = 'graven' |
31 | | -image_owner = 'baal' |
32 | | -image_protected = False |
33 | | -image_visibility = 'public' |
34 | | -image_tags = [] |
35 | | -image_size = 0 |
36 | | - |
37 | | -IMAGE = { |
38 | | - 'id': image_id, |
39 | | - 'name': image_name, |
40 | | - 'owner': image_owner, |
41 | | - 'protected': image_protected, |
42 | | - 'visibility': image_visibility, |
43 | | - 'tags': image_tags, |
44 | | - 'size': image_size |
45 | | -} |
46 | | - |
47 | | -IMAGE_columns = tuple(sorted(IMAGE)) |
48 | | -IMAGE_data = tuple((IMAGE[x] for x in sorted(IMAGE))) |
49 | | - |
50 | | -IMAGE_SHOW = copy.copy(IMAGE) |
51 | | -IMAGE_SHOW['tags'] = format_columns.ListColumn(IMAGE_SHOW['tags']) |
52 | | -IMAGE_SHOW_data = tuple((IMAGE_SHOW[x] for x in sorted(IMAGE_SHOW))) |
53 | | - |
54 | | -# Just enough v2 schema to do some testing |
55 | | -IMAGE_schema = { |
56 | | - "additionalProperties": { |
57 | | - "type": "string" |
58 | | - }, |
59 | | - "name": "image", |
60 | | - "links": [ |
61 | | - { |
62 | | - "href": "{self}", |
63 | | - "rel": "self" |
64 | | - }, |
65 | | - { |
66 | | - "href": "{file}", |
67 | | - "rel": "enclosure" |
68 | | - }, |
69 | | - { |
70 | | - "href": "{schema}", |
71 | | - "rel": "describedby" |
72 | | - } |
73 | | - ], |
74 | | - "properties": { |
75 | | - "id": { |
76 | | - "pattern": "^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}$", # noqa |
77 | | - "type": "string", |
78 | | - "description": "An identifier for the image" |
79 | | - }, |
80 | | - "name": { |
81 | | - "type": [ |
82 | | - "null", |
83 | | - "string" |
84 | | - ], |
85 | | - "description": "Descriptive name for the image", |
86 | | - "maxLength": 255 |
87 | | - }, |
88 | | - "owner": { |
89 | | - "type": [ |
90 | | - "null", |
91 | | - "string" |
92 | | - ], |
93 | | - "description": "Owner of the image", |
94 | | - "maxLength": 255 |
95 | | - }, |
96 | | - "protected": { |
97 | | - "type": "boolean", |
98 | | - "description": "If true, image will not be deletable." |
99 | | - }, |
100 | | - "self": { |
101 | | - "type": "string", |
102 | | - "description": "(READ-ONLY)" |
103 | | - }, |
104 | | - "schema": { |
105 | | - "type": "string", |
106 | | - "description": "(READ-ONLY)" |
107 | | - }, |
108 | | - "size": { |
109 | | - "type": [ |
110 | | - "null", |
111 | | - "integer", |
112 | | - "string" |
113 | | - ], |
114 | | - "description": "Size of image file in bytes (READ-ONLY)" |
115 | | - }, |
116 | | - "status": { |
117 | | - "enum": [ |
118 | | - "queued", |
119 | | - "saving", |
120 | | - "active", |
121 | | - "killed", |
122 | | - "deleted", |
123 | | - "pending_delete" |
124 | | - ], |
125 | | - "type": "string", |
126 | | - "description": "Status of the image (READ-ONLY)" |
127 | | - }, |
128 | | - "tags": { |
129 | | - "items": { |
130 | | - "type": "string", |
131 | | - "maxLength": 255 |
132 | | - }, |
133 | | - "type": "array", |
134 | | - "description": "List of strings related to the image" |
135 | | - }, |
136 | | - "visibility": { |
137 | | - "enum": [ |
138 | | - "public", |
139 | | - "private" |
140 | | - ], |
141 | | - "type": "string", |
142 | | - "description": "Scope of image accessibility" |
143 | | - }, |
144 | | - } |
145 | | -} |
146 | 28 |
|
147 | 29 |
|
148 | 30 | class FakeImagev2Client(object): |
@@ -231,61 +113,6 @@ def create_images(attrs=None, count=2): |
231 | 113 |
|
232 | 114 | return images |
233 | 115 |
|
234 | | - @staticmethod |
235 | | - def get_images(images=None, count=2): |
236 | | - """Get an iterable MagicMock object with a list of faked images. |
237 | | -
|
238 | | - If images list is provided, then initialize the Mock object with the |
239 | | - list. Otherwise create one. |
240 | | -
|
241 | | - :param List images: |
242 | | - A list of FakeResource objects faking images |
243 | | - :param Integer count: |
244 | | - The number of images to be faked |
245 | | - :return: |
246 | | - An iterable Mock object with side_effect set to a list of faked |
247 | | - images |
248 | | - """ |
249 | | - if images is None: |
250 | | - images = FakeImage.create_images(count) |
251 | | - |
252 | | - return mock.Mock(side_effect=images) |
253 | | - |
254 | | - @staticmethod |
255 | | - def get_image_columns(image=None): |
256 | | - """Get the image columns from a faked image object. |
257 | | -
|
258 | | - :param image: |
259 | | - A FakeResource objects faking image |
260 | | - :return: |
261 | | - A tuple which may include the following keys: |
262 | | - ('id', 'name', 'owner', 'protected', 'visibility', 'tags') |
263 | | - """ |
264 | | - if image is not None: |
265 | | - return tuple(sorted(image)) |
266 | | - return IMAGE_columns |
267 | | - |
268 | | - @staticmethod |
269 | | - def get_image_data(image=None): |
270 | | - """Get the image data from a faked image object. |
271 | | -
|
272 | | - :param image: |
273 | | - A FakeResource objects faking image |
274 | | - :return: |
275 | | - A tuple which may include the following values: |
276 | | - ('image-123', 'image-foo', 'admin', False, 'public', 'bar, baz') |
277 | | - """ |
278 | | - data_list = [] |
279 | | - if image is not None: |
280 | | - for x in sorted(image.keys()): |
281 | | - if x == 'tags': |
282 | | - # The 'tags' should be format_list |
283 | | - data_list.append( |
284 | | - format_columns.ListColumn(getattr(image, x))) |
285 | | - else: |
286 | | - data_list.append(getattr(image, x)) |
287 | | - return tuple(data_list) |
288 | | - |
289 | 116 | @staticmethod |
290 | 117 | def create_one_image_member(attrs=None): |
291 | 118 | """Create a fake image member. |
|
0 commit comments