diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py index 8827d0797e..40f9fce1a8 100644 --- a/openstackclient/image/v1/image.py +++ b/openstackclient/image/v1/image.py @@ -213,7 +213,7 @@ class DeleteImage(command.Command): image_client.images, parsed_args.image, ) - image_client.images.delete(image) + image_client.images.delete(image.id) class ListImage(lister.Lister): diff --git a/openstackclient/tests/compute/test_compute.py b/openstackclient/tests/compute/test_compute.py deleted file mode 100644 index 9d2061d284..0000000000 --- a/openstackclient/tests/compute/test_compute.py +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright 2013 OpenStack, LLC. -# -# 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 mock - -from openstackclient.common import clientmanager -from openstackclient.compute import client as compute_client -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.client = mock.MagicMock() - self.client.auth_url = AUTH_URL - - -class TestCompute(utils.TestCase): - def setUp(self): - super(TestCompute, self).setUp() - - api_version = {"compute": "2"} - - compute_client.API_VERSIONS = { - "2": "openstackclient.tests.compute.test_compute.FakeClient" - } - - self.cm = clientmanager.ClientManager(token=AUTH_TOKEN, - url=AUTH_URL, - auth_url=AUTH_URL, - api_version=api_version) - - def test_make_client(self): - self.assertEqual(self.cm.compute.client.auth_token, AUTH_TOKEN) - self.assertEqual(self.cm.compute.client.auth_url, AUTH_URL) diff --git a/openstackclient/tests/identity/v3/test_identity.py b/openstackclient/tests/compute/v2/__init__.py similarity index 57% rename from openstackclient/tests/identity/v3/test_identity.py rename to openstackclient/tests/compute/v2/__init__.py index 4b55ee4540..c534c012e8 100644 --- a/openstackclient/tests/identity/v3/test_identity.py +++ b/openstackclient/tests/compute/v2/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2013 Nebula Inc. +# 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 @@ -12,20 +12,3 @@ # License for the specific language governing permissions and limitations # under the License. # - -from openstackclient.tests.identity.v3 import fakes -from openstackclient.tests import utils - - -AUTH_TOKEN = "foobar" -AUTH_URL = "http://0.0.0.0" - - -class TestIdentityv3(utils.TestCommand): - def setUp(self): - super(TestIdentityv3, self).setUp() - - self.app.client_manager.identity = fakes.FakeIdentityv3Client( - endpoint=AUTH_URL, - token=AUTH_TOKEN, - ) diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py new file mode 100644 index 0000000000..8154449fbf --- /dev/null +++ b/openstackclient/tests/compute/v2/fakes.py @@ -0,0 +1,55 @@ +# 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. +# + +import mock + +from openstackclient.tests import fakes +from openstackclient.tests import utils + + +image_id = 'im1' + +IMAGE = { + 'id': image_id, +} + + +server_id = 'serv1' +server_name = 'waiter' + +SERVER = { + 'id': server_id, + 'name': server_name, +} + + +class FakeComputev2Client(object): + def __init__(self, **kwargs): + self.images = mock.Mock() + self.images.resource_class = fakes.FakeResource(None, {}) + self.servers = mock.Mock() + self.servers.resource_class = fakes.FakeResource(None, {}) + self.auth_token = kwargs['token'] + self.management_url = kwargs['endpoint'] + + +class TestComputev2(utils.TestCommand): + def setUp(self): + super(TestComputev2, self).setUp() + + self.app.client_manager.compute = FakeComputev2Client( + endpoint=fakes.AUTH_URL, + token=fakes.AUTH_TOKEN, + ) diff --git a/openstackclient/tests/compute/v2/test_server.py b/openstackclient/tests/compute/v2/test_server.py new file mode 100644 index 0000000000..7e68808e1d --- /dev/null +++ b/openstackclient/tests/compute/v2/test_server.py @@ -0,0 +1,63 @@ +# 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. +# + +import copy + +from openstackclient.compute.v2 import server +from openstackclient.tests.compute.v2 import fakes as compute_fakes +from openstackclient.tests import fakes + + +class TestServer(compute_fakes.TestComputev2): + + def setUp(self): + super(TestServer, self).setUp() + + # Get a shortcut to the ServerManager Mock + self.servers_mock = self.app.client_manager.compute.servers + self.servers_mock.reset_mock() + + +class TestServerDelete(TestServer): + + def setUp(self): + super(TestServerDelete, self).setUp() + + # This is the return value for utils.find_resource() + self.servers_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(compute_fakes.SERVER), + loaded=True, + ) + self.servers_mock.delete.return_value = None + + # Get the command object to test + self.cmd = server.DeleteServer(self.app, None) + + def test_server_delete_no_options(self): + arglist = [ + compute_fakes.server_id, + ] + verifylist = [ + ('server', compute_fakes.server_id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # DisplayCommandBase.take_action() returns two tuples + self.cmd.take_action(parsed_args) + + self.servers_mock.delete.assert_called_with( + compute_fakes.server_id, + ) diff --git a/openstackclient/tests/fakes.py b/openstackclient/tests/fakes.py index d6cf1d742f..8ab4546588 100644 --- a/openstackclient/tests/fakes.py +++ b/openstackclient/tests/fakes.py @@ -16,6 +16,10 @@ import sys +AUTH_TOKEN = "foobar" +AUTH_URL = "http://0.0.0.0" + + class FakeStdout: def __init__(self): self.content = [] diff --git a/openstackclient/tests/identity/v2_0/fakes.py b/openstackclient/tests/identity/v2_0/fakes.py index b1aeabd4ca..80febd29a4 100644 --- a/openstackclient/tests/identity/v2_0/fakes.py +++ b/openstackclient/tests/identity/v2_0/fakes.py @@ -16,6 +16,8 @@ import mock from openstackclient.tests import fakes +from openstackclient.tests import utils + project_id = '8-9-64' project_name = 'beatles' @@ -83,3 +85,13 @@ class FakeIdentityv2Client(object): self.ec2.resource_class = fakes.FakeResource(None, {}) self.auth_token = kwargs['token'] self.management_url = kwargs['endpoint'] + + +class TestIdentityv2(utils.TestCommand): + def setUp(self): + super(TestIdentityv2, self).setUp() + + self.app.client_manager.identity = FakeIdentityv2Client( + endpoint=fakes.AUTH_URL, + token=fakes.AUTH_TOKEN, + ) diff --git a/openstackclient/tests/identity/v2_0/test_project.py b/openstackclient/tests/identity/v2_0/test_project.py index 933bd0941d..30f4278bea 100644 --- a/openstackclient/tests/identity/v2_0/test_project.py +++ b/openstackclient/tests/identity/v2_0/test_project.py @@ -18,10 +18,9 @@ import copy from openstackclient.identity.v2_0 import project from openstackclient.tests import fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes -from openstackclient.tests.identity.v2_0 import test_identity -class TestProject(test_identity.TestIdentityv2): +class TestProject(identity_fakes.TestIdentityv2): def setUp(self): super(TestProject, self).setUp() diff --git a/openstackclient/tests/identity/v2_0/test_role.py b/openstackclient/tests/identity/v2_0/test_role.py index 56e9d4cb54..d515bd7cdb 100644 --- a/openstackclient/tests/identity/v2_0/test_role.py +++ b/openstackclient/tests/identity/v2_0/test_role.py @@ -20,10 +20,9 @@ from openstackclient.common import exceptions from openstackclient.identity.v2_0 import role from openstackclient.tests import fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes -from openstackclient.tests.identity.v2_0 import test_identity -class TestRole(test_identity.TestIdentityv2): +class TestRole(identity_fakes.TestIdentityv2): def setUp(self): super(TestRole, self).setUp() diff --git a/openstackclient/tests/identity/v2_0/test_service.py b/openstackclient/tests/identity/v2_0/test_service.py index f09c4137ad..6c93574bf5 100644 --- a/openstackclient/tests/identity/v2_0/test_service.py +++ b/openstackclient/tests/identity/v2_0/test_service.py @@ -18,10 +18,9 @@ import copy from openstackclient.identity.v2_0 import service from openstackclient.tests import fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes -from openstackclient.tests.identity.v2_0 import test_identity -class TestService(test_identity.TestIdentityv2): +class TestService(identity_fakes.TestIdentityv2): def setUp(self): super(TestService, self).setUp() diff --git a/openstackclient/tests/identity/v2_0/test_user.py b/openstackclient/tests/identity/v2_0/test_user.py index 2fe585ed96..a18d13d821 100644 --- a/openstackclient/tests/identity/v2_0/test_user.py +++ b/openstackclient/tests/identity/v2_0/test_user.py @@ -18,10 +18,9 @@ import copy from openstackclient.identity.v2_0 import user from openstackclient.tests import fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes -from openstackclient.tests.identity.v2_0 import test_identity -class TestUser(test_identity.TestIdentityv2): +class TestUser(identity_fakes.TestIdentityv2): def setUp(self): super(TestUser, self).setUp() diff --git a/openstackclient/tests/identity/v3/fakes.py b/openstackclient/tests/identity/v3/fakes.py index 1338553608..9d40d9dbec 100644 --- a/openstackclient/tests/identity/v3/fakes.py +++ b/openstackclient/tests/identity/v3/fakes.py @@ -16,6 +16,7 @@ import mock from openstackclient.tests import fakes +from openstackclient.tests import utils domain_id = 'd1' @@ -104,3 +105,13 @@ class FakeIdentityv3Client(object): self.users.resource_class = fakes.FakeResource(None, {}) self.auth_token = kwargs['token'] self.management_url = kwargs['endpoint'] + + +class TestIdentityv3(utils.TestCommand): + def setUp(self): + super(TestIdentityv3, self).setUp() + + self.app.client_manager.identity = FakeIdentityv3Client( + endpoint=fakes.AUTH_URL, + token=fakes.AUTH_TOKEN, + ) diff --git a/openstackclient/tests/identity/v3/test_project.py b/openstackclient/tests/identity/v3/test_project.py index 91c15e246d..02cb41bedb 100644 --- a/openstackclient/tests/identity/v3/test_project.py +++ b/openstackclient/tests/identity/v3/test_project.py @@ -18,10 +18,9 @@ import copy from openstackclient.identity.v3 import project from openstackclient.tests import fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes -from openstackclient.tests.identity.v3 import test_identity -class TestProject(test_identity.TestIdentityv3): +class TestProject(identity_fakes.TestIdentityv3): def setUp(self): super(TestProject, self).setUp() diff --git a/openstackclient/tests/identity/v3/test_role.py b/openstackclient/tests/identity/v3/test_role.py index ef2b3e057c..040c39dd1b 100644 --- a/openstackclient/tests/identity/v3/test_role.py +++ b/openstackclient/tests/identity/v3/test_role.py @@ -18,10 +18,9 @@ import copy from openstackclient.identity.v3 import role from openstackclient.tests import fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes -from openstackclient.tests.identity.v3 import test_identity -class TestRole(test_identity.TestIdentityv3): +class TestRole(identity_fakes.TestIdentityv3): def setUp(self): super(TestRole, self).setUp() diff --git a/openstackclient/tests/identity/v3/test_service.py b/openstackclient/tests/identity/v3/test_service.py index 1c3ae21e16..10d249c5db 100644 --- a/openstackclient/tests/identity/v3/test_service.py +++ b/openstackclient/tests/identity/v3/test_service.py @@ -18,10 +18,9 @@ import copy from openstackclient.identity.v3 import service from openstackclient.tests import fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes -from openstackclient.tests.identity.v3 import test_identity -class TestService(test_identity.TestIdentityv3): +class TestService(identity_fakes.TestIdentityv3): def setUp(self): super(TestService, self).setUp() diff --git a/openstackclient/tests/identity/v3/test_user.py b/openstackclient/tests/identity/v3/test_user.py index 8f195805c2..4321b04799 100644 --- a/openstackclient/tests/identity/v3/test_user.py +++ b/openstackclient/tests/identity/v3/test_user.py @@ -18,10 +18,9 @@ import copy from openstackclient.identity.v3 import user from openstackclient.tests import fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes -from openstackclient.tests.identity.v3 import test_identity -class TestUser(test_identity.TestIdentityv3): +class TestUser(identity_fakes.TestIdentityv3): def setUp(self): super(TestUser, self).setUp() diff --git a/openstackclient/tests/image/test_image.py b/openstackclient/tests/image/test_image.py deleted file mode 100644 index f4c8d72e37..0000000000 --- a/openstackclient/tests/image/test_image.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2013 OpenStack, LLC. -# -# 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 mock - -from openstackclient.common import clientmanager -from openstackclient.image import client as image_client -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.client = mock.MagicMock() - self.client.auth_token = AUTH_TOKEN - self.client.auth_url = AUTH_URL - - -class TestImage(utils.TestCase): - def setUp(self): - super(TestImage, self).setUp() - - api_version = {"image": "2"} - - image_client.API_VERSIONS = { - "2": "openstackclient.tests.image.test_image.FakeClient" - } - - self.cm = clientmanager.ClientManager(token=AUTH_TOKEN, - url=AUTH_URL, - auth_url=AUTH_URL, - api_version=api_version) - - def test_make_client(self): - self.assertEqual(self.cm.image.client.auth_token, AUTH_TOKEN) - self.assertEqual(self.cm.image.client.auth_url, AUTH_URL) diff --git a/openstackclient/tests/identity/v2_0/test_identity.py b/openstackclient/tests/image/v1/__init__.py similarity index 56% rename from openstackclient/tests/identity/v2_0/test_identity.py rename to openstackclient/tests/image/v1/__init__.py index 8a50a48a06..ebf59b327e 100644 --- a/openstackclient/tests/identity/v2_0/test_identity.py +++ b/openstackclient/tests/image/v1/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2013 Nebula Inc. +# Copyright 2013 OpenStack, LLC. # # 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 @@ -12,20 +12,3 @@ # License for the specific language governing permissions and limitations # under the License. # - -from openstackclient.tests.identity.v2_0 import fakes -from openstackclient.tests import utils - - -AUTH_TOKEN = "foobar" -AUTH_URL = "http://0.0.0.0" - - -class TestIdentityv2(utils.TestCommand): - def setUp(self): - super(TestIdentityv2, self).setUp() - - self.app.client_manager.identity = fakes.FakeIdentityv2Client( - endpoint=AUTH_URL, - token=AUTH_TOKEN, - ) diff --git a/openstackclient/tests/image/v1/fakes.py b/openstackclient/tests/image/v1/fakes.py new file mode 100644 index 0000000000..ea2af84ccd --- /dev/null +++ b/openstackclient/tests/image/v1/fakes.py @@ -0,0 +1,46 @@ +# 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. +# + +import mock + +from openstackclient.tests import fakes +from openstackclient.tests import utils + + +image_id = 'im1' +image_name = 'graven' + +IMAGE = { + 'id': image_id, + 'name': image_name +} + + +class FakeImagev1Client(object): + def __init__(self, **kwargs): + self.images = mock.Mock() + self.images.resource_class = fakes.FakeResource(None, {}) + self.auth_token = kwargs['token'] + self.management_url = kwargs['endpoint'] + + +class TestImagev1(utils.TestCommand): + def setUp(self): + super(TestImagev1, self).setUp() + + self.app.client_manager.image = FakeImagev1Client( + endpoint=fakes.AUTH_URL, + token=fakes.AUTH_TOKEN, + ) diff --git a/openstackclient/tests/image/v1/test_image.py b/openstackclient/tests/image/v1/test_image.py new file mode 100644 index 0000000000..a410674d71 --- /dev/null +++ b/openstackclient/tests/image/v1/test_image.py @@ -0,0 +1,63 @@ +# 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. +# + +import copy + +from openstackclient.image.v1 import image +from openstackclient.tests import fakes +from openstackclient.tests.image.v1 import fakes as image_fakes + + +class TestImage(image_fakes.TestImagev1): + + def setUp(self): + super(TestImage, self).setUp() + + # Get a shortcut to the ServerManager Mock + self.images_mock = self.app.client_manager.image.images + self.images_mock.reset_mock() + + +class TestImageDelete(TestImage): + + def setUp(self): + super(TestImageDelete, self).setUp() + + # This is the return value for utils.find_resource() + self.images_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(image_fakes.IMAGE), + loaded=True, + ) + self.images_mock.delete.return_value = None + + # Get the command object to test + self.cmd = image.DeleteImage(self.app, None) + + def test_image_delete_no_options(self): + arglist = [ + image_fakes.image_id, + ] + verifylist = [ + ('image', image_fakes.image_id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # DisplayCommandBase.take_action() returns two tuples + self.cmd.take_action(parsed_args) + + self.images_mock.delete.assert_called_with( + image_fakes.image_id, + ) diff --git a/openstackclient/tests/image/v2/__init__.py b/openstackclient/tests/image/v2/__init__.py new file mode 100644 index 0000000000..ebf59b327e --- /dev/null +++ b/openstackclient/tests/image/v2/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2013 OpenStack, LLC. +# +# 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/image/v2/fakes.py b/openstackclient/tests/image/v2/fakes.py new file mode 100644 index 0000000000..df6b80726a --- /dev/null +++ b/openstackclient/tests/image/v2/fakes.py @@ -0,0 +1,46 @@ +# 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. +# + +import mock + +from openstackclient.tests import fakes +from openstackclient.tests import utils + + +image_id = 'im1' +image_name = 'graven' + +IMAGE = { + 'id': image_id, + 'name': image_name +} + + +class FakeImagev2Client(object): + def __init__(self, **kwargs): + self.images = mock.Mock() + self.images.resource_class = fakes.FakeResource(None, {}) + self.auth_token = kwargs['token'] + self.management_url = kwargs['endpoint'] + + +class TestImagev2(utils.TestCommand): + def setUp(self): + super(TestImagev2, self).setUp() + + self.app.client_manager.image = FakeImagev2Client( + endpoint=fakes.AUTH_URL, + token=fakes.AUTH_TOKEN, + ) diff --git a/openstackclient/tests/image/v2/test_image.py b/openstackclient/tests/image/v2/test_image.py new file mode 100644 index 0000000000..ef84e2c04e --- /dev/null +++ b/openstackclient/tests/image/v2/test_image.py @@ -0,0 +1,63 @@ +# 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. +# + +import copy + +from openstackclient.image.v1 import image +from openstackclient.tests import fakes +from openstackclient.tests.image.v2 import fakes as image_fakes + + +class TestImage(image_fakes.TestImagev2): + + def setUp(self): + super(TestImage, self).setUp() + + # Get a shortcut to the ServerManager Mock + self.images_mock = self.app.client_manager.image.images + self.images_mock.reset_mock() + + +class TestImageDelete(TestImage): + + def setUp(self): + super(TestImageDelete, self).setUp() + + # This is the return value for utils.find_resource() + self.images_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(image_fakes.IMAGE), + loaded=True, + ) + self.images_mock.delete.return_value = None + + # Get the command object to test + self.cmd = image.DeleteImage(self.app, None) + + def test_image_delete_no_options(self): + arglist = [ + image_fakes.image_id, + ] + verifylist = [ + ('image', image_fakes.image_id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # DisplayCommandBase.take_action() returns two tuples + self.cmd.take_action(parsed_args) + + self.images_mock.delete.assert_called_with( + image_fakes.image_id, + ) diff --git a/openstackclient/tests/object/fakes.py b/openstackclient/tests/object/v1/fakes.py similarity index 100% rename from openstackclient/tests/object/fakes.py rename to openstackclient/tests/object/v1/fakes.py diff --git a/openstackclient/tests/object/test_container.py b/openstackclient/tests/object/v1/test_container.py similarity index 99% rename from openstackclient/tests/object/test_container.py rename to openstackclient/tests/object/v1/test_container.py index 24d6763376..2090b88029 100644 --- a/openstackclient/tests/object/test_container.py +++ b/openstackclient/tests/object/v1/test_container.py @@ -18,7 +18,7 @@ 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.object.v1 import fakes as object_fakes from openstackclient.tests import utils diff --git a/openstackclient/tests/object/test_object.py b/openstackclient/tests/object/v1/test_object.py similarity index 99% rename from openstackclient/tests/object/test_object.py rename to openstackclient/tests/object/v1/test_object.py index 1ceb0a59dd..52b5ebd086 100644 --- a/openstackclient/tests/object/test_object.py +++ b/openstackclient/tests/object/v1/test_object.py @@ -18,7 +18,7 @@ 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.object.v1 import fakes as object_fakes from openstackclient.tests import utils diff --git a/openstackclient/tests/volume/v1/fakes.py b/openstackclient/tests/volume/v1/fakes.py index a382dbb8b7..b25dfaf70a 100644 --- a/openstackclient/tests/volume/v1/fakes.py +++ b/openstackclient/tests/volume/v1/fakes.py @@ -16,6 +16,9 @@ import mock from openstackclient.tests import fakes +from openstackclient.tests.identity.v2_0 import fakes as identity_fakes +from openstackclient.tests import utils + volume_id = 'vvvvvvvv-vvvv-vvvv-vvvvvvvv' volume_name = 'nigel' @@ -42,3 +45,18 @@ class FakeVolumev1Client(object): self.services.resource_class = fakes.FakeResource(None, {}) self.auth_token = kwargs['token'] self.management_url = kwargs['endpoint'] + + +class TestVolumev1(utils.TestCommand): + def setUp(self): + super(TestVolumev1, self).setUp() + + self.app.client_manager.volume = FakeVolumev1Client( + endpoint=fakes.AUTH_URL, + token=fakes.AUTH_TOKEN, + ) + + self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client( + endpoint=fakes.AUTH_URL, + token=fakes.AUTH_TOKEN, + ) diff --git a/openstackclient/tests/volume/v1/test_volume.py b/openstackclient/tests/volume/v1/test_volume.py index 58024f0bfd..4e033dfeea 100644 --- a/openstackclient/tests/volume/v1/test_volume.py +++ b/openstackclient/tests/volume/v1/test_volume.py @@ -1,4 +1,4 @@ -# Copyright 2013 OpenStack, LLC. +# 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 @@ -13,25 +13,256 @@ # under the License. # +import copy + +from openstackclient.tests import fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes -from openstackclient.tests import utils -from openstackclient.tests.volume.v1 import fakes +from openstackclient.tests.volume.v1 import fakes as volume_fakes +from openstackclient.volume.v1 import volume -AUTH_TOKEN = "foobar" -AUTH_URL = "http://0.0.0.0" +class TestVolume(volume_fakes.TestVolumev1): - -class TestVolumev1(utils.TestCommand): def setUp(self): - super(TestVolumev1, self).setUp() + super(TestVolume, self).setUp() - self.app.client_manager.volume = fakes.FakeVolumev1Client( - endpoint=AUTH_URL, - token=AUTH_TOKEN, + # Get a shortcut to the VolumeManager Mock + self.volumes_mock = self.app.client_manager.volume.volumes + self.volumes_mock.reset_mock() + + # Get a shortcut to the TenantManager Mock + self.projects_mock = self.app.client_manager.identity.tenants + self.projects_mock.reset_mock() + + # Get a shortcut to the UserManager Mock + self.users_mock = self.app.client_manager.identity.users + self.users_mock.reset_mock() + + +# TODO(dtroyer): The volume create tests are incomplete, only the minimal +# options and the options that require additional processing +# are implemented at this time. + +class TestVolumeCreate(TestVolume): + + def setUp(self): + super(TestVolumeCreate, self).setUp() + + self.volumes_mock.create.return_value = fakes.FakeResource( + None, + copy.deepcopy(volume_fakes.VOLUME), + loaded=True, ) - self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client( - endpoint=AUTH_URL, - token=AUTH_TOKEN, + # Get the command object to test + self.cmd = volume.CreateVolume(self.app, None) + + def test_volume_create_min_options(self): + arglist = [ + '--size', str(volume_fakes.volume_size), + volume_fakes.volume_name, + ] + verifylist = [ + ('size', volume_fakes.volume_size), + ('name', volume_fakes.volume_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 = { + # 'metadata': volume_fakes.volume_metadata, + #} + # VolumeManager.create(size, snapshot_id=, source_volid=, + # display_name=, display_description=, + # volume_type=, user_id=, + # project_id=, availability_zone=, + # metadata=, imageRef=) + self.volumes_mock.create.assert_called_with( + volume_fakes.volume_size, + None, + None, + volume_fakes.volume_name, + None, + None, + None, + None, + None, + None, + None, ) + + collist = ( + 'attach_status', + 'display_description', + 'display_name', + 'id', + 'properties', + 'size', + 'status', + ) + self.assertEqual(columns, collist) + datalist = ( + 'detatched', + volume_fakes.volume_description, + volume_fakes.volume_name, + volume_fakes.volume_id, + '', + volume_fakes.volume_size, + '', + ) + self.assertEqual(data, datalist) + + def test_volume_create_user_project_id(self): + # Return a project + self.projects_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(identity_fakes.PROJECT), + loaded=True, + ) + # Return a user + self.users_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(identity_fakes.USER), + loaded=True, + ) + + arglist = [ + '--size', str(volume_fakes.volume_size), + '--project', identity_fakes.project_id, + '--user', identity_fakes.user_id, + volume_fakes.volume_name, + ] + verifylist = [ + ('size', volume_fakes.volume_size), + ('project', identity_fakes.project_id), + ('user', identity_fakes.user_id), + ('name', volume_fakes.volume_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 = { + # 'metadata': volume_fakes.volume_metadata, + #} + # VolumeManager.create(size, snapshot_id=, source_volid=, + # display_name=, display_description=, + # volume_type=, user_id=, + # project_id=, availability_zone=, + # metadata=, imageRef=) + self.volumes_mock.create.assert_called_with( + volume_fakes.volume_size, + None, + None, + volume_fakes.volume_name, + #volume_fakes.volume_description, + None, + None, + identity_fakes.user_id, + identity_fakes.project_id, + None, + None, + None, + ) + + collist = ( + 'attach_status', + 'display_description', + 'display_name', + 'id', + 'properties', + 'size', + 'status', + ) + self.assertEqual(columns, collist) + datalist = ( + 'detatched', + volume_fakes.volume_description, + volume_fakes.volume_name, + volume_fakes.volume_id, + '', + volume_fakes.volume_size, + '', + ) + self.assertEqual(data, datalist) + + def test_volume_create_user_project_name(self): + # Return a project + self.projects_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(identity_fakes.PROJECT), + loaded=True, + ) + # Return a user + self.users_mock.get.return_value = fakes.FakeResource( + None, + copy.deepcopy(identity_fakes.USER), + loaded=True, + ) + + arglist = [ + '--size', str(volume_fakes.volume_size), + '--project', identity_fakes.project_name, + '--user', identity_fakes.user_name, + volume_fakes.volume_name, + ] + verifylist = [ + ('size', volume_fakes.volume_size), + ('project', identity_fakes.project_name), + ('user', identity_fakes.user_name), + ('name', volume_fakes.volume_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 = { + # 'metadata': volume_fakes.volume_metadata, + #} + # VolumeManager.create(size, snapshot_id=, source_volid=, + # display_name=, display_description=, + # volume_type=, user_id=, + # project_id=, availability_zone=, + # metadata=, imageRef=) + self.volumes_mock.create.assert_called_with( + volume_fakes.volume_size, + None, + None, + volume_fakes.volume_name, + #volume_fakes.volume_description, + None, + None, + identity_fakes.user_id, + identity_fakes.project_id, + None, + None, + None, + ) + + collist = ( + 'attach_status', + 'display_description', + 'display_name', + 'id', + 'properties', + 'size', + 'status', + ) + self.assertEqual(columns, collist) + datalist = ( + 'detatched', + volume_fakes.volume_description, + volume_fakes.volume_name, + volume_fakes.volume_id, + '', + volume_fakes.volume_size, + '', + ) + self.assertEqual(data, datalist) diff --git a/openstackclient/tests/volume/v1/test_volumecmd.py b/openstackclient/tests/volume/v1/test_volumecmd.py deleted file mode 100644 index 1f5ed882aa..0000000000 --- a/openstackclient/tests/volume/v1/test_volumecmd.py +++ /dev/null @@ -1,269 +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. -# - -import copy - -from openstackclient.tests import fakes -from openstackclient.tests.identity.v2_0 import fakes as identity_fakes -from openstackclient.tests.volume.v1 import fakes as volume_fakes -from openstackclient.tests.volume.v1 import test_volume -from openstackclient.volume.v1 import volume - - -class TestVolume(test_volume.TestVolumev1): - - def setUp(self): - super(TestVolume, self).setUp() - - # Get a shortcut to the VolumeManager Mock - self.volumes_mock = self.app.client_manager.volume.volumes - self.volumes_mock.reset_mock() - - # Get a shortcut to the TenantManager Mock - self.projects_mock = self.app.client_manager.identity.tenants - self.projects_mock.reset_mock() - - # Get a shortcut to the UserManager Mock - self.users_mock = self.app.client_manager.identity.users - self.users_mock.reset_mock() - - -# TODO(dtroyer): The volume create tests are incomplete, only the minimal -# options and the options that require additional processing -# are implemented at this time. - -class TestVolumeCreate(TestVolume): - - def setUp(self): - super(TestVolumeCreate, self).setUp() - - self.volumes_mock.create.return_value = fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.VOLUME), - loaded=True, - ) - - # Get the command object to test - self.cmd = volume.CreateVolume(self.app, None) - - def test_volume_create_min_options(self): - arglist = [ - '--size', str(volume_fakes.volume_size), - volume_fakes.volume_name, - ] - verifylist = [ - ('size', volume_fakes.volume_size), - ('name', volume_fakes.volume_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 = { - # 'metadata': volume_fakes.volume_metadata, - #} - # VolumeManager.create(size, snapshot_id=, source_volid=, - # display_name=, display_description=, - # volume_type=, user_id=, - # project_id=, availability_zone=, - # metadata=, imageRef=) - self.volumes_mock.create.assert_called_with( - volume_fakes.volume_size, - None, - None, - volume_fakes.volume_name, - None, - None, - None, - None, - None, - None, - None, - ) - - collist = ( - 'attach_status', - 'display_description', - 'display_name', - 'id', - 'properties', - 'size', - 'status', - ) - self.assertEqual(columns, collist) - datalist = ( - 'detatched', - volume_fakes.volume_description, - volume_fakes.volume_name, - volume_fakes.volume_id, - '', - volume_fakes.volume_size, - '', - ) - self.assertEqual(data, datalist) - - def test_volume_create_user_project_id(self): - # Return a project - self.projects_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.PROJECT), - loaded=True, - ) - # Return a user - self.users_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.USER), - loaded=True, - ) - - arglist = [ - '--size', str(volume_fakes.volume_size), - '--project', identity_fakes.project_id, - '--user', identity_fakes.user_id, - volume_fakes.volume_name, - ] - verifylist = [ - ('size', volume_fakes.volume_size), - ('project', identity_fakes.project_id), - ('user', identity_fakes.user_id), - ('name', volume_fakes.volume_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 = { - # 'metadata': volume_fakes.volume_metadata, - #} - # VolumeManager.create(size, snapshot_id=, source_volid=, - # display_name=, display_description=, - # volume_type=, user_id=, - # project_id=, availability_zone=, - # metadata=, imageRef=) - self.volumes_mock.create.assert_called_with( - volume_fakes.volume_size, - None, - None, - volume_fakes.volume_name, - #volume_fakes.volume_description, - None, - None, - identity_fakes.user_id, - identity_fakes.project_id, - None, - None, - None, - ) - - collist = ( - 'attach_status', - 'display_description', - 'display_name', - 'id', - 'properties', - 'size', - 'status', - ) - self.assertEqual(columns, collist) - datalist = ( - 'detatched', - volume_fakes.volume_description, - volume_fakes.volume_name, - volume_fakes.volume_id, - '', - volume_fakes.volume_size, - '', - ) - self.assertEqual(data, datalist) - - def test_volume_create_user_project_name(self): - # Return a project - self.projects_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.PROJECT), - loaded=True, - ) - # Return a user - self.users_mock.get.return_value = fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.USER), - loaded=True, - ) - - arglist = [ - '--size', str(volume_fakes.volume_size), - '--project', identity_fakes.project_name, - '--user', identity_fakes.user_name, - volume_fakes.volume_name, - ] - verifylist = [ - ('size', volume_fakes.volume_size), - ('project', identity_fakes.project_name), - ('user', identity_fakes.user_name), - ('name', volume_fakes.volume_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 = { - # 'metadata': volume_fakes.volume_metadata, - #} - # VolumeManager.create(size, snapshot_id=, source_volid=, - # display_name=, display_description=, - # volume_type=, user_id=, - # project_id=, availability_zone=, - # metadata=, imageRef=) - self.volumes_mock.create.assert_called_with( - volume_fakes.volume_size, - None, - None, - volume_fakes.volume_name, - #volume_fakes.volume_description, - None, - None, - identity_fakes.user_id, - identity_fakes.project_id, - None, - None, - None, - ) - - collist = ( - 'attach_status', - 'display_description', - 'display_name', - 'id', - 'properties', - 'size', - 'status', - ) - self.assertEqual(columns, collist) - datalist = ( - 'detatched', - volume_fakes.volume_description, - volume_fakes.volume_name, - volume_fakes.volume_id, - '', - volume_fakes.volume_size, - '', - ) - self.assertEqual(data, datalist)