From 79001ce88a7c0a2197cad32ae84565822ad9b40e Mon Sep 17 00:00:00 2001 From: Steve Martinelli Date: Mon, 11 Feb 2013 16:10:25 -0600 Subject: [PATCH] Add volume test cases and structure add basic unit test for client update/modify test_shell.py to include volume Change-Id: I7d08e15a2711da5e51590b8a82eca3a1234962f8 --- tests/test_shell.py | 11 ++++++-- tests/volume/__init__.py | 14 ++++++++++ tests/volume/test_volume.py | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 tests/volume/__init__.py create mode 100644 tests/volume/test_volume.py diff --git a/tests/test_shell.py b/tests/test_shell.py index d259785fa7..6b9b07609f 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -32,10 +32,12 @@ DEFAULT_SERVICE_URL = "http://127.0.0.1:8771/v3.0/" DEFAULT_COMPUTE_API_VERSION = "2" DEFAULT_IDENTITY_API_VERSION = "2.0" DEFAULT_IMAGE_API_VERSION = "v2" +DEFAULT_VOLUME_API_VERSION = "1" LIB_COMPUTE_API_VERSION = "2" LIB_IDENTITY_API_VERSION = "2.0" LIB_IMAGE_API_VERSION = "1.0" +LIB_VOLUME_API_VERSION = "1" def make_shell(): @@ -106,6 +108,8 @@ class TestShell(utils.TestCase): default_args["identity_api_version"]) self.assertEqual(_shell.options.os_image_api_version, default_args["image_api_version"]) + self.assertEqual(_shell.options.os_volume_api_version, + default_args["volume_api_version"]) class TestShellHelp(TestShell): @@ -252,6 +256,7 @@ class TestShellCli(TestShell): "OS_COMPUTE_API_VERSION": DEFAULT_COMPUTE_API_VERSION, "OS_IDENTITY_API_VERSION": DEFAULT_IDENTITY_API_VERSION, "OS_IMAGE_API_VERSION": DEFAULT_IMAGE_API_VERSION, + "OS_VOLUME_API_VERSION": DEFAULT_VOLUME_API_VERSION, } self.orig_env, os.environ = os.environ, env.copy() @@ -271,7 +276,8 @@ class TestShellCli(TestShell): kwargs = { "compute_api_version": DEFAULT_COMPUTE_API_VERSION, "identity_api_version": DEFAULT_IDENTITY_API_VERSION, - "image_api_version": DEFAULT_IMAGE_API_VERSION + "image_api_version": DEFAULT_IMAGE_API_VERSION, + "volume_api_version": DEFAULT_VOLUME_API_VERSION } self._assert_cli(flag, kwargs) @@ -281,6 +287,7 @@ class TestShellCli(TestShell): kwargs = { "compute_api_version": LIB_COMPUTE_API_VERSION, "identity_api_version": LIB_IDENTITY_API_VERSION, - "image_api_version": LIB_IMAGE_API_VERSION + "image_api_version": LIB_IMAGE_API_VERSION, + "volume_api_version": LIB_VOLUME_API_VERSION } self._assert_cli(flag, kwargs) diff --git a/tests/volume/__init__.py b/tests/volume/__init__.py new file mode 100644 index 0000000000..ebf59b327e --- /dev/null +++ b/tests/volume/__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/tests/volume/test_volume.py b/tests/volume/test_volume.py new file mode 100644 index 0000000000..8c60dd1242 --- /dev/null +++ b/tests/volume/test_volume.py @@ -0,0 +1,51 @@ +# 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.volume import client as volume_client +from 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 TestVolume(utils.TestCase): + def setUp(self): + super(TestVolume, self).setUp() + + api_version = {"volume": "1"} + + volume_client.API_VERSIONS = { + "1": "tests.volume.test_volume.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.volume.client.auth_token, AUTH_TOKEN) + self.assertEqual(self.cm.volume.client.auth_url, AUTH_URL)