Move from unittest2 to testtools
Part of blueprint grizzly-testtools Change-Id: I13e068ca156f12114eaa3a65bdb557e4eb2c988d
This commit is contained in:
@@ -6,9 +6,6 @@ from tests import utils
|
|||||||
|
|
||||||
class ClientTest(utils.TestCase):
|
class ClientTest(utils.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_get_client_class_v1(self):
|
def test_get_client_class_v1(self):
|
||||||
output = cinderclient.client.get_client_class('1')
|
output = cinderclient.client.get_client_class('1')
|
||||||
self.assertEqual(output, cinderclient.v1.client.Client)
|
self.assertEqual(output, cinderclient.v1.client.Client)
|
||||||
|
@@ -1,7 +1,11 @@
|
|||||||
import cStringIO
|
import cStringIO
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import fixtures
|
||||||
|
from testtools import matchers
|
||||||
|
|
||||||
from cinderclient import exceptions
|
from cinderclient import exceptions
|
||||||
import cinderclient.shell
|
import cinderclient.shell
|
||||||
from tests import utils
|
from tests import utils
|
||||||
@@ -9,16 +13,19 @@ from tests import utils
|
|||||||
|
|
||||||
class ShellTest(utils.TestCase):
|
class ShellTest(utils.TestCase):
|
||||||
|
|
||||||
|
FAKE_ENV = {
|
||||||
|
'OS_USERNAME': 'username',
|
||||||
|
'OS_PASSWORD': 'password',
|
||||||
|
'OS_TENANT_NAME': 'tenant_name',
|
||||||
|
'OS_AUTH_URL': 'http://no.where',
|
||||||
|
}
|
||||||
|
|
||||||
# Patch os.environ to avoid required auth info.
|
# Patch os.environ to avoid required auth info.
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
global _old_env
|
super(ShellTest, self).setUp()
|
||||||
fake_env = {
|
for var in self.FAKE_ENV:
|
||||||
'OS_USERNAME': 'username',
|
self.useFixture(fixtures.EnvironmentVariable(var,
|
||||||
'OS_PASSWORD': 'password',
|
self.FAKE_ENV[var]))
|
||||||
'OS_TENANT_NAME': 'tenant_name',
|
|
||||||
'OS_AUTH_URL': 'http://no.where',
|
|
||||||
}
|
|
||||||
_old_env, os.environ = os.environ, fake_env.copy()
|
|
||||||
|
|
||||||
def shell(self, argstr):
|
def shell(self, argstr):
|
||||||
orig = sys.stdout
|
orig = sys.stdout
|
||||||
@@ -36,28 +43,26 @@ class ShellTest(utils.TestCase):
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
global _old_env
|
|
||||||
os.environ = _old_env
|
|
||||||
|
|
||||||
def test_help_unknown_command(self):
|
def test_help_unknown_command(self):
|
||||||
self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo')
|
self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo')
|
||||||
|
|
||||||
def test_help(self):
|
def test_help(self):
|
||||||
required = [
|
required = [
|
||||||
'^usage: ',
|
'.*?^usage: ',
|
||||||
'(?m)^\s+create\s+Add a new volume.',
|
'.*?(?m)^\s+create\s+Add a new volume.',
|
||||||
'(?m)^See "cinder help COMMAND" for help on a specific command',
|
'.*?(?m)^See "cinder help COMMAND" for help on a specific command',
|
||||||
]
|
]
|
||||||
help_text = self.shell('help')
|
help_text = self.shell('help')
|
||||||
for r in required:
|
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):
|
def test_help_on_subcommand(self):
|
||||||
required = [
|
required = [
|
||||||
'^usage: cinder list',
|
'.*?^usage: cinder list',
|
||||||
'(?m)^List all the volumes.',
|
'.*?(?m)^List all the volumes.',
|
||||||
]
|
]
|
||||||
help_text = self.shell('help list')
|
help_text = self.shell('help list')
|
||||||
for r in required:
|
for r in required:
|
||||||
self.assertRegexpMatches(help_text, r)
|
self.assertThat(help_text,
|
||||||
|
matchers.MatchesRegex(r, re.DOTALL|re.MULTILINE))
|
||||||
|
@@ -45,6 +45,7 @@ class FakeManager(base.ManagerWithFind):
|
|||||||
class FindResourceTestCase(test_utils.TestCase):
|
class FindResourceTestCase(test_utils.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(FindResourceTestCase, self).setUp()
|
||||||
self.manager = FakeManager(None)
|
self.manager = FakeManager(None)
|
||||||
|
|
||||||
def test_find_none(self):
|
def test_find_none(self):
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import unittest2
|
import testtools
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class TestCase(unittest2.TestCase):
|
class TestCase(testtools.TestCase):
|
||||||
TEST_REQUEST_BASE = {
|
TEST_REQUEST_BASE = {
|
||||||
'config': {'danger_mode': False},
|
'config': {'danger_mode': False},
|
||||||
'verify': True,
|
'verify': True,
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import fixtures
|
||||||
|
|
||||||
from cinderclient import client
|
from cinderclient import client
|
||||||
from cinderclient import shell
|
from cinderclient import shell
|
||||||
from tests.v1 import fakes
|
from tests.v1 import fakes
|
||||||
@@ -25,17 +27,21 @@ from tests import utils
|
|||||||
|
|
||||||
class ShellTest(utils.TestCase):
|
class ShellTest(utils.TestCase):
|
||||||
|
|
||||||
|
FAKE_ENV = {
|
||||||
|
'CINDER_USERNAME': 'username',
|
||||||
|
'CINDER_PASSWORD': 'password',
|
||||||
|
'CINDER_PROJECT_ID': 'project_id',
|
||||||
|
'OS_COMPUTE_API_VERSION': '1.1',
|
||||||
|
'CINDER_URL': 'http://no.where',
|
||||||
|
}
|
||||||
|
|
||||||
# Patch os.environ to avoid required auth info.
|
# Patch os.environ to avoid required auth info.
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Run before each test."""
|
"""Run before each test."""
|
||||||
self.old_environment = os.environ.copy()
|
super(ShellTest, self).setUp()
|
||||||
os.environ = {
|
for var in self.FAKE_ENV:
|
||||||
'CINDER_USERNAME': 'username',
|
self.useFixture(fixtures.EnvironmentVariable(var,
|
||||||
'CINDER_PASSWORD': 'password',
|
self.FAKE_ENV[var]))
|
||||||
'CINDER_PROJECT_ID': 'project_id',
|
|
||||||
'OS_COMPUTE_API_VERSION': '1.1',
|
|
||||||
'CINDER_URL': 'http://no.where',
|
|
||||||
}
|
|
||||||
|
|
||||||
self.shell = shell.OpenStackCinderShell()
|
self.shell = shell.OpenStackCinderShell()
|
||||||
|
|
||||||
@@ -44,7 +50,6 @@ class ShellTest(utils.TestCase):
|
|||||||
client.get_client_class = lambda *_: fakes.FakeClient
|
client.get_client_class = lambda *_: fakes.FakeClient
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
os.environ = self.old_environment
|
|
||||||
# For some method like test_image_meta_bad_action we are
|
# For some method like test_image_meta_bad_action we are
|
||||||
# testing a SystemExit to be thrown and object self.shell has
|
# testing a SystemExit to be thrown and object self.shell has
|
||||||
# no time to get instantatiated which is OK in this case, so
|
# 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
|
#HACK(bcwaldon): replace this when we start using stubs
|
||||||
client.get_client_class = self.old_get_client_class
|
client.get_client_class = self.old_get_client_class
|
||||||
|
super(ShellTest, self).tearDown()
|
||||||
|
|
||||||
def run_command(self, cmd):
|
def run_command(self, cmd):
|
||||||
self.shell.main(cmd.split())
|
self.shell.main(cmd.split())
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
distribute>=0.6.24
|
distribute>=0.6.24
|
||||||
|
|
||||||
|
fixtures
|
||||||
mock
|
mock
|
||||||
nose
|
nose
|
||||||
|
nosehtmloutput
|
||||||
nosexcover
|
nosexcover
|
||||||
openstack.nose_plugin
|
openstack.nose_plugin
|
||||||
nosehtmloutput
|
|
||||||
pep8==1.3.3
|
pep8==1.3.3
|
||||||
sphinx>=1.1.2
|
sphinx>=1.1.2
|
||||||
unittest2
|
testtools>=0.9.22
|
||||||
|
Reference in New Issue
Block a user