summaryrefslogtreecommitdiff
path: root/tests/v1_1/test_shell.py
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 /tests/v1_1/test_shell.py
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
Diffstat (limited to 'tests/v1_1/test_shell.py')
-rw-r--r--tests/v1_1/test_shell.py48
1 files changed, 28 insertions, 20 deletions
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())