diff options
Diffstat (limited to 'openstackclient/tests/object')
| -rw-r--r-- | openstackclient/tests/object/__init__.py | 0 | ||||
| -rw-r--r-- | openstackclient/tests/object/v1/__init__.py | 0 | ||||
| -rw-r--r-- | openstackclient/tests/object/v1/fakes.py | 88 | ||||
| -rw-r--r-- | openstackclient/tests/object/v1/test_container.py | 407 | ||||
| -rw-r--r-- | openstackclient/tests/object/v1/test_container_all.py | 345 | ||||
| -rw-r--r-- | openstackclient/tests/object/v1/test_object.py | 382 | ||||
| -rw-r--r-- | openstackclient/tests/object/v1/test_object_all.py | 182 |
7 files changed, 0 insertions, 1404 deletions
diff --git a/openstackclient/tests/object/__init__.py b/openstackclient/tests/object/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/openstackclient/tests/object/__init__.py +++ /dev/null diff --git a/openstackclient/tests/object/v1/__init__.py b/openstackclient/tests/object/v1/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/openstackclient/tests/object/v1/__init__.py +++ /dev/null diff --git a/openstackclient/tests/object/v1/fakes.py b/openstackclient/tests/object/v1/fakes.py deleted file mode 100644 index 6c367111..00000000 --- a/openstackclient/tests/object/v1/fakes.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2013 Nebula Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -from keystoneauth1 import session - -from openstackclient.api import object_store_v1 as object_store -from openstackclient.tests import utils - - -ACCOUNT_ID = 'tqbfjotld' -ENDPOINT = 'https://0.0.0.0:6482/v1/' + ACCOUNT_ID - -container_name = 'bit-bucket' -container_bytes = 1024 -container_count = 1 - -container_name_2 = 'archive' -container_name_3 = 'bit-blit' - -CONTAINER = { - 'name': container_name, - 'bytes': container_bytes, - 'count': container_count, -} - -CONTAINER_2 = { - 'name': container_name_2, - 'bytes': container_bytes * 2, - 'count': container_count * 2, -} - -CONTAINER_3 = { - 'name': container_name_3, - 'bytes': container_bytes * 3, - 'count': container_count * 3, -} - -object_name_1 = 'punch-card' -object_bytes_1 = 80 -object_hash_1 = '1234567890' -object_content_type_1 = 'text' -object_modified_1 = 'today' - -object_name_2 = 'floppy-disk' -object_bytes_2 = 1440000 -object_hash_2 = '0987654321' -object_content_type_2 = 'text' -object_modified_2 = 'today' - -OBJECT = { - 'name': object_name_1, - 'bytes': object_bytes_1, - 'hash': object_hash_1, - 'content_type': object_content_type_1, - 'last_modified': object_modified_1, -} - -OBJECT_2 = { - 'name': object_name_2, - 'bytes': object_bytes_2, - 'hash': object_hash_2, - 'content_type': object_content_type_2, - 'last_modified': object_modified_2, -} - - -class TestObjectv1(utils.TestCommand): - - def setUp(self): - super(TestObjectv1, self).setUp() - - self.app.client_manager.session = session.Session() - self.app.client_manager.object_store = object_store.APIv1( - session=self.app.client_manager.session, - endpoint=ENDPOINT, - ) diff --git a/openstackclient/tests/object/v1/test_container.py b/openstackclient/tests/object/v1/test_container.py deleted file mode 100644 index 41bc6e8c..00000000 --- a/openstackclient/tests/object/v1/test_container.py +++ /dev/null @@ -1,407 +0,0 @@ -# Copyright 2013 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -import copy -import mock - -from openstackclient.api import object_store_v1 as object_store -from openstackclient.object.v1 import container -from openstackclient.tests.object.v1 import fakes as object_fakes - - -AUTH_TOKEN = "foobar" -AUTH_URL = "http://0.0.0.0" - - -class FakeClient(object): - - def __init__(self, endpoint=None, **kwargs): - self.endpoint = AUTH_URL - self.token = AUTH_TOKEN - - -class TestContainer(object_fakes.TestObjectv1): - - columns = ('Name',) - - def setUp(self): - super(TestContainer, self).setUp() - self.app.client_manager.object_store = object_store.APIv1( - session=mock.Mock(), - service_type="object-store", - ) - self.api = self.app.client_manager.object_store - - -@mock.patch('openstackclient.api.object_store_v1.APIv1.object_delete') -@mock.patch('openstackclient.api.object_store_v1.APIv1.object_list') -@mock.patch('openstackclient.api.object_store_v1.APIv1.container_delete') -class TestContainerDelete(TestContainer): - - def setUp(self): - super(TestContainerDelete, self).setUp() - - # Get the command object to test - self.cmd = container.DeleteContainer(self.app, None) - - def test_container_delete(self, c_mock, o_list_mock, o_delete_mock): - c_mock.return_value = None - - arglist = [ - object_fakes.container_name, - ] - verifylist = [ - ('containers', [object_fakes.container_name]), - ('recursive', False), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - self.assertIsNone(self.cmd.take_action(parsed_args)) - - kwargs = {} - c_mock.assert_called_with( - container=object_fakes.container_name, - **kwargs - ) - self.assertFalse(o_list_mock.called) - self.assertFalse(o_delete_mock.called) - - def test_recursive_delete(self, c_mock, o_list_mock, o_delete_mock): - c_mock.return_value = None - o_list_mock.return_value = [object_fakes.OBJECT] - o_delete_mock.return_value = None - - arglist = [ - '--recursive', - object_fakes.container_name, - ] - verifylist = [ - ('containers', [object_fakes.container_name]), - ('recursive', True), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - self.assertIsNone(self.cmd.take_action(parsed_args)) - - kwargs = {} - c_mock.assert_called_with( - container=object_fakes.container_name, - **kwargs - ) - o_list_mock.assert_called_with(container=object_fakes.container_name) - o_delete_mock.assert_called_with( - container=object_fakes.container_name, - object=object_fakes.OBJECT['name'], - ) - - def test_r_delete(self, c_mock, o_list_mock, o_delete_mock): - c_mock.return_value = None - o_list_mock.return_value = [object_fakes.OBJECT] - o_delete_mock.return_value = None - - arglist = [ - '-r', - object_fakes.container_name, - ] - verifylist = [ - ('containers', [object_fakes.container_name]), - ('recursive', True), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - self.assertIsNone(self.cmd.take_action(parsed_args)) - - kwargs = {} - c_mock.assert_called_with( - container=object_fakes.container_name, - **kwargs - ) - o_list_mock.assert_called_with(container=object_fakes.container_name) - o_delete_mock.assert_called_with( - container=object_fakes.container_name, - object=object_fakes.OBJECT['name'], - ) - - -@mock.patch( - 'openstackclient.api.object_store_v1.APIv1.container_list' -) -class TestContainerList(TestContainer): - - def setUp(self): - super(TestContainerList, self).setUp() - - # Get the command object to test - self.cmd = container.ListContainer(self.app, None) - - def test_object_list_containers_no_options(self, c_mock): - c_mock.return_value = [ - copy.deepcopy(object_fakes.CONTAINER), - copy.deepcopy(object_fakes.CONTAINER_3), - copy.deepcopy(object_fakes.CONTAINER_2), - ] - - arglist = [] - verifylist = [] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - } - c_mock.assert_called_with( - **kwargs - ) - - self.assertEqual(self.columns, columns) - datalist = ( - (object_fakes.container_name, ), - (object_fakes.container_name_3, ), - (object_fakes.container_name_2, ), - ) - self.assertEqual(datalist, tuple(data)) - - def test_object_list_containers_prefix(self, c_mock): - c_mock.return_value = [ - copy.deepcopy(object_fakes.CONTAINER), - copy.deepcopy(object_fakes.CONTAINER_3), - ] - - arglist = [ - '--prefix', 'bit', - ] - verifylist = [ - ('prefix', 'bit'), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'prefix': 'bit', - } - c_mock.assert_called_with( - **kwargs - ) - - self.assertEqual(self.columns, columns) - datalist = ( - (object_fakes.container_name, ), - (object_fakes.container_name_3, ), - ) - self.assertEqual(datalist, tuple(data)) - - def test_object_list_containers_marker(self, c_mock): - c_mock.return_value = [ - copy.deepcopy(object_fakes.CONTAINER), - copy.deepcopy(object_fakes.CONTAINER_3), - ] - - arglist = [ - '--marker', object_fakes.container_name, - '--end-marker', object_fakes.container_name_3, - ] - verifylist = [ - ('marker', object_fakes.container_name), - ('end_marker', object_fakes.container_name_3), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'marker': object_fakes.container_name, - 'end_marker': object_fakes.container_name_3, - } - c_mock.assert_called_with( - **kwargs - ) - - self.assertEqual(self.columns, columns) - datalist = ( - (object_fakes.container_name, ), - (object_fakes.container_name_3, ), - ) - self.assertEqual(datalist, tuple(data)) - - def test_object_list_containers_limit(self, c_mock): - c_mock.return_value = [ - copy.deepcopy(object_fakes.CONTAINER), - copy.deepcopy(object_fakes.CONTAINER_3), - ] - - arglist = [ - '--limit', '2', - ] - verifylist = [ - ('limit', 2), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'limit': 2, - } - c_mock.assert_called_with( - **kwargs - ) - - self.assertEqual(self.columns, columns) - datalist = ( - (object_fakes.container_name, ), - (object_fakes.container_name_3, ), - ) - self.assertEqual(datalist, tuple(data)) - - def test_object_list_containers_long(self, c_mock): - c_mock.return_value = [ - copy.deepcopy(object_fakes.CONTAINER), - copy.deepcopy(object_fakes.CONTAINER_3), - ] - - arglist = [ - '--long', - ] - verifylist = [ - ('long', True), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - } - c_mock.assert_called_with( - **kwargs - ) - - collist = ('Name', 'Bytes', 'Count') - self.assertEqual(collist, columns) - datalist = ( - ( - object_fakes.container_name, - object_fakes.container_bytes, - object_fakes.container_count, - ), - ( - object_fakes.container_name_3, - object_fakes.container_bytes * 3, - object_fakes.container_count * 3, - ), - ) - self.assertEqual(datalist, tuple(data)) - - def test_object_list_containers_all(self, c_mock): - c_mock.return_value = [ - copy.deepcopy(object_fakes.CONTAINER), - copy.deepcopy(object_fakes.CONTAINER_2), - copy.deepcopy(object_fakes.CONTAINER_3), - ] - - arglist = [ - '--all', - ] - verifylist = [ - ('all', True), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'full_listing': True, - } - c_mock.assert_called_with( - **kwargs - ) - - self.assertEqual(self.columns, columns) - datalist = ( - (object_fakes.container_name, ), - (object_fakes.container_name_2, ), - (object_fakes.container_name_3, ), - ) - self.assertEqual(datalist, tuple(data)) - - -@mock.patch( - 'openstackclient.api.object_store_v1.APIv1.container_show' -) -class TestContainerShow(TestContainer): - - 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) - - # 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) - - # Set expected values - kwargs = { - } - # lib.container.show_container(api, url, container) - c_mock.assert_called_with( - container=object_fakes.container_name, - **kwargs - ) - - collist = ('bytes', 'count', 'name') - self.assertEqual(collist, columns) - datalist = ( - object_fakes.container_bytes, - object_fakes.container_count, - object_fakes.container_name, - ) - self.assertEqual(datalist, data) diff --git a/openstackclient/tests/object/v1/test_container_all.py b/openstackclient/tests/object/v1/test_container_all.py deleted file mode 100644 index 95e12f47..00000000 --- a/openstackclient/tests/object/v1/test_container_all.py +++ /dev/null @@ -1,345 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -import copy - -from requests_mock.contrib import fixture - -from openstackclient.object.v1 import container as container_cmds -from openstackclient.tests.object.v1 import fakes as object_fakes - - -class TestContainerAll(object_fakes.TestObjectv1): - - def setUp(self): - super(TestContainerAll, self).setUp() - - self.requests_mock = self.useFixture(fixture.Fixture()) - - -class TestContainerCreate(TestContainerAll): - - columns = ( - 'account', - 'container', - 'x-trans-id', - ) - - def setUp(self): - super(TestContainerCreate, self).setUp() - - # Get the command object to test - self.cmd = container_cmds.CreateContainer(self.app, None) - - def test_object_create_container_single(self): - self.requests_mock.register_uri( - 'PUT', - object_fakes.ENDPOINT + '/ernie', - headers={'x-trans-id': '314159'}, - status_code=200, - ) - - arglist = [ - 'ernie', - ] - verifylist = [( - 'containers', ['ernie'], - )] - 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.assertEqual(self.columns, columns) - datalist = [( - object_fakes.ACCOUNT_ID, - 'ernie', - '314159', - )] - self.assertEqual(datalist, list(data)) - - def test_object_create_container_more(self): - self.requests_mock.register_uri( - 'PUT', - object_fakes.ENDPOINT + '/ernie', - headers={'x-trans-id': '314159'}, - status_code=200, - ) - self.requests_mock.register_uri( - 'PUT', - object_fakes.ENDPOINT + '/bert', - headers={'x-trans-id': '42'}, - status_code=200, - ) - - arglist = [ - 'ernie', - 'bert', - ] - verifylist = [( - 'containers', ['ernie', 'bert'], - )] - 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.assertEqual(self.columns, columns) - datalist = [ - ( - object_fakes.ACCOUNT_ID, - 'ernie', - '314159', - ), - ( - object_fakes.ACCOUNT_ID, - 'bert', - '42', - ), - ] - self.assertEqual(datalist, list(data)) - - -class TestContainerDelete(TestContainerAll): - - def setUp(self): - super(TestContainerDelete, self).setUp() - - # Get the command object to test - self.cmd = container_cmds.DeleteContainer(self.app, None) - - def test_object_delete_container_single(self): - self.requests_mock.register_uri( - 'DELETE', - object_fakes.ENDPOINT + '/ernie', - status_code=200, - ) - - arglist = [ - 'ernie', - ] - verifylist = [( - 'containers', ['ernie'], - )] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # Command.take_action() returns None - ret = self.cmd.take_action(parsed_args) - self.assertIsNone(ret) - - def test_object_delete_container_more(self): - self.requests_mock.register_uri( - 'DELETE', - object_fakes.ENDPOINT + '/ernie', - status_code=200, - ) - self.requests_mock.register_uri( - 'DELETE', - object_fakes.ENDPOINT + '/bert', - status_code=200, - ) - - arglist = [ - 'ernie', - 'bert', - ] - verifylist = [( - 'containers', ['ernie', 'bert'], - )] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # Command.take_action() returns None - ret = self.cmd.take_action(parsed_args) - self.assertIsNone(ret) - - -class TestContainerList(TestContainerAll): - - columns = ('Name',) - - def setUp(self): - super(TestContainerList, self).setUp() - - # Get the command object to test - self.cmd = container_cmds.ListContainer(self.app, None) - - def test_object_list_containers_no_options(self): - return_body = [ - copy.deepcopy(object_fakes.CONTAINER), - copy.deepcopy(object_fakes.CONTAINER_3), - copy.deepcopy(object_fakes.CONTAINER_2), - ] - self.requests_mock.register_uri( - 'GET', - object_fakes.ENDPOINT + '?format=json', - json=return_body, - status_code=200, - ) - - arglist = [] - verifylist = [] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # Lister.take_action() returns two tuples - columns, data = self.cmd.take_action(parsed_args) - - self.assertEqual(self.columns, columns) - datalist = [ - (object_fakes.container_name, ), - (object_fakes.container_name_3, ), - (object_fakes.container_name_2, ), - ] - self.assertEqual(datalist, list(data)) - - def test_object_list_containers_prefix(self): - return_body = [ - copy.deepcopy(object_fakes.CONTAINER), - copy.deepcopy(object_fakes.CONTAINER_3), - ] - self.requests_mock.register_uri( - 'GET', - object_fakes.ENDPOINT + '?format=json&prefix=bit', - json=return_body, - status_code=200, - ) - - arglist = [ - '--prefix', 'bit', - ] - verifylist = [ - ('prefix', 'bit'), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # Lister.take_action() returns two tuples - columns, data = self.cmd.take_action(parsed_args) - - self.assertEqual(self.columns, columns) - datalist = [ - (object_fakes.container_name, ), - (object_fakes.container_name_3, ), - ] - self.assertEqual(datalist, list(data)) - - -class TestContainerSave(TestContainerAll): - - def setUp(self): - super(TestContainerSave, self).setUp() - - # Get the command object to test - self.cmd = container_cmds.SaveContainer(self.app, None) - -# TODO(dtroyer): need to mock out object_lib.save_object() to test this -# def test_object_save_container(self): -# return_body = [ -# copy.deepcopy(object_fakes.OBJECT), -# copy.deepcopy(object_fakes.OBJECT_2), -# ] -# # Initial container list request -# self.requests_mock.register_uri( -# 'GET', -# object_fakes.ENDPOINT + '/oscar?format=json', -# json=return_body, -# status_code=200, -# ) -# # Individual object save requests -# self.requests_mock.register_uri( -# 'GET', -# object_fakes.ENDPOINT + '/oscar/' + object_fakes.object_name_1, -# json=object_fakes.OBJECT, -# status_code=200, -# ) -# self.requests_mock.register_uri( -# 'GET', -# object_fakes.ENDPOINT + '/oscar/' + object_fakes.object_name_2, -# json=object_fakes.OBJECT_2, -# status_code=200, -# ) -# -# arglist = [ -# 'oscar', -# ] -# verifylist = [( -# 'container', 'oscar', -# )] -# parsed_args = self.check_parser(self.cmd, arglist, verifylist) -# -# # Command.take_action() returns None -# ret = self.cmd.take_action(parsed_args) -# self.assertIsNone(ret) - - -class TestContainerShow(TestContainerAll): - - def setUp(self): - super(TestContainerShow, self).setUp() - - # Get the command object to test - self.cmd = container_cmds.ShowContainer(self.app, None) - - def test_object_show_container(self): - headers = { - 'x-container-object-count': '42', - 'x-container-bytes-used': '123', - 'x-container-read': 'qaz', - 'x-container-write': 'wsx', - 'x-container-sync-to': 'edc', - 'x-container-sync-key': 'rfv', - } - self.requests_mock.register_uri( - 'HEAD', - object_fakes.ENDPOINT + '/ernie', - headers=headers, - status_code=200, - ) - - arglist = [ - 'ernie', - ] - verifylist = [( - 'container', 'ernie', - )] - 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) - - collist = ( - 'account', - 'bytes_used', - 'container', - 'object_count', - 'read_acl', - 'sync_key', - 'sync_to', - 'write_acl', - ) - self.assertEqual(collist, columns) - datalist = [ - object_fakes.ACCOUNT_ID, - '123', - 'ernie', - '42', - 'qaz', - 'rfv', - 'edc', - 'wsx', - ] - self.assertEqual(datalist, list(data)) diff --git a/openstackclient/tests/object/v1/test_object.py b/openstackclient/tests/object/v1/test_object.py deleted file mode 100644 index e11f78a1..00000000 --- a/openstackclient/tests/object/v1/test_object.py +++ /dev/null @@ -1,382 +0,0 @@ -# Copyright 2013 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -import copy -import mock - -from openstackclient.api import object_store_v1 as object_store -from openstackclient.object.v1 import object as obj -from openstackclient.tests.object.v1 import fakes as object_fakes - - -AUTH_TOKEN = "foobar" -AUTH_URL = "http://0.0.0.0" - - -class TestObject(object_fakes.TestObjectv1): - - def setUp(self): - super(TestObject, self).setUp() - self.app.client_manager.object_store = object_store.APIv1( - session=mock.Mock(), - service_type="object-store", - ) - self.api = self.app.client_manager.object_store - - -@mock.patch( - 'openstackclient.api.object_store_v1.APIv1.object_list' -) -class TestObjectList(TestObject): - - columns = ('Name',) - datalist = ( - ( - object_fakes.object_name_2, - ), - ) - - def setUp(self): - super(TestObjectList, self).setUp() - - # Get the command object to test - self.cmd = obj.ListObject(self.app, None) - - def test_object_list_objects_no_options(self, o_mock): - o_mock.return_value = [ - copy.deepcopy(object_fakes.OBJECT), - copy.deepcopy(object_fakes.OBJECT_2), - ] - - arglist = [ - object_fakes.container_name, - ] - verifylist = [ - ('container', object_fakes.container_name), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - o_mock.assert_called_with( - container=object_fakes.container_name, - ) - - self.assertEqual(self.columns, columns) - datalist = ( - (object_fakes.object_name_1, ), - (object_fakes.object_name_2, ), - ) - self.assertEqual(datalist, tuple(data)) - - def test_object_list_objects_prefix(self, o_mock): - o_mock.return_value = [ - copy.deepcopy(object_fakes.OBJECT_2), - ] - - arglist = [ - '--prefix', 'floppy', - object_fakes.container_name_2, - ] - verifylist = [ - ('prefix', 'floppy'), - ('container', object_fakes.container_name_2), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'prefix': 'floppy', - } - o_mock.assert_called_with( - container=object_fakes.container_name_2, - **kwargs - ) - - self.assertEqual(self.columns, columns) - self.assertEqual(self.datalist, tuple(data)) - - def test_object_list_objects_delimiter(self, o_mock): - o_mock.return_value = [ - copy.deepcopy(object_fakes.OBJECT_2), - ] - - arglist = [ - '--delimiter', '=', - object_fakes.container_name_2, - ] - verifylist = [ - ('delimiter', '='), - ('container', object_fakes.container_name_2), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'delimiter': '=', - } - o_mock.assert_called_with( - container=object_fakes.container_name_2, - **kwargs - ) - - self.assertEqual(self.columns, columns) - self.assertEqual(self.datalist, tuple(data)) - - def test_object_list_objects_marker(self, o_mock): - o_mock.return_value = [ - copy.deepcopy(object_fakes.OBJECT_2), - ] - - arglist = [ - '--marker', object_fakes.object_name_2, - object_fakes.container_name_2, - ] - verifylist = [ - ('marker', object_fakes.object_name_2), - ('container', object_fakes.container_name_2), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'marker': object_fakes.object_name_2, - } - o_mock.assert_called_with( - container=object_fakes.container_name_2, - **kwargs - ) - - self.assertEqual(self.columns, columns) - self.assertEqual(self.datalist, tuple(data)) - - def test_object_list_objects_end_marker(self, o_mock): - o_mock.return_value = [ - copy.deepcopy(object_fakes.OBJECT_2), - ] - - arglist = [ - '--end-marker', object_fakes.object_name_2, - object_fakes.container_name_2, - ] - verifylist = [ - ('end_marker', object_fakes.object_name_2), - ('container', object_fakes.container_name_2), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'end_marker': object_fakes.object_name_2, - } - o_mock.assert_called_with( - container=object_fakes.container_name_2, - **kwargs - ) - - self.assertEqual(self.columns, columns) - self.assertEqual(self.datalist, tuple(data)) - - def test_object_list_objects_limit(self, o_mock): - o_mock.return_value = [ - copy.deepcopy(object_fakes.OBJECT_2), - ] - - arglist = [ - '--limit', '2', - object_fakes.container_name_2, - ] - verifylist = [ - ('limit', 2), - ('container', object_fakes.container_name_2), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'limit': 2, - } - o_mock.assert_called_with( - container=object_fakes.container_name_2, - **kwargs - ) - - self.assertEqual(self.columns, columns) - self.assertEqual(self.datalist, tuple(data)) - - def test_object_list_objects_long(self, o_mock): - o_mock.return_value = [ - copy.deepcopy(object_fakes.OBJECT), - copy.deepcopy(object_fakes.OBJECT_2), - ] - - arglist = [ - '--long', - object_fakes.container_name, - ] - verifylist = [ - ('long', True), - ('container', object_fakes.container_name), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - } - o_mock.assert_called_with( - container=object_fakes.container_name, - **kwargs - ) - - collist = ('Name', 'Bytes', 'Hash', 'Content Type', 'Last Modified') - self.assertEqual(collist, columns) - datalist = ( - ( - object_fakes.object_name_1, - object_fakes.object_bytes_1, - object_fakes.object_hash_1, - object_fakes.object_content_type_1, - object_fakes.object_modified_1, - ), - ( - object_fakes.object_name_2, - object_fakes.object_bytes_2, - object_fakes.object_hash_2, - object_fakes.object_content_type_2, - object_fakes.object_modified_2, - ), - ) - self.assertEqual(datalist, tuple(data)) - - def test_object_list_objects_all(self, o_mock): - o_mock.return_value = [ - copy.deepcopy(object_fakes.OBJECT), - copy.deepcopy(object_fakes.OBJECT_2), - ] - - arglist = [ - '--all', - object_fakes.container_name, - ] - verifylist = [ - ('all', True), - ('container', object_fakes.container_name), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - # Set expected values - kwargs = { - 'full_listing': True, - } - o_mock.assert_called_with( - container=object_fakes.container_name, - **kwargs - ) - - self.assertEqual(self.columns, columns) - datalist = ( - (object_fakes.object_name_1, ), - (object_fakes.object_name_2, ), - ) - self.assertEqual(datalist, tuple(data)) - - -@mock.patch( - 'openstackclient.api.object_store_v1.APIv1.object_show' -) -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) - - # 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) - - # Set expected values - kwargs = { - } - # lib.container.show_container(api, url, container) - c_mock.assert_called_with( - container=object_fakes.container_name, - object=object_fakes.object_name_1, - **kwargs - ) - - collist = ('bytes', 'content_type', 'hash', 'last_modified', 'name') - self.assertEqual(collist, columns) - 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(datalist, data) diff --git a/openstackclient/tests/object/v1/test_object_all.py b/openstackclient/tests/object/v1/test_object_all.py deleted file mode 100644 index 2a1bf059..00000000 --- a/openstackclient/tests/object/v1/test_object_all.py +++ /dev/null @@ -1,182 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -import copy - -from requests_mock.contrib import fixture - -from openstackclient.object.v1 import object as object_cmds -from openstackclient.tests.object.v1 import fakes as object_fakes - - -class TestObjectAll(object_fakes.TestObjectv1): - - def setUp(self): - super(TestObjectAll, self).setUp() - - self.requests_mock = self.useFixture(fixture.Fixture()) - - -class TestObjectCreate(TestObjectAll): - - def setUp(self): - super(TestObjectCreate, self).setUp() - - # Get the command object to test - self.cmd = object_cmds.CreateObject(self.app, None) - - -class TestObjectList(TestObjectAll): - - columns = ('Name',) - - def setUp(self): - super(TestObjectList, self).setUp() - - # Get the command object to test - self.cmd = object_cmds.ListObject(self.app, None) - - def test_object_list_objects_no_options(self): - return_body = [ - copy.deepcopy(object_fakes.OBJECT), - copy.deepcopy(object_fakes.OBJECT_2), - ] - self.requests_mock.register_uri( - 'GET', - object_fakes.ENDPOINT + - '/' + - object_fakes.container_name + - '?format=json', - json=return_body, - status_code=200, - ) - - arglist = [ - object_fakes.container_name, - ] - verifylist = [ - ('container', object_fakes.container_name), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # Lister.take_action() returns two tuples - columns, data = self.cmd.take_action(parsed_args) - - self.assertEqual(self.columns, columns) - datalist = [ - (object_fakes.object_name_1, ), - (object_fakes.object_name_2, ), - ] - self.assertEqual(datalist, list(data)) - - def test_object_list_objects_prefix(self): - return_body = [ - copy.deepcopy(object_fakes.OBJECT_2), - ] - self.requests_mock.register_uri( - 'GET', - object_fakes.ENDPOINT + - '/' + - object_fakes.container_name_2 + - '?prefix=floppy&format=json', - json=return_body, - status_code=200, - ) - - arglist = [ - '--prefix', 'floppy', - object_fakes.container_name_2, - ] - verifylist = [ - ('prefix', 'floppy'), - ('container', object_fakes.container_name_2), - ] - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - - # In base command class Lister in cliff, abstract method take_action() - # returns a tuple containing the column names and an iterable - # containing the data to be listed. - columns, data = self.cmd.take_action(parsed_args) - - self.assertEqual(self.columns, columns) - datalist = ( - (object_fakes.object_name_2, ), - ) - self.assertEqual(datalist, tuple(data)) - - -class TestObjectShow(TestObjectAll): - - def setUp(self): - super(TestObjectShow, self).setUp() - - # Get the command object to test - self.cmd = object_cmds.ShowObject(self.app, None) - - def test_object_show(self): - headers = { - 'content-type': 'text/plain', - 'content-length': '20', - 'last-modified': 'yesterday', - 'etag': '4c4e39a763d58392724bccf76a58783a', - 'x-container-meta-owner': object_fakes.ACCOUNT_ID, - 'x-object-manifest': 'manifest', - } - self.requests_mock.register_uri( - 'HEAD', - '/'.join([ - object_fakes.ENDPOINT, - object_fakes.container_name, - object_fakes.object_name_1, - ]), - headers=headers, - status_code=200, - ) - - 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) - - # 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) - - collist = ( - 'account', - 'container', - 'content-length', - 'content-type', - 'etag', - 'last-modified', - 'object', - 'x-object-manifest', - ) - self.assertEqual(collist, columns) - datalist = ( - object_fakes.ACCOUNT_ID, - object_fakes.container_name, - '20', - 'text/plain', - '4c4e39a763d58392724bccf76a58783a', - 'yesterday', - object_fakes.object_name_1, - 'manifest', - ) - self.assertEqual(datalist, data) |
