summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2013-01-24 12:33:17 -0600
committerDean Troyer <dtroyer@gmail.com>2013-01-28 17:58:59 -0600
commit4297e5781b03bad1c67cfdaa6cfdb73f6d1385de (patch)
treefaa7b3e386293f188b94b3e2d0c48b52cc832d08
parent1bb59c53ee8181ece69bed783d6563d8f74a78ad (diff)
downloadpython-openstackclient-4297e5781b03bad1c67cfdaa6cfdb73f6d1385de.tar.gz
First pass at adding compute unit tests.
Change-Id: Icf3340d457f75eec89bb0e5c9b4b953c3b81020f
-rw-r--r--tests/compute/__init__.py14
-rw-r--r--tests/compute/test_compute.py59
-rw-r--r--tests/test_clientmanager.py (renamed from tests/test_clientmanager_clientcache.py)25
-rw-r--r--tests/test_shell.py9
-rw-r--r--tests/utils.py5
5 files changed, 91 insertions, 21 deletions
diff --git a/tests/compute/__init__.py b/tests/compute/__init__.py
new file mode 100644
index 00000000..ebf59b32
--- /dev/null
+++ b/tests/compute/__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/compute/test_compute.py b/tests/compute/test_compute.py
new file mode 100644
index 00000000..bbac7123
--- /dev/null
+++ b/tests/compute/test_compute.py
@@ -0,0 +1,59 @@
+# 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 tests import utils
+
+
+class FakeClient(object):
+ def __init__(self, endpoint=None, **kwargs):
+ self.client = mock.MagicMock()
+ self.servers = mock.MagicMock()
+
+ self.client.auth_url = kwargs['auth_url']
+
+
+class TestCompute(utils.TestCase):
+ def setUp(self):
+ super(TestCompute, self).setUp()
+
+ self.auth_token = "foobar"
+ self.auth_url = "http://0.0.0.0"
+
+ api_version = {"compute": "2"}
+
+ compute_client.API_VERSIONS = {
+ "2": "tests.compute.test_compute.FakeClient"
+ }
+
+ self.cm = clientmanager.ClientManager(token=self.auth_token,
+ url=self.auth_url,
+ auth_url=self.auth_url,
+ api_version=api_version)
+
+ def test_make_client(self):
+ test_servers = [
+ ["id 1", "name 1", "status 1", "networks 1"],
+ ["id 2", "name 2", "status 2", "networks 2"]
+ ]
+
+ self.cm.compute.servers.list.return_value = test_servers
+
+ self.assertEqual(self.cm.compute.servers.list(), test_servers)
+ self.assertEqual(self.cm.compute.client.auth_token, self.auth_token)
+ self.assertEqual(self.cm.compute.client.auth_url, self.auth_url)
diff --git a/tests/test_clientmanager_clientcache.py b/tests/test_clientmanager.py
index 8ebf14be..fe99c599 100644
--- a/tests/test_clientmanager_clientcache.py
+++ b/tests/test_clientmanager.py
@@ -14,23 +14,22 @@
#
from openstackclient.common import clientmanager
-
-
-def factory(inst):
- return object()
+from tests import utils
class Container(object):
+ attr = clientmanager.ClientCache(lambda x: object())
- attr = clientmanager.ClientCache(factory)
+ def __init__(self):
+ pass
- def init_token(self):
- return
+class TestClientManager(utils.TestCase):
+ def setUp(self):
+ super(TestClientManager, self).setUp()
-def test_singleton():
- # Verify that the ClientCache descriptor only
- # invokes the factory one time and always
- # returns the same value after that.
- c = Container()
- assert c.attr is c.attr
+ def test_singleton(self):
+ # NOTE(dtroyer): Verify that the ClientCache descriptor only invokes
+ # the factory one time and always returns the same value after that.
+ c = Container()
+ self.assertEqual(c.attr, c.attr)
diff --git a/tests/test_shell.py b/tests/test_shell.py
index cf4fc924..87a7795a 100644
--- a/tests/test_shell.py
+++ b/tests/test_shell.py
@@ -13,10 +13,10 @@
# under the License.
#
+import fixtures
import os
import mock
-import fixtures
from openstackclient import shell as os_shell
from tests import utils
@@ -47,8 +47,7 @@ def make_shell():
return _shell
-class ShellTest(utils.TestCase):
-
+class TestShell(utils.TestCase):
FAKE_ENV = {
'OS_AUTH_URL': DEFAULT_AUTH_URL,
'OS_TENANT_ID': DEFAULT_TENANT_ID,
@@ -60,7 +59,7 @@ class ShellTest(utils.TestCase):
def setUp(self):
""" Patch os.environ to avoid required auth info"""
- super(ShellTest, self).setUp()
+ super(TestShell, self).setUp()
for var in self.FAKE_ENV:
self.useFixture(
fixtures.EnvironmentVariable(
@@ -85,7 +84,7 @@ class ShellTest(utils.TestCase):
def tearDown(self):
#self.auth_patch.stop()
self.cmd_patch.stop()
- super(ShellTest, self).tearDown()
+ super(TestShell, self).tearDown()
def test_shell_args(self):
sh = make_shell()
diff --git a/tests/utils.py b/tests/utils.py
index 5c4b50c6..75515fad 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -22,14 +22,13 @@ import testtools
class TestCase(testtools.TestCase):
def setUp(self):
super(TestCase, self).setUp()
+
if (os.environ.get("OS_STDOUT_NOCAPTURE") == "True" and
os.environ.get("OS_STDOUT_NOCAPTURE") == "1"):
stdout = self.useFixture(fixtures.StringStream("stdout")).stream
self.useFixture(fixtures.MonkeyPatch("sys.stdout", stdout))
+
if (os.environ.get("OS_STDERR_NOCAPTURE") == "True" and
os.environ.get("OS_STDERR_NOCAPTURE") == "1"):
stderr = self.useFixture(fixtures.StringStream("stderr")).stream
self.useFixture(fixtures.MonkeyPatch("sys.stderr", stderr))
-
- def tearDown(self):
- super(TestCase, self).tearDown()