From 6ac6193118090b5675b011d8e69f2e461e63f30a Mon Sep 17 00:00:00 2001 From: Nicholas Jones Date: Thu, 10 Aug 2017 14:41:11 -0500 Subject: [PATCH] Move common/utils tests to top level test folder Moves common/utils tests out of the test folder in that directory and into the root tests folder, where tox and Jenkins can pick them up. Change-Id: I28222a1839102a0973712d72bfcb365b5e4bc4b5 --- .../client/audit/audit_client/api/audit.py | 6 +-- .../orm_common/utils/api_error_utils.py | 2 +- orm/common/orm_common/utils/utils.py | 2 +- .../utils => tests/unit/common}/__init__.py | 0 .../unit/common}/test_api_error_utils.py | 2 +- .../unit/common}/test_cross_api_utils.py | 10 ++--- .../utils => tests/unit/common}/test_utils.py | 37 ++++++++++--------- test-requirements.txt | 13 +++---- 8 files changed, 37 insertions(+), 35 deletions(-) rename orm/{common/orm_common/tests/utils => tests/unit/common}/__init__.py (100%) rename orm/{common/orm_common/tests/utils => tests/unit/common}/test_api_error_utils.py (90%) rename orm/{common/orm_common/tests/utils => tests/unit/common}/test_cross_api_utils.py (88%) rename orm/{common/orm_common/tests/utils => tests/unit/common}/test_utils.py (85%) diff --git a/orm/common/client/audit/audit_client/api/audit.py b/orm/common/client/audit/audit_client/api/audit.py index 6c40c315..9077d8d6 100755 --- a/orm/common/client/audit/audit_client/api/audit.py +++ b/orm/common/client/audit/audit_client/api/audit.py @@ -6,9 +6,9 @@ import threading import time import urllib2 -from audit_client.api.exceptions.audit_exception import AuditException -from audit_client.api.model.get_audits_result import AuditsResult -from audit_client.api.model.transaction import Transaction +from orm.common.client.audit.audit_client.api.exceptions.audit_exception import AuditException +from orm.common.client.audit.audit_client.api.model.get_audits_result import AuditsResult +from orm.common.client.audit.audit_client.api.model.transaction import Transaction logger = logging.getLogger(__name__) diff --git a/orm/common/orm_common/utils/api_error_utils.py b/orm/common/orm_common/utils/api_error_utils.py index 67c51678..1ce17862 100755 --- a/orm/common/orm_common/utils/api_error_utils.py +++ b/orm/common/orm_common/utils/api_error_utils.py @@ -1,6 +1,6 @@ import json -from orm_common.utils import utils +from orm.common.orm_common.utils import utils from wsme.exc import ClientSideError diff --git a/orm/common/orm_common/utils/utils.py b/orm/common/orm_common/utils/utils.py index 3f2c77dd..b21e5189 100755 --- a/orm/common/orm_common/utils/utils.py +++ b/orm/common/orm_common/utils/utils.py @@ -4,7 +4,7 @@ import time import requests -from audit_client.api import audit +from orm.common.client.audit.audit_client.api import audit from pecan import conf # from cms_rest.logger import get_logger diff --git a/orm/common/orm_common/tests/utils/__init__.py b/orm/tests/unit/common/__init__.py similarity index 100% rename from orm/common/orm_common/tests/utils/__init__.py rename to orm/tests/unit/common/__init__.py diff --git a/orm/common/orm_common/tests/utils/test_api_error_utils.py b/orm/tests/unit/common/test_api_error_utils.py similarity index 90% rename from orm/common/orm_common/tests/utils/test_api_error_utils.py rename to orm/tests/unit/common/test_api_error_utils.py index 76fa728f..7f840d50 100755 --- a/orm/common/orm_common/tests/utils/test_api_error_utils.py +++ b/orm/tests/unit/common/test_api_error_utils.py @@ -2,7 +2,7 @@ import json from unittest import TestCase import mock -from orm_common.utils import api_error_utils +from orm.common.orm_common.utils import api_error_utils class TestCrossApiUtil(TestCase): diff --git a/orm/common/orm_common/tests/utils/test_cross_api_utils.py b/orm/tests/unit/common/test_cross_api_utils.py similarity index 88% rename from orm/common/orm_common/tests/utils/test_cross_api_utils.py rename to orm/tests/unit/common/test_cross_api_utils.py index 78371d3a..81bacd93 100755 --- a/orm/common/orm_common/tests/utils/test_cross_api_utils.py +++ b/orm/tests/unit/common/test_cross_api_utils.py @@ -2,7 +2,7 @@ import time from unittest import TestCase import mock -from orm_common.utils import cross_api_utils +from orm.common.orm_common.utils import cross_api_utils class TestCrossApiUtil(TestCase): @@ -24,25 +24,25 @@ class TestCrossApiUtil(TestCase): cross_api_utils.set_utils_conf(None) self.assertRaises(AssertionError, cross_api_utils._check_conf_initialization) - @mock.patch('orm_common.utils.cross_api_utils.get_rms_region_group') + @mock.patch('orm.common.orm_common.utils.cross_api_utils.get_rms_region_group') def test_is_region_group_exist(self, mock_rms_region_group): mock_rms_region_group.return_value = 'test_group' exist = cross_api_utils.is_region_group_exist('test_group_name') self.assertEqual(exist, True) - @mock.patch('orm_common.utils.cross_api_utils.get_rms_region_group') + @mock.patch('orm.common.orm_common.utils.cross_api_utils.get_rms_region_group') def test_is_region_group_exist_false(self, mock_rms_region_group): mock_rms_region_group.return_value = None exist = cross_api_utils.is_region_group_exist('test_group_name') self.assertEqual(exist, False) - @mock.patch('orm_common.utils.cross_api_utils.get_rms_region_group') + @mock.patch('orm.common.orm_common.utils.cross_api_utils.get_rms_region_group') def test_get_regions_of_group(self, mock_rms_region_group): mock_rms_region_group.return_value = {'regions': 'group'} exist = cross_api_utils.get_regions_of_group('test_group_name') self.assertEqual(exist, 'group') - @mock.patch('orm_common.utils.cross_api_utils.get_rms_region_group') + @mock.patch('orm.common.orm_common.utils.cross_api_utils.get_rms_region_group') def test_get_regions_of_group_false(self, mock_rms_region_group): mock_rms_region_group.return_value = None exist = cross_api_utils.get_regions_of_group('test_group_name') diff --git a/orm/common/orm_common/tests/utils/test_utils.py b/orm/tests/unit/common/test_utils.py similarity index 85% rename from orm/common/orm_common/tests/utils/test_utils.py rename to orm/tests/unit/common/test_utils.py index 6ce8a4c6..f2ff139d 100755 --- a/orm/common/orm_common/tests/utils/test_utils.py +++ b/orm/tests/unit/common/test_utils.py @@ -3,7 +3,7 @@ import pprint from unittest import TestCase import mock -from orm_common.utils import utils +from orm.common.orm_common.utils import utils from testfixtures import log_capture @@ -25,12 +25,12 @@ class TestUtil(TestCase): self.assertEqual(uuid, '987654321') @mock.patch('requests.post') - @log_capture('orm_common.utils.utils', level=logging.INFO) + @log_capture('orm.common.orm_common.utils.utils', level=logging.INFO) def test_make_uuid_offline(self, mock_post, l): mock_post.side_effect = Exception('boom') uuid = utils.make_uuid() self.assertEqual(uuid, None) - l.check(('orm_common.utils.utils', 'INFO', 'Failed in make_uuid:boom')) + l.check(('orm.common.orm_common.utils.utils', 'INFO', 'Failed in make_uuid:boom')) @mock.patch('requests.post') def test_make_transid(self, mock_post): @@ -39,33 +39,34 @@ class TestUtil(TestCase): self.assertEqual(uuid, '987654321') @mock.patch('requests.post') - @log_capture('orm_common.utils.utils', level=logging.INFO) + @log_capture('orm.common.orm_common.utils.utils', level=logging.INFO) def test_make_transid_offline(self, mock_post, l): mock_post.side_effect = Exception('boom') uuid = utils.make_transid() self.assertEqual(uuid, None) l.check( - ('orm_common.utils.utils', 'INFO', 'Failed in make_transid:boom')) + ('orm.common.orm_common.utils.utils', 'INFO', 'Failed in make_transid:boom')) - @mock.patch('audit_client.api.audit.init') - @mock.patch('audit_client.api.audit.audit') + @mock.patch('orm.common.client.audit.audit_client.api.audit.init') + @mock.patch('orm.common.client.audit.audit_client.api.audit.audit') def test_audit_trail(self, mock_init, mock_audit): resp = utils.audit_trail('create customer', '1234', {'X-RANGER-Client': 'Fred'}, '5678') self.assertEqual(resp, 200) - @mock.patch('audit_client.api.audit.audit') + @mock.patch('orm.common.client.audit.audit_client.api.audit.audit') def test_audit_trail_offline(self, mock_audit): mock_audit.side_effect = Exception('boom') resp = utils.audit_trail('create customer', '1234', {'X-RANGER-Client': 'Fred'}, '5678') self.assertEqual(resp, None) - @mock.patch('audit_client.api.audit.init') - @mock.patch('audit_client.api.audit.audit') + @mock.patch('orm.common.client.audit.audit_client.api.audit.init') + @mock.patch('orm.common.client.audit.audit_client.api.audit.audit') def test_audit_service_args_least(self, mock_audit, mock_init): resp = utils.audit_trail('create customer', '1234', - {'X-RANGER-Client': 'Fred'}, '5678') + {'X-RANGER-Client': 'Fred'}, '5678', + event_details='CMS') self.assertEqual(mock_audit.call_args[0][1], 'Fred') # application_id self.assertEqual(mock_audit.call_args[0][2], '1234') # tracking_id self.assertEqual(mock_audit.call_args[0][3], '1234') # transaction_id @@ -78,12 +79,13 @@ class TestUtil(TestCase): self.assertEqual(mock_audit.call_args[0][9], 'CMS') # event_details # self.assertEqual(mock_audit.call_args[0][10], 'Saved to DB') # status - @mock.patch('audit_client.api.audit.init') - @mock.patch('audit_client.api.audit.audit') + @mock.patch('orm.common.client.audit.audit_client.api.audit.init') + @mock.patch('orm.common.client.audit.audit_client.api.audit.audit') def test_audit_service_with_tracking(self, mock_audit, mock_init): utils.audit_trail('create customer', '1234', {'X-RANGER-Client': 'Fred', - 'X-RANGER-Tracking-Id': 'Track12'}, '5678') + 'X-RANGER-Tracking-Id': 'Track12'}, '5678', + event_details='CMS') self.assertEqual(mock_audit.call_args[0][1], 'Fred') # application_id self.assertEqual(mock_audit.call_args[0][2], 'Track12') # tracking_id self.assertEqual(mock_audit.call_args[0][3], '1234') # transaction_id @@ -96,12 +98,13 @@ class TestUtil(TestCase): self.assertEqual(mock_audit.call_args[0][9], 'CMS') # event_details # self.assertEqual(mock_audit.call_args[0][10], 'Saved to DB') # status - @mock.patch('audit_client.api.audit.init') - @mock.patch('audit_client.api.audit.audit') + @mock.patch('orm.common.client.audit.audit_client.api.audit.init') + @mock.patch('orm.common.client.audit.audit_client.api.audit.audit') def test_audit_service_with_requester(self, mock_audit, mock_init): resp = utils.audit_trail('create customer', '1234', {'X-RANGER-Client': 'Fred', - 'X-RANGER-Requester': 'Req04'}, '5678') + 'X-RANGER-Requester': 'Req04'}, '5678', + event_details='CMS') self.assertEqual(mock_audit.call_args[0][1], 'Fred') # application_id self.assertEqual(mock_audit.call_args[0][2], '1234') # tracking_id self.assertEqual(mock_audit.call_args[0][3], '1234') # transaction_id diff --git a/test-requirements.txt b/test-requirements.txt index 241c53c0..4935e32e 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,13 +5,12 @@ hacking>=0.12.0,<0.13 # Apache-2.0 coverage>=4.0,!=4.4 # Apache-2.0 -python-subunit>=0.0.18 # Apache-2.0/BSD -sphinx>=1.6.2 # BSD +openstackdocstheme>=1.11.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0 +os-testr>=0.8.0 # Apache-2.0 +python-subunit>=0.0.18 # Apache-2.0/BSD +reno>=1.8.0 # Apache-2.0 +sphinx>=1.6.2 # BSD +testfixtures>=5.1.1 # MIT testrepository>=0.0.18 # Apache-2.0/BSD testtools>=1.4.0 # MIT -openstackdocstheme>=1.11.0 # Apache-2.0 -os-testr>=0.8.0 # Apache-2.0 -# releasenotes -reno>=1.8.0 # Apache-2.0 -