From 4388b493289c006dd93d48d4087878e468a33fb5 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Thu, 1 Sep 2016 14:10:29 +0800 Subject: [PATCH] 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 --- mistralclient/tests/unit/base.py | 7 ++++--- mistralclient/tests/unit/base_shell_test.py | 4 ++-- mistralclient/tests/unit/test_client.py | 5 +++-- mistralclient/tests/unit/test_httpclient.py | 4 ++-- mistralclient/tests/unit/test_utils.py | 4 ++-- mistralclient/tests/unit/v2/test_environments.py | 14 ++++++++------ mistralclient/tests/unit/v2/test_executions.py | 14 ++------------ test-requirements.txt | 4 +--- 8 files changed, 24 insertions(+), 32 deletions(-) diff --git a/mistralclient/tests/unit/base.py b/mistralclient/tests/unit/base.py index c89d9f6c..e64b3a37 100644 --- a/mistralclient/tests/unit/base.py +++ b/mistralclient/tests/unit/base.py @@ -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 diff --git a/mistralclient/tests/unit/base_shell_test.py b/mistralclient/tests/unit/base_shell_test.py index b7cb2d82..c09cdb84 100644 --- a/mistralclient/tests/unit/base_shell_test.py +++ b/mistralclient/tests/unit/base_shell_test.py @@ -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) diff --git a/mistralclient/tests/unit/test_client.py b/mistralclient/tests/unit/test_client.py index 39418c48..43c318d0 100644 --- a/mistralclient/tests/unit/test_client.py +++ b/mistralclient/tests/unit/test_client.py @@ -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 diff --git a/mistralclient/tests/unit/test_httpclient.py b/mistralclient/tests/unit/test_httpclient.py index df74bfc1..f553198f 100644 --- a/mistralclient/tests/unit/test_httpclient.py +++ b/mistralclient/tests/unit/test_httpclient.py @@ -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() diff --git a/mistralclient/tests/unit/test_utils.py b/mistralclient/tests/unit/test_utils.py index 8eb08e9e..e52ad5eb 100644 --- a/mistralclient/tests/unit/test_utils.py +++ b/mistralclient/tests/unit/test_utils.py @@ -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)) diff --git a/mistralclient/tests/unit/v2/test_environments.py b/mistralclient/tests/unit/v2/test_environments.py index 95c3d6db..becc67db 100644 --- a/mistralclient/tests/unit/v2/test_environments.py +++ b/mistralclient/tests/unit/v2/test_environments.py @@ -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]}) diff --git a/mistralclient/tests/unit/v2/test_executions.py b/mistralclient/tests/unit/v2/test_executions.py index 93b00c8b..c62e1d5f 100644 --- a/mistralclient/tests/unit/v2/test_executions.py +++ b/mistralclient/tests/unit/v2/test_executions.py @@ -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) diff --git a/test-requirements.txt b/test-requirements.txt index 2be4f246..c9e6caa3 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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