Use oslotest instead of testtools/unittest

The oslo community has standardized on some basic test requirements.
This helps people understand what is available when moving between
projects. Use oslotest instead of testtools directly.

Change-Id: I8fa6c10810df021dd7036d1d43c562955e4dcbcc
This commit is contained in:
Jamie Lennox
2016-09-01 14:10:29 +08:00
parent 3a8ee95923
commit 4388b49328
8 changed files with 24 additions and 32 deletions

View File

@@ -15,7 +15,7 @@
import json
import mock
import unittest2
from oslotest import base
class FakeResponse(object):
@@ -30,7 +30,7 @@ class FakeResponse(object):
return json.loads(self.content)
class BaseClientTest(unittest2.TestCase):
class BaseClientTest(base.BaseTestCase):
_client = None
def mock_http_get(self, content, status_code=200):
@@ -67,8 +67,9 @@ class BaseClientTest(unittest2.TestCase):
return self._client.http_client.delete
class BaseCommandTest(unittest2.TestCase):
class BaseCommandTest(base.BaseTestCase):
def setUp(self):
super(BaseCommandTest, self).setUp()
self.app = mock.Mock()
self.client = self.app.client_manager.workflow_engine

View File

@@ -15,13 +15,13 @@
import os
import sys
from oslotest import base
import six
import testtools
from mistralclient import shell
class BaseShellTests(testtools.TestCase):
class BaseShellTests(base.BaseTestCase):
def shell(self, argstr):
orig = (sys.stdout, sys.stderr)

View File

@@ -18,7 +18,7 @@ import tempfile
import uuid
import mock
import testtools
from oslotest import base
import osprofiler.profiler
@@ -32,7 +32,8 @@ MISTRAL_HTTPS_URL = MISTRAL_HTTP_URL.replace('http', 'https')
PROFILER_HMAC_KEY = 'SECRET_HMAC_KEY'
class BaseClientTests(testtools.TestCase):
class BaseClientTests(base.BaseTestCase):
@mock.patch('keystoneclient.v2_0.client.Client')
def test_mistral_url_from_catalog_v2(self, keystone_client_mock):
keystone_client_instance = keystone_client_mock.return_value

View File

@@ -16,8 +16,8 @@ import copy
import uuid
import mock
from oslotest import base
import requests
import testtools
from osprofiler import _utils as osprofiler_utils
import osprofiler.profiler
@@ -66,7 +66,7 @@ class FakeResponse(object):
self.status_code = status_code
class HTTPClientTest(testtools.TestCase):
class HTTPClientTest(base.BaseTestCase):
def setUp(self):
super(HTTPClientTest, self).setUp()

View File

@@ -15,10 +15,10 @@
import json
import os.path
import tempfile
import testtools
import yaml
from mistralclient import utils
from oslotest import base
ENV_DICT = {'k1': 'abc', 'k2': 123, 'k3': True}
@@ -26,7 +26,7 @@ ENV_STR = json.dumps(ENV_DICT)
ENV_YAML = yaml.safe_dump(ENV_DICT, default_flow_style=False)
class UtilityTest(testtools.TestCase):
class UtilityTest(base.BaseTestCase):
def test_load_empty(self):
self.assertDictEqual(dict(), utils.load_content(None))

View File

@@ -83,10 +83,11 @@ class TestEnvironmentsV2(base.BaseClientV2Test):
data = copy.deepcopy(ENVIRONMENT)
data.pop('name')
with self.assertRaises(api_base.APIException) as cm:
self.environments.create(**data)
e = self.assertRaises(api_base.APIException,
self.environments.create,
**data)
self.assertEqual(400, cm.exception.error_code)
self.assertEqual(400, e.error_code)
def test_update(self):
data = copy.deepcopy(ENVIRONMENT)
@@ -128,10 +129,11 @@ class TestEnvironmentsV2(base.BaseClientV2Test):
data = copy.deepcopy(ENVIRONMENT)
data.pop('name')
with self.assertRaises(api_base.APIException) as cm:
self.environments.update(**data)
e = self.assertRaises(api_base.APIException,
self.environments.update,
**data)
self.assertEqual(400, cm.exception.error_code)
self.assertEqual(400, e.error_code)
def test_list(self):
mock = self.mock_http_get(content={'environments': [ENVIRONMENT]})

View File

@@ -15,8 +15,7 @@
import json
import unittest2
from mistralclient.api import base as api_base
from mistralclient.api.v2 import executions
from mistralclient.tests.unit.v2 import base
@@ -102,18 +101,9 @@ class TestExecutionsV2(base.BaseClientV2Test):
self.assertEqual(URL_TEMPLATE, mock.call_args[0][0])
self.assertDictEqual(body, json.loads(mock.call_args[0][1]))
@unittest2.expectedFailure
def test_create_failure1(self):
self.mock_http_post(content=EXEC)
self.executions.create("")
@unittest2.expectedFailure
def test_create_failure2(self):
self.mock_http_post(content=EXEC)
self.executions.create(
EXEC['workflow_name'],
list('343', 'sdfsd')
)
self.assertRaises(api_base.APIException, self.executions.create, '')
def test_update(self):
mock = self.mock_http_put(content=EXEC)

View File

@@ -5,10 +5,8 @@ hacking<0.11,>=0.10
pylint==1.4.5 # GPLv2
python-openstackclient>=2.1.0 # Apache-2.0
sphinx!=1.3b1,<1.3,>=1.2.1 # BSD
unittest2 # BSD
fixtures>=3.0.0 # Apache-2.0/BSD
mock>=2.0 # BSD
nose # LGPL
oslotest>=1.10.0 # Apache-2.0
tempest>=12.1.0 # Apache-2.0
testtools>=1.4.0 # MIT
osprofiler>=1.4.0 # Apache-2.0