summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2013-08-20 15:13:41 -0500
committerDean Troyer <dtroyer@gmail.com>2013-08-28 22:16:34 -0500
commit725e2543efef8913ec9e69769eb45d5bc3d56aad (patch)
tree1f8c526a2306356eca8784b4f4add395f189257b /openstackclient/tests
parent17f13f7bf4cea80e8e1380fbc8295318de5be383 (diff)
downloadpython-openstackclient-725e2543efef8913ec9e69769eb45d5bc3d56aad.tar.gz
Object API commands using our REST API layer
* Add object-store API to ClientManager * Add object-store client * Add Object API library in openstackclient.object.v1.lib * Add Object API {container,object} list commands * Add library tests * Add command tests This should complete the Object v1 container and object list commands Change-Id: Ib1770d45efa8871959826b85faafa1e0bcef0a03
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/fakes.py5
-rw-r--r--openstackclient/tests/object/__init__.py12
-rw-r--r--openstackclient/tests/object/fakes.py67
-rw-r--r--openstackclient/tests/object/test_container.py315
-rw-r--r--openstackclient/tests/object/test_object.py362
-rw-r--r--openstackclient/tests/object/v1/__init__.py12
-rw-r--r--openstackclient/tests/object/v1/lib/__init__.py12
-rw-r--r--openstackclient/tests/object/v1/lib/test_container.py159
-rw-r--r--openstackclient/tests/object/v1/lib/test_object.py203
-rw-r--r--openstackclient/tests/utils.py1
10 files changed, 1148 insertions, 0 deletions
diff --git a/openstackclient/tests/fakes.py b/openstackclient/tests/fakes.py
index d0cd4a9f..e0122022 100644
--- a/openstackclient/tests/fakes.py
+++ b/openstackclient/tests/fakes.py
@@ -44,6 +44,11 @@ class FakeClientManager(object):
pass
+class FakeRESTApi(object):
+ def __init__(self):
+ pass
+
+
class FakeResource(object):
def __init__(self, manager, info, loaded=False):
self.manager = manager
diff --git a/openstackclient/tests/object/__init__.py b/openstackclient/tests/object/__init__.py
new file mode 100644
index 00000000..02be10cd
--- /dev/null
+++ b/openstackclient/tests/object/__init__.py
@@ -0,0 +1,12 @@
+# 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.
+#
diff --git a/openstackclient/tests/object/fakes.py b/openstackclient/tests/object/fakes.py
new file mode 100644
index 00000000..fbc784aa
--- /dev/null
+++ b/openstackclient/tests/object/fakes.py
@@ -0,0 +1,67 @@
+# 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.
+#
+
+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,
+}
diff --git a/openstackclient/tests/object/test_container.py b/openstackclient/tests/object/test_container.py
new file mode 100644
index 00000000..9b53e360
--- /dev/null
+++ b/openstackclient/tests/object/test_container.py
@@ -0,0 +1,315 @@
+# 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.common import clientmanager
+from openstackclient.object.v1 import container
+from openstackclient.tests.object import fakes as object_fakes
+from openstackclient.tests import utils
+
+
+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 TestObject(utils.TestCommand):
+ def setUp(self):
+ super(TestObject, self).setUp()
+
+ api_version = {"object-store": "1"}
+ self.app.client_manager = clientmanager.ClientManager(
+ token=AUTH_TOKEN,
+ url=AUTH_URL,
+ auth_url=AUTH_URL,
+ api_version=api_version,
+ )
+
+
+class TestObjectClient(TestObject):
+
+ def test_make_client(self):
+ self.assertEqual(self.app.client_manager.object.endpoint, AUTH_URL)
+ self.assertEqual(self.app.client_manager.object.token, AUTH_TOKEN)
+
+
+@mock.patch(
+ 'openstackclient.object.v1.container.lib_container.list_containers'
+)
+class TestContainerList(TestObject):
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ }
+ c_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.container_name, ),
+ (object_fakes.container_name_3, ),
+ (object_fakes.container_name_2, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'prefix': 'bit',
+ }
+ c_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.container_name, ),
+ (object_fakes.container_name_3, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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,
+ ]
+ verifylist = [
+ ('marker', 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 = {
+ 'marker': object_fakes.container_name,
+ }
+ c_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.container_name, ),
+ (object_fakes.container_name_3, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ def test_object_list_containers_end_marker(self, c_mock):
+ c_mock.return_value = [
+ copy.deepcopy(object_fakes.CONTAINER),
+ copy.deepcopy(object_fakes.CONTAINER_3),
+ ]
+
+ arglist = [
+ '--end-marker', object_fakes.container_name_3,
+ ]
+ verifylist = [
+ ('end_marker', object_fakes.container_name_3),
+ ]
+ 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 = {
+ 'end_marker': object_fakes.container_name_3,
+ }
+ c_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.container_name, ),
+ (object_fakes.container_name_3, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'limit': 2,
+ }
+ c_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.container_name, ),
+ (object_fakes.container_name_3, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ }
+ c_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ **kwargs
+ )
+
+ collist = ('Name', 'Bytes', 'Count')
+ self.assertEqual(columns, collist)
+ 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(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'full_listing': True,
+ }
+ c_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.container_name, ),
+ (object_fakes.container_name_2, ),
+ (object_fakes.container_name_3, ),
+ )
+ self.assertEqual(tuple(data), datalist)
diff --git a/openstackclient/tests/object/test_object.py b/openstackclient/tests/object/test_object.py
new file mode 100644
index 00000000..ddd5b592
--- /dev/null
+++ b/openstackclient/tests/object/test_object.py
@@ -0,0 +1,362 @@
+# 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.common import clientmanager
+from openstackclient.object.v1 import object as obj
+from openstackclient.tests.object import fakes as object_fakes
+from openstackclient.tests import utils
+
+
+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 TestObject(utils.TestCommand):
+ def setUp(self):
+ super(TestObject, self).setUp()
+
+ api_version = {"object-store": "1"}
+ self.app.client_manager = clientmanager.ClientManager(
+ token=AUTH_TOKEN,
+ url=AUTH_URL,
+ auth_url=AUTH_URL,
+ api_version=api_version,
+ )
+
+
+class TestObjectClient(TestObject):
+
+ def test_make_client(self):
+ self.assertEqual(self.app.client_manager.object.endpoint, AUTH_URL)
+ self.assertEqual(self.app.client_manager.object.token, AUTH_TOKEN)
+
+
+@mock.patch(
+ 'openstackclient.object.v1.object.lib_object.list_objects'
+)
+class TestObjectList(TestObject):
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ o_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name,
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.object_name_1, ),
+ (object_fakes.object_name_2, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'prefix': 'floppy',
+ }
+ o_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name_2,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.object_name_2, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'delimiter': '=',
+ }
+ o_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name_2,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.object_name_2, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'marker': object_fakes.object_name_2,
+ }
+ o_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name_2,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.object_name_2, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'end_marker': object_fakes.object_name_2,
+ }
+ o_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name_2,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.object_name_2, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'limit': 2,
+ }
+ o_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name_2,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.object_name_2, ),
+ )
+ self.assertEqual(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ }
+ o_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name,
+ **kwargs
+ )
+
+ collist = ('Name', 'Bytes', 'Hash', 'Content Type', 'Last Modified')
+ self.assertEqual(columns, collist)
+ 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(tuple(data), datalist)
+
+ 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)
+
+ # DisplayCommandBase.take_action() returns two tuples
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'full_listing': True,
+ }
+ o_mock.assert_called_with(
+ self.app.restapi,
+ AUTH_URL,
+ object_fakes.container_name,
+ **kwargs
+ )
+
+ collist = ('Name',)
+ self.assertEqual(columns, collist)
+ datalist = (
+ (object_fakes.object_name_1, ),
+ (object_fakes.object_name_2, ),
+ )
+ self.assertEqual(tuple(data), datalist)
diff --git a/openstackclient/tests/object/v1/__init__.py b/openstackclient/tests/object/v1/__init__.py
new file mode 100644
index 00000000..02be10cd
--- /dev/null
+++ b/openstackclient/tests/object/v1/__init__.py
@@ -0,0 +1,12 @@
+# 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.
+#
diff --git a/openstackclient/tests/object/v1/lib/__init__.py b/openstackclient/tests/object/v1/lib/__init__.py
new file mode 100644
index 00000000..02be10cd
--- /dev/null
+++ b/openstackclient/tests/object/v1/lib/__init__.py
@@ -0,0 +1,12 @@
+# 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.
+#
diff --git a/openstackclient/tests/object/v1/lib/test_container.py b/openstackclient/tests/object/v1/lib/test_container.py
new file mode 100644
index 00000000..a241cc02
--- /dev/null
+++ b/openstackclient/tests/object/v1/lib/test_container.py
@@ -0,0 +1,159 @@
+# 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.
+#
+
+"""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 utils
+
+
+fake_auth = '11223344556677889900'
+fake_url = 'http://gopher.com'
+
+fake_container = 'rainbarrel'
+
+
+class FakeClient(object):
+ def __init__(self, endpoint=None, **kwargs):
+ self.endpoint = fake_url
+ self.token = fake_auth
+
+
+class TestObject(utils.TestCommand):
+
+ def setUp(self):
+ super(TestObject, self).setUp()
+ self.app.client_manager.object = FakeClient()
+ self.app.restapi = mock.MagicMock()
+
+
+class TestObjectListContainers(TestObject):
+
+ def test_list_containers_no_options(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_container.list_containers(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '?format=json',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_containers_marker(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_container.list_containers(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ marker='next',
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '?format=json&marker=next',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_containers_limit(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_container.list_containers(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ limit=5,
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '?format=json&limit=5',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_containers_end_marker(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_container.list_containers(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ end_marker='last',
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '?format=json&end_marker=last',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_containers_prefix(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_container.list_containers(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ prefix='foo/',
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '?format=json&prefix=foo/',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_containers_full_listing(self):
+
+ def side_effect(*args, **kwargs):
+ rv = self.app.restapi.request.return_value
+ self.app.restapi.request.return_value = restapi.FakeResponse(
+ data=[],
+ )
+ self.app.restapi.request.side_effect = None
+ return rv
+
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+ self.app.restapi.request.side_effect = side_effect
+
+ data = lib_container.list_containers(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ full_listing=True,
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '?format=json&marker=is-name',
+ )
+ self.assertEqual(data, resp)
diff --git a/openstackclient/tests/object/v1/lib/test_object.py b/openstackclient/tests/object/v1/lib/test_object.py
new file mode 100644
index 00000000..ef8ae18d
--- /dev/null
+++ b/openstackclient/tests/object/v1/lib/test_object.py
@@ -0,0 +1,203 @@
+# 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.
+#
+
+"""Test Object API library module"""
+
+from __future__ import unicode_literals
+
+import mock
+
+from openstackclient.object.v1.lib import object as lib_object
+from openstackclient.tests.common import test_restapi as restapi
+from openstackclient.tests import utils
+
+
+fake_auth = '11223344556677889900'
+fake_url = 'http://gopher.com'
+
+fake_container = 'rainbarrel'
+
+
+class FakeClient(object):
+ def __init__(self, endpoint=None, **kwargs):
+ self.endpoint = fake_url
+ self.token = fake_auth
+
+
+class TestObject(utils.TestCommand):
+
+ def setUp(self):
+ super(TestObject, self).setUp()
+ self.app.client_manager.object = FakeClient()
+ self.app.restapi = mock.MagicMock()
+
+
+class TestObjectListObjects(TestObject):
+
+ def test_list_objects_no_options(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_object.list_objects(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '/' + fake_container + '?format=json',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_objects_marker(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_object.list_objects(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ marker='next',
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '/' + fake_container + '?format=json&marker=next',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_objects_limit(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_object.list_objects(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ limit=5,
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '/' + fake_container + '?format=json&limit=5',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_objects_end_marker(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_object.list_objects(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ end_marker='last',
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '/' + fake_container + '?format=json&end_marker=last',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_objects_delimiter(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_object.list_objects(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ delimiter='|',
+ )
+
+ # Check expected values
+ # NOTE(dtroyer): requests handles the URL encoding and we're
+ # mocking that so use the otherwise-not-legal
+ # pipe '|' char in the response.
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '/' + fake_container + '?format=json&delimiter=|',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_objects_prefix(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_object.list_objects(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ prefix='foo/',
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '/' + fake_container + '?format=json&prefix=foo/',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_objects_path(self):
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+
+ data = lib_object.list_objects(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ path='next',
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '/' + fake_container + '?format=json&path=next',
+ )
+ self.assertEqual(data, resp)
+
+ def test_list_objects_full_listing(self):
+
+ def side_effect(*args, **kwargs):
+ rv = self.app.restapi.request.return_value
+ self.app.restapi.request.return_value = restapi.FakeResponse(
+ data=[],
+ )
+ self.app.restapi.request.side_effect = None
+ return rv
+
+ resp = [{'name': 'is-name'}]
+ self.app.restapi.request.return_value = restapi.FakeResponse(data=resp)
+ self.app.restapi.request.side_effect = side_effect
+
+ data = lib_object.list_objects(
+ self.app.restapi,
+ self.app.client_manager.object.endpoint,
+ fake_container,
+ full_listing=True,
+ )
+
+ # Check expected values
+ self.app.restapi.request.assert_called_with(
+ 'GET',
+ fake_url + '/' + fake_container + '?format=json&marker=is-name',
+ )
+ self.assertEqual(data, resp)
diff --git a/openstackclient/tests/utils.py b/openstackclient/tests/utils.py
index ff7d8a33..45163189 100644
--- a/openstackclient/tests/utils.py
+++ b/openstackclient/tests/utils.py
@@ -71,6 +71,7 @@ class TestCommand(TestCase):
self.fake_stdout = fakes.FakeStdout()
self.app = fakes.FakeApp(self.fake_stdout)
self.app.client_manager = fakes.FakeClientManager()
+ self.app.restapi = fakes.FakeRESTApi()
def check_parser(self, cmd, args, verify_args):
cmd_parser = cmd.get_parser('check_parser')