Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 53aee5cf4b66c98c1142a57244d7466249e44f1f 1 parent e31023f
@emonty emonty authored
View
7 tests/test_auth_plugins.py
@@ -174,8 +174,9 @@ def mock_iter_entry_points(_type):
@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()
View
3  tests/test_client.py
@@ -6,9 +6,6 @@
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)
View
47 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 @@
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 @@ def shell(self, argstr):
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))
View
1  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):
View
4 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,
View
48 tests/v1_1/test_shell.py
@@ -21,6 +21,8 @@
import sys
import tempfile
+import fixtures
+
import novaclient.shell
import novaclient.client
from novaclient import exceptions
@@ -29,39 +31,45 @@
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())
View
3  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
Please sign in to comment.
Something went wrong with that request. Please try again.