summaryrefslogtreecommitdiff
path: root/openstackclient/tests/object
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2013-08-30 17:55:37 -0500
committerDean Troyer <dtroyer@gmail.com>2013-09-26 13:34:11 -0500
commitad59b03be6af9da31230689af268139b12b548e7 (patch)
tree0394d365ab2b1d847ae20f46b0c208a71e5dd9a3 /openstackclient/tests/object
parent74f4e3138996e258d4bdce1a162a5dade62a0c15 (diff)
downloadpython-openstackclient-ad59b03be6af9da31230689af268139b12b548e7.tar.gz
Add object-store show commands
* Add lib.container.show_container() and lib.object.show_object() * Add container and object show commands Change-Id: I963d664c55b59739453345f0f353aa2eaf1bf70e
Diffstat (limited to 'openstackclient/tests/object')
-rw-r--r--openstackclient/tests/object/test_container.py46
-rw-r--r--openstackclient/tests/object/test_object.py51
-rw-r--r--openstackclient/tests/object/v1/lib/test_container.py59
-rw-r--r--openstackclient/tests/object/v1/lib/test_object.py77
4 files changed, 217 insertions, 16 deletions
diff --git a/openstackclient/tests/object/test_container.py b/openstackclient/tests/object/test_container.py
index 9b53e360..24d67633 100644
--- a/openstackclient/tests/object/test_container.py
+++ b/openstackclient/tests/object/test_container.py
@@ -313,3 +313,49 @@ class TestContainerList(TestObject):
(object_fakes.container_name_3, ),
)
self.assertEqual(tuple(data), datalist)
+
+
+@mock.patch(
+ 'openstackclient.object.v1.container.lib_container.show_container'
+)
+class TestContainerShow(TestObject):
+
+ def setUp(self):
+ super(TestContainerShow, self).setUp()
+
+ # Get the command object to test
+ self.cmd = container.ShowContainer(self.app, None)
+
+ def test_container_show(self, c_mock):
+ c_mock.return_value = copy.deepcopy(object_fakes.CONTAINER)
+
+ arglist = [
+ object_fakes.container_name,
+ ]
+ verifylist = [
+ ('container', object_fakes.container_name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ }
+ # lib.container.show_container(api, url, container)
+ c_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name,
+ **kwargs
+ )
+
+ collist = ('bytes', 'count', 'name')
+ self.assertEqual(columns, collist)
+ datalist = (
+ object_fakes.container_bytes,
+ object_fakes.container_count,
+ object_fakes.container_name,
+ )
+ self.assertEqual(data, datalist)
diff --git a/openstackclient/tests/object/test_object.py b/openstackclient/tests/object/test_object.py
index ddd5b592..1ceb0a59 100644
--- a/openstackclient/tests/object/test_object.py
+++ b/openstackclient/tests/object/test_object.py
@@ -360,3 +360,54 @@ class TestObjectList(TestObject):
(object_fakes.object_name_2, ),
)
self.assertEqual(tuple(data), datalist)
+
+
+@mock.patch(
+ 'openstackclient.object.v1.object.lib_object.show_object'
+)
+class TestObjectShow(TestObject):
+
+ def setUp(self):
+ super(TestObjectShow, self).setUp()
+
+ # Get the command object to test
+ self.cmd = obj.ShowObject(self.app, None)
+
+ def test_object_show(self, c_mock):
+ c_mock.return_value = copy.deepcopy(object_fakes.OBJECT)
+
+ arglist = [
+ object_fakes.container_name,
+ object_fakes.object_name_1,
+ ]
+ verifylist = [
+ ('container', object_fakes.container_name),
+ ('object', object_fakes.object_name_1),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ }
+ # lib.container.show_container(api, url, container)
+ c_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name,
+ object_fakes.object_name_1,
+ **kwargs
+ )
+
+ collist = ('bytes', 'content_type', 'hash', 'last_modified', 'name')
+ self.assertEqual(columns, collist)
+ datalist = (
+ object_fakes.object_bytes_1,
+ object_fakes.object_content_type_1,
+ object_fakes.object_hash_1,
+ object_fakes.object_modified_1,
+ object_fakes.object_name_1,
+ )
+ self.assertEqual(data, datalist)
diff --git a/openstackclient/tests/object/v1/lib/test_container.py b/openstackclient/tests/object/v1/lib/test_container.py
index 1c0112c8..3b9976a1 100644
--- a/openstackclient/tests/object/v1/lib/test_container.py
+++ b/openstackclient/tests/object/v1/lib/test_container.py
@@ -15,19 +15,17 @@
"""Test Object API library module"""
-from __future__ import unicode_literals
-
import mock
-
from openstackclient.object.v1.lib import container as lib_container
from openstackclient.tests.common import test_restapi as restapi
from openstackclient.tests import fakes
from openstackclient.tests import utils
+fake_account = 'q12we34r'
fake_auth = '11223344556677889900'
-fake_url = 'http://gopher.com'
+fake_url = 'http://gopher.com/v1/' + fake_account
fake_container = 'rainbarrel'
@@ -38,18 +36,18 @@ class FakeClient(object):
self.token = fake_auth
-class TestObject(utils.TestCommand):
+class TestContainer(utils.TestCommand):
def setUp(self):
- super(TestObject, self).setUp()
+ super(TestContainer, self).setUp()
self.app.client_manager = fakes.FakeClientManager()
self.app.client_manager.object = FakeClient()
self.app.restapi = mock.MagicMock()
-class TestObjectListContainers(TestObject):
+class TestContainerList(TestContainer):
- def test_list_containers_no_options(self):
+ def test_container_list_no_options(self):
resp = [{'name': 'is-name'}]
self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
@@ -65,7 +63,7 @@ class TestObjectListContainers(TestObject):
)
self.assertEqual(data, resp)
- def test_list_containers_marker(self):
+ def test_container_list_marker(self):
resp = [{'name': 'is-name'}]
self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
@@ -82,7 +80,7 @@ class TestObjectListContainers(TestObject):
)
self.assertEqual(data, resp)
- def test_list_containers_limit(self):
+ def test_container_list_limit(self):
resp = [{'name': 'is-name'}]
self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
@@ -99,7 +97,7 @@ class TestObjectListContainers(TestObject):
)
self.assertEqual(data, resp)
- def test_list_containers_end_marker(self):
+ def test_container_list_end_marker(self):
resp = [{'name': 'is-name'}]
self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
@@ -116,7 +114,7 @@ class TestObjectListContainers(TestObject):
)
self.assertEqual(data, resp)
- def test_list_containers_prefix(self):
+ def test_container_list_prefix(self):
resp = [{'name': 'is-name'}]
self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
@@ -133,7 +131,7 @@ class TestObjectListContainers(TestObject):
)
self.assertEqual(data, resp)
- def test_list_containers_full_listing(self):
+ def test_container_list_full_listing(self):
def side_effect(*args, **kwargs):
rv = self.app.restapi.request.return_value
@@ -159,3 +157,38 @@ class TestObjectListContainers(TestObject):
fake_url + '?format=json&marker=is-name',
)
self.assertEqual(data, resp)
+
+
+class TestContainerShow(TestContainer):
+
+ def test_container_show_no_options(self):
+ resp = {
+ 'x-container-object-count': 1,
+ 'x-container-bytes-used': 577,
+ }
+ self.app.restapi.request.return_value = \
+ restapi.FakeResponse(headers=resp)
+
+ data = lib_container.show_container(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ 'is-name',
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'HEAD',
+ fake_url + '/is-name',
+ )
+
+ data_expected = {
+ 'account': fake_account,
+ 'container': 'is-name',
+ 'object_count': 1,
+ 'bytes_used': 577,
+ 'read_acl': None,
+ 'write_acl': None,
+ 'sync_to': None,
+ 'sync_key': None,
+ }
+ self.assertEqual(data, data_expected)
diff --git a/openstackclient/tests/object/v1/lib/test_object.py b/openstackclient/tests/object/v1/lib/test_object.py
index b4793cc2..0104183e 100644
--- a/openstackclient/tests/object/v1/lib/test_object.py
+++ b/openstackclient/tests/object/v1/lib/test_object.py
@@ -15,8 +15,6 @@
"""Test Object API library module"""
-from __future__ import unicode_literals
-
import mock
from openstackclient.object.v1.lib import object as lib_object
@@ -25,10 +23,12 @@ from openstackclient.tests import fakes
from openstackclient.tests import utils
+fake_account = 'q12we34r'
fake_auth = '11223344556677889900'
-fake_url = 'http://gopher.com'
+fake_url = 'http://gopher.com/v1/' + fake_account
fake_container = 'rainbarrel'
+fake_object = 'raindrop'
class FakeClient(object):
@@ -203,3 +203,74 @@ class TestObjectListObjects(TestObject):
fake_url + '/' + fake_container + '?format=json&marker=is-name',
)
self.assertEqual(data, resp)
+
+
+class TestObjectShowObjects(TestObject):
+
+ def test_object_show_no_options(self):
+ resp = {
+ 'content-type': 'text/alpha',
+ }
+ self.app.restapi.request.return_value = \
+ restapi.FakeResponse(headers=resp)
+
+ data = lib_object.show_object(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ fake_object,
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'HEAD',
+ fake_url + '/%s/%s' % (fake_container, fake_object),
+ )
+
+ data_expected = {
+ 'account': fake_account,
+ 'container': fake_container,
+ 'object': fake_object,
+ 'content-type': 'text/alpha',
+ }
+ self.assertEqual(data, data_expected)
+
+ def test_object_show_all_options(self):
+ resp = {
+ 'content-type': 'text/alpha',
+ 'content-length': 577,
+ 'last-modified': '20130101',
+ 'etag': 'qaz',
+ 'x-object-manifest': None,
+ 'x-object-meta-wife': 'Wilma',
+ 'x-tra-header': 'yabba-dabba-do',
+ }
+ self.app.restapi.request.return_value = \
+ restapi.FakeResponse(headers=resp)
+
+ data = lib_object.show_object(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ fake_object,
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'HEAD',
+ fake_url + '/%s/%s' % (fake_container, fake_object),
+ )
+
+ data_expected = {
+ 'account': fake_account,
+ 'container': fake_container,
+ 'object': fake_object,
+ 'content-type': 'text/alpha',
+ 'content-length': 577,
+ 'last-modified': '20130101',
+ 'etag': 'qaz',
+ 'x-object-manifest': None,
+ 'Wife': 'Wilma',
+ 'X-Tra-Header': 'yabba-dabba-do',
+ }
+ self.assertEqual(data, data_expected)