Add volume test cases and structure

add basic unit test for client
update/modify test_shell.py to include volume

Change-Id: I7d08e15a2711da5e51590b8a82eca3a1234962f8
This commit is contained in:
Steve Martinelli 2013-02-11 16:10:25 -06:00
parent 7072b4f802
commit 79001ce88a
3 changed files with 74 additions and 2 deletions

@ -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)

14
tests/volume/__init__.py Normal file

@ -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.
#

@ -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)