Skip to content

Commit ce65164

Browse files
committed
Add functional tests for image set
This patch includes functional tests for image set and it includes a change to use the OSC utils.format_dict method to format the properties. This will give a more user friendly format to the image commands and it gives a more consistent testable format to the output. Instead of: {u'a': u'b', u'c': u'd'} The user will see: a=b, c=d Change-Id: Ib396316586ffc5dbab231064d5b6dc9425507934
1 parent deb5a97 commit ce65164

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

functional/tests/image/v1/test_image.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ImageTests(test.TestCase):
1919
"""Functional tests for image. """
2020

2121
NAME = uuid.uuid4().hex
22+
OTHER_NAME = uuid.uuid4().hex
2223
HEADERS = ['Name']
2324
FIELDS = ['name']
2425

@@ -31,7 +32,13 @@ def setUpClass(cls):
3132

3233
@classmethod
3334
def tearDownClass(cls):
34-
raw_output = cls.openstack('image delete ' + cls.NAME)
35+
# Rename test
36+
opts = cls.get_show_opts(cls.FIELDS)
37+
raw_output = cls.openstack(
38+
'image set --name ' + cls.OTHER_NAME + ' ' + cls.NAME + opts)
39+
cls.assertOutput(cls.OTHER_NAME + "\n", raw_output)
40+
# Delete test
41+
raw_output = cls.openstack('image delete ' + cls.OTHER_NAME)
3542
cls.assertOutput('', raw_output)
3643

3744
def test_image_list(self):
@@ -43,3 +50,17 @@ def test_image_show(self):
4350
opts = self.get_show_opts(self.FIELDS)
4451
raw_output = self.openstack('image show ' + self.NAME + opts)
4552
self.assertEqual(self.NAME + "\n", raw_output)
53+
54+
def test_image_set(self):
55+
opts = self.get_show_opts([
56+
"disk_format", "is_public", "min_disk", "min_ram", "name"])
57+
raw_output = self.openstack('image set --min-disk 4 --min-ram 5 ' +
58+
'--disk-format qcow2 --public ' +
59+
self.NAME + opts)
60+
self.assertEqual("qcow2\nTrue\n4\n5\n" + self.NAME + '\n', raw_output)
61+
62+
def test_image_metadata(self):
63+
opts = self.get_show_opts(["name", "properties"])
64+
raw_output = self.openstack(
65+
'image set --property a=b --property c=d ' + self.NAME + opts)
66+
self.assertEqual(self.NAME + "\na='b', c='d'\n", raw_output)

openstackclient/image/v1/image.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def take_action(self, parsed_args):
275275

276276
info = {}
277277
info.update(image._info)
278+
info['properties'] = utils.format_dict(info.get('properties', {}))
278279
return zip(*sorted(six.iteritems(info)))
279280

280281

@@ -608,6 +609,7 @@ def take_action(self, parsed_args):
608609

609610
info = {}
610611
info.update(image._info)
612+
info['properties'] = utils.format_dict(info.get('properties', {}))
611613
return zip(*sorted(six.iteritems(info)))
612614

613615

@@ -636,4 +638,5 @@ def take_action(self, parsed_args):
636638

637639
info = {}
638640
info.update(image._info)
641+
info['properties'] = utils.format_dict(info.get('properties', {}))
639642
return zip(*sorted(six.iteritems(info)))

openstackclient/tests/image/v1/fakes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
'Beta': 'b',
3131
'Gamma': 'g',
3232
}
33-
image_properties_str = "{'Alpha': 'a', 'Beta': 'b', 'Gamma': 'g'}"
33+
image_properties_str = "Alpha='a', Beta='b', Gamma='g'"
3434
image_data = 'line 1\nline 2\n'
3535

3636
IMAGE = {
@@ -47,7 +47,9 @@
4747
}
4848

4949
IMAGE_columns = tuple(sorted(IMAGE))
50-
IMAGE_data = tuple((IMAGE[x] for x in sorted(IMAGE)))
50+
IMAGE_output = dict(IMAGE)
51+
IMAGE_output['properties'] = image_properties_str
52+
IMAGE_data = tuple((IMAGE_output[x] for x in sorted(IMAGE_output)))
5153

5254

5355
class FakeImagev1Client(object):

0 commit comments

Comments
 (0)