diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2013-08-30 17:55:37 -0500 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2013-09-26 13:34:11 -0500 |
| commit | ad59b03be6af9da31230689af268139b12b548e7 (patch) | |
| tree | 0394d365ab2b1d847ae20f46b0c208a71e5dd9a3 /openstackclient/tests/object/v1 | |
| parent | 74f4e3138996e258d4bdce1a162a5dade62a0c15 (diff) | |
| download | python-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/v1')
| -rw-r--r-- | openstackclient/tests/object/v1/lib/test_container.py | 59 | ||||
| -rw-r--r-- | openstackclient/tests/object/v1/lib/test_object.py | 77 |
2 files changed, 120 insertions, 16 deletions
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) |
