summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-01 17:48:11 +0000
committerGerrit Code Review <review@openstack.org>2017-06-01 17:48:11 +0000
commit3707717f8f36160994b11097924e9d2d1a60edff (patch)
treed474d5d553002852824d942173560ae6c340879c /openstackclient/tests
parentd034b980ab03bbd50d31ef8bd439bc80a91a7d77 (diff)
parent6962cc963e6e17e709524ecf6a395e2d0c8b8370 (diff)
downloadpython-openstackclient-3707717f8f36160994b11097924e9d2d1a60edff.tar.gz
Merge "To display image size in human friendly format"
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/unit/image/v1/fakes.py2
-rw-r--r--openstackclient/tests/unit/image/v1/test_image.py27
-rw-r--r--openstackclient/tests/unit/image/v2/fakes.py9
-rw-r--r--openstackclient/tests/unit/image/v2/test_image.py26
4 files changed, 60 insertions, 4 deletions
diff --git a/openstackclient/tests/unit/image/v1/fakes.py b/openstackclient/tests/unit/image/v1/fakes.py
index 080356ee..4b6d278c 100644
--- a/openstackclient/tests/unit/image/v1/fakes.py
+++ b/openstackclient/tests/unit/image/v1/fakes.py
@@ -34,6 +34,7 @@ image_properties = {
}
image_properties_str = "Alpha='a', Beta='b', Gamma='g'"
image_data = 'line 1\nline 2\n'
+image_size = 0
IMAGE = {
'id': image_id,
@@ -46,6 +47,7 @@ IMAGE = {
'is_public': image_public,
'protected': image_protected,
'properties': image_properties,
+ 'size': image_size,
}
IMAGE_columns = tuple(sorted(IMAGE))
diff --git a/openstackclient/tests/unit/image/v1/test_image.py b/openstackclient/tests/unit/image/v1/test_image.py
index 036c8336..41ddc49f 100644
--- a/openstackclient/tests/unit/image/v1/test_image.py
+++ b/openstackclient/tests/unit/image/v1/test_image.py
@@ -692,7 +692,8 @@ class TestImageSet(TestImage):
class TestImageShow(TestImage):
- _image = image_fakes.FakeImage.create_one_image()
+ _image = image_fakes.FakeImage.create_one_image(
+ attrs={'size': 2000})
columns = (
'container_format',
'disk_format',
@@ -704,6 +705,7 @@ class TestImageShow(TestImage):
'owner',
'properties',
'protected',
+ 'size',
)
data = (
_image.container_format,
@@ -716,6 +718,7 @@ class TestImageShow(TestImage):
_image.owner,
utils.format_dict(_image.properties),
_image.protected,
+ _image.size,
)
def setUp(self):
@@ -745,3 +748,25 @@ class TestImageShow(TestImage):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
+
+ def test_image_show_human_readable(self):
+ arglist = [
+ '--human-readable',
+ self._image.id,
+ ]
+ verifylist = [
+ ('human_readable', True),
+ ('image', self._image.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+ self.images_mock.get.assert_called_with(
+ self._image.id,
+ )
+
+ size_index = columns.index('size')
+ self.assertEqual(data[size_index], '2K')
diff --git a/openstackclient/tests/unit/image/v2/fakes.py b/openstackclient/tests/unit/image/v2/fakes.py
index 7b214587..0255ce38 100644
--- a/openstackclient/tests/unit/image/v2/fakes.py
+++ b/openstackclient/tests/unit/image/v2/fakes.py
@@ -32,6 +32,7 @@ image_owner = 'baal'
image_protected = False
image_visibility = 'public'
image_tags = []
+image_size = 0
IMAGE = {
'id': image_id,
@@ -39,7 +40,8 @@ IMAGE = {
'owner': image_owner,
'protected': image_protected,
'visibility': image_visibility,
- 'tags': image_tags
+ 'tags': image_tags,
+ 'size': image_size
}
IMAGE_columns = tuple(sorted(IMAGE))
@@ -106,7 +108,8 @@ IMAGE_schema = {
"size": {
"type": [
"null",
- "integer"
+ "integer",
+ "string"
],
"description": "Size of image file in bytes (READ-ONLY)"
},
@@ -185,7 +188,7 @@ class FakeImage(object):
A dictionary with all attrbutes of image
:return:
A FakeResource object with id, name, owner, protected,
- visibility and tags attrs
+ visibility, tags and size attrs
"""
attrs = attrs or {}
diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py
index 164185df..65764e98 100644
--- a/openstackclient/tests/unit/image/v2/test_image.py
+++ b/openstackclient/tests/unit/image/v2/test_image.py
@@ -1288,6 +1288,9 @@ class TestImageSet(TestImage):
class TestImageShow(TestImage):
+ new_image = image_fakes.FakeImage.create_one_image(
+ attrs={'size': 1000})
+
def setUp(self):
super(TestImageShow, self).setUp()
@@ -1322,6 +1325,29 @@ class TestImageShow(TestImage):
self.assertEqual(image_fakes.IMAGE_columns, columns)
self.assertEqual(image_fakes.IMAGE_SHOW_data, data)
+ def test_image_show_human_readable(self):
+ self.images_mock.get.return_value = self.new_image
+ arglist = [
+ '--human-readable',
+ self.new_image.id,
+ ]
+ verifylist = [
+ ('human_readable', True),
+ ('image', self.new_image.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+ self.images_mock.get.assert_called_with(
+ self.new_image.id,
+ )
+
+ size_index = columns.index('size')
+ self.assertEqual(data[size_index], '1K')
+
class TestImageUnset(TestImage):