summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2012-12-24 19:11:38 -0600
committerMonty Taylor <mordred@inaugust.com>2013-01-03 11:58:13 -0800
commit53aee5cf4b66c98c1142a57244d7466249e44f1f (patch)
tree7f1c6dd4b8adeff724333afa81bbb54125f8f669
parente31023fee104ff69fd14a01703b8e62aeff088a1 (diff)
downloadpython-novaclient-53aee5cf4b66c98c1142a57244d7466249e44f1f.tar.gz
Move from untitest2 to testtools.
Use testtools as the base testclass. Use fixtures library for managing fixtures. Part of blueprint grizzly-testtools Change-Id: Iac5af286b988787acf7049344641aadf140b9398
-rw-r--r--tests/test_auth_plugins.py7
-rw-r--r--tests/test_client.py3
-rw-r--r--tests/test_shell.py47
-rw-r--r--tests/test_utils.py1
-rw-r--r--tests/utils.py4
-rw-r--r--tests/v1_1/test_shell.py48
-rw-r--r--tools/test-requires3
7 files changed, 62 insertions, 51 deletions
diff --git a/tests/test_auth_plugins.py b/tests/test_auth_plugins.py
index 00b3a759..c4950af8 100644
--- a/tests/test_auth_plugins.py
+++ b/tests/test_auth_plugins.py
@@ -174,8 +174,9 @@ class AuthPluginTest(utils.TestCase):
@mock.patch.object(pkg_resources, "iter_entry_points",
mock_iter_entry_points)
def test_auth_call():
- with self.assertRaises(exceptions.EndpointNotFound):
- cs = client.Client("username", "password", "project_id",
- auth_system="fakewithauthurl")
+ self.assertRaises(
+ exceptions.EndpointNotFound,
+ client.Client, "username", "password", "project_id",
+ auth_system="fakewithauthurl")
test_auth_call()
diff --git a/tests/test_client.py b/tests/test_client.py
index e2fc9d96..48d511a8 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -6,9 +6,6 @@ from tests import utils
class ClientTest(utils.TestCase):
- def setUp(self):
- pass
-
def test_get_client_class_v2(self):
output = novaclient.client.get_client_class('2')
self.assertEqual(output, novaclient.v1_1.client.Client)
diff --git a/tests/test_shell.py b/tests/test_shell.py
index 79c3d2f4..63c7244a 100644
--- a/tests/test_shell.py
+++ b/tests/test_shell.py
@@ -1,7 +1,10 @@
import cStringIO
-import os
+import re
import sys
+import fixtures
+from testtools import matchers
+
from novaclient import exceptions
import novaclient.shell
from tests import utils
@@ -9,16 +12,18 @@ from tests import utils
class ShellTest(utils.TestCase):
- # Patch os.environ to avoid required auth info.
+ FAKE_ENV = {
+ 'OS_USERNAME': 'username',
+ 'OS_PASSWORD': 'password',
+ 'OS_TENANT_NAME': 'tenant_name',
+ 'OS_AUTH_URL': 'http://no.where',
+ }
+
def setUp(self):
- global _old_env
- fake_env = {
- 'OS_USERNAME': 'username',
- 'OS_PASSWORD': 'password',
- 'OS_TENANT_NAME': 'tenant_name',
- 'OS_AUTH_URL': 'http://no.where',
- }
- _old_env, os.environ = os.environ, fake_env.copy()
+ super(ShellTest, self).setUp()
+ for var in self.FAKE_ENV:
+ self.useFixture(fixtures.EnvironmentVariable(var,
+ self.FAKE_ENV[var]))
def shell(self, argstr):
orig = sys.stdout
@@ -36,29 +41,27 @@ class ShellTest(utils.TestCase):
return out
- def tearDown(self):
- global _old_env
- os.environ = _old_env
-
def test_help_unknown_command(self):
self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo')
def test_help(self):
required = [
- '^usage: ',
- '(?m)^\s+root-password\s+Change the root password',
- '(?m)^See "nova help COMMAND" for help on a specific command',
+ '.*?^usage: ',
+ '.*?^\s+root-password\s+Change the root password',
+ '.*?^See "nova help COMMAND" for help on a specific command',
]
help_text = self.shell('help')
for r in required:
- self.assertRegexpMatches(help_text, r)
+ self.assertThat(help_text,
+ matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
def test_help_on_subcommand(self):
required = [
- '^usage: nova root-password',
- '(?m)^Change the root password',
- '(?m)^Positional arguments:',
+ '.*?^usage: nova root-password',
+ '.*?^Change the root password',
+ '.*?^Positional arguments:',
]
help_text = self.shell('help root-password')
for r in required:
- self.assertRegexpMatches(help_text, r)
+ self.assertThat(help_text,
+ matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 0eb64cff..c619fe14 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -61,6 +61,7 @@ class FakeDisplayManager(FakeManager):
class FindResourceTestCase(test_utils.TestCase):
def setUp(self):
+ super(FindResourceTestCase, self).setUp()
self.manager = FakeManager(None)
def test_find_none(self):
diff --git a/tests/utils.py b/tests/utils.py
index 3bbe8bba..ef231a77 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -1,8 +1,8 @@
import requests
-import unittest2
+import testtools
-class TestCase(unittest2.TestCase):
+class TestCase(testtools.TestCase):
TEST_REQUEST_BASE = {
'config': {'danger_mode': False},
'verify': True,
diff --git a/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py
index de85a3e5..375fb811 100644
--- a/tests/v1_1/test_shell.py
+++ b/tests/v1_1/test_shell.py
@@ -21,6 +21,8 @@ import mock
import sys
import tempfile
+import fixtures
+
import novaclient.shell
import novaclient.client
from novaclient import exceptions
@@ -29,39 +31,45 @@ from tests.v1_1 import fakes
from tests import utils
-class ShellTest(utils.TestCase):
+class ShellFixture(fixtures.Fixture):
- # Patch os.environ to avoid required auth info.
def setUp(self):
- """Run before each test."""
- self.old_environment = os.environ.copy()
- os.environ = {
- 'NOVA_USERNAME': 'username',
- 'NOVA_PASSWORD': 'password',
- 'NOVA_PROJECT_ID': 'project_id',
- 'OS_COMPUTE_API_VERSION': '1.1',
- 'NOVA_URL': 'http://no.where',
- }
-
+ super(ShellFixture, self).setUp()
self.shell = novaclient.shell.OpenStackComputeShell()
- #HACK(bcwaldon): replace this when we start using stubs
- self.old_get_client_class = novaclient.client.get_client_class
- novaclient.client.get_client_class = lambda *_: fakes.FakeClient
-
def tearDown(self):
- os.environ = self.old_environment
# For some method like test_image_meta_bad_action we are
# testing a SystemExit to be thrown and object self.shell has
# no time to get instantatiated which is OK in this case, so
# we make sure the method is there before launching it.
if hasattr(self.shell, 'cs'):
self.shell.cs.clear_callstack()
+ super(ShellFixture, self).tearDown()
+
+
+class ShellTest(utils.TestCase):
+
+ FAKE_ENV = {
+ 'NOVA_USERNAME': 'username',
+ 'NOVA_PASSWORD': 'password',
+ 'NOVA_PROJECT_ID': 'project_id',
+ 'OS_COMPUTE_API_VERSION': '1.1',
+ 'NOVA_URL': 'http://no.where',
+ }
+
+ def setUp(self):
+ """Run before each test."""
+ super(ShellTest, self).setUp()
- #HACK(bcwaldon): replace this when we start using stubs
- novaclient.client.get_client_class = self.old_get_client_class
+ for var in self.FAKE_ENV:
+ self.useFixture(fixtures.EnvironmentVariable(var,
+ self.FAKE_ENV[var]))
+ self.shell = self.useFixture(ShellFixture()).shell
- timeutils.clear_time_override()
+ self.useFixture(fixtures.MonkeyPatch(
+ 'novaclient.client.get_client_class',
+ lambda *_: fakes.FakeClient))
+ self.addCleanup(timeutils.clear_time_override)
def run_command(self, cmd):
self.shell.main(cmd.split())
diff --git a/tools/test-requires b/tools/test-requires
index 43a94695..f69ef390 100644
--- a/tools/test-requires
+++ b/tools/test-requires
@@ -1,5 +1,6 @@
distribute>=0.6.24
+fixtures
mock
nose
nose-exclude
@@ -8,4 +9,4 @@ openstack.nose_plugin
nosehtmloutput
pep8==1.1
sphinx>=1.1.2
-unittest2
+testtools