Move from unittest2 to testtools

Part of blueprint grizzly-testtools

Change-Id: I13e068ca156f12114eaa3a65bdb557e4eb2c988d
This commit is contained in:
Monty Taylor
2012-12-24 21:49:34 -06:00
parent bf7b86748a
commit 06acb0c009
6 changed files with 46 additions and 36 deletions

View File

@@ -6,9 +6,6 @@ from tests import utils
class ClientTest(utils.TestCase):
def setUp(self):
pass
def test_get_client_class_v1(self):
output = cinderclient.client.get_client_class('1')
self.assertEqual(output, cinderclient.v1.client.Client)

View File

@@ -1,7 +1,11 @@
import cStringIO
import os
import re
import sys
import fixtures
from testtools import matchers
from cinderclient import exceptions
import cinderclient.shell
from tests import utils
@@ -9,16 +13,19 @@ from tests import utils
class ShellTest(utils.TestCase):
# Patch os.environ to avoid required auth info.
def setUp(self):
global _old_env
fake_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()
# Patch os.environ to avoid required auth info.
def setUp(self):
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,28 +43,26 @@ 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+create\s+Add a new volume.',
'(?m)^See "cinder help COMMAND" for help on a specific command',
'.*?^usage: ',
'.*?(?m)^\s+create\s+Add a new volume.',
'.*?(?m)^See "cinder 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: cinder list',
'(?m)^List all the volumes.',
'.*?^usage: cinder list',
'.*?(?m)^List all the volumes.',
]
help_text = self.shell('help list')
for r in required:
self.assertRegexpMatches(help_text, r)
self.assertThat(help_text,
matchers.MatchesRegex(r, re.DOTALL|re.MULTILINE))

View File

@@ -45,6 +45,7 @@ class FakeManager(base.ManagerWithFind):
class FindResourceTestCase(test_utils.TestCase):
def setUp(self):
super(FindResourceTestCase, self).setUp()
self.manager = FakeManager(None)
def test_find_none(self):

View File

@@ -1,9 +1,9 @@
import unittest2
import testtools
import requests
class TestCase(unittest2.TestCase):
class TestCase(testtools.TestCase):
TEST_REQUEST_BASE = {
'config': {'danger_mode': False},
'verify': True,

View File

@@ -17,6 +17,8 @@
import os
import fixtures
from cinderclient import client
from cinderclient import shell
from tests.v1 import fakes
@@ -25,11 +27,7 @@ from tests import utils
class ShellTest(utils.TestCase):
# Patch os.environ to avoid required auth info.
def setUp(self):
"""Run before each test."""
self.old_environment = os.environ.copy()
os.environ = {
FAKE_ENV = {
'CINDER_USERNAME': 'username',
'CINDER_PASSWORD': 'password',
'CINDER_PROJECT_ID': 'project_id',
@@ -37,6 +35,14 @@ class ShellTest(utils.TestCase):
'CINDER_URL': 'http://no.where',
}
# Patch os.environ to avoid required auth info.
def setUp(self):
"""Run before each test."""
super(ShellTest, self).setUp()
for var in self.FAKE_ENV:
self.useFixture(fixtures.EnvironmentVariable(var,
self.FAKE_ENV[var]))
self.shell = shell.OpenStackCinderShell()
#HACK(bcwaldon): replace this when we start using stubs
@@ -44,7 +50,6 @@ class ShellTest(utils.TestCase):
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
@@ -54,6 +59,7 @@ class ShellTest(utils.TestCase):
#HACK(bcwaldon): replace this when we start using stubs
client.get_client_class = self.old_get_client_class
super(ShellTest, self).tearDown()
def run_command(self, cmd):
self.shell.main(cmd.split())

View File

@@ -1,10 +1,11 @@
distribute>=0.6.24
fixtures
mock
nose
nosehtmloutput
nosexcover
openstack.nose_plugin
nosehtmloutput
pep8==1.3.3
sphinx>=1.1.2
unittest2
testtools>=0.9.22