From 20aa6dcdba1deaf5105b9d60078f2b67d94c4885 Mon Sep 17 00:00:00 2001 From: Nicholas Jones Date: Tue, 15 Aug 2017 07:44:50 -0500 Subject: [PATCH] Move all common tests to top level folder Moves all tests under orm/common to the top level tests folder and makes minimal necessary changes to get them working. Change-Id: Ib813d130ac5a2b3e2205c3a0d9cbeff46359ced1 --- .../client/keystone/keystone_utils/tokens.py | 6 +++--- orm/common/orm_common/hooks/api_error_hook.py | 2 +- .../orm_common/hooks/transaction_id_hook.py | 2 +- .../orm_common/injector/fang/resolver.py | 2 +- orm/common/orm_common/injector/injector.py | 6 +++--- orm/common/orm_common/policy/_checks.py | 4 ++-- orm/common/orm_common/policy/_parser.py | 7 +++---- orm/common/orm_common/policy/policy.py | 6 +++--- orm/common/orm_common/tests/__init__.py | 0 orm/common/orm_common/tests/hooks/__init__.py | 0 .../orm_common/tests/injector/__init__.py | 0 orm/common/orm_common/tests/policy/__init__.py | 0 orm/common/tox.ini | 18 ------------------ .../unit/common}/test_api_error_hook.py | 2 +- .../unit/common}/test_checks.py | 2 +- .../unit/common}/test_injector.py | 2 +- .../unit/common}/test_policy.py | 2 +- .../unit/common}/test_security_headers_hook.py | 2 +- .../unit/common}/test_transaction_id_hook.py | 2 +- 19 files changed, 23 insertions(+), 42 deletions(-) delete mode 100644 orm/common/orm_common/tests/__init__.py delete mode 100644 orm/common/orm_common/tests/hooks/__init__.py delete mode 100644 orm/common/orm_common/tests/injector/__init__.py delete mode 100644 orm/common/orm_common/tests/policy/__init__.py delete mode 100755 orm/common/tox.ini rename orm/{common/orm_common/tests/hooks => tests/unit/common}/test_api_error_hook.py (98%) rename orm/{common/orm_common/tests/policy => tests/unit/common}/test_checks.py (98%) rename orm/{common/orm_common/tests/injector => tests/unit/common}/test_injector.py (97%) rename orm/{common/orm_common/tests/policy => tests/unit/common}/test_policy.py (99%) rename orm/{common/orm_common/tests/hooks => tests/unit/common}/test_security_headers_hook.py (94%) rename orm/{common/orm_common/tests/hooks => tests/unit/common}/test_transaction_id_hook.py (89%) diff --git a/orm/common/client/keystone/keystone_utils/tokens.py b/orm/common/client/keystone/keystone_utils/tokens.py index 20900b24..65266544 100755 --- a/orm/common/client/keystone/keystone_utils/tokens.py +++ b/orm/common/client/keystone/keystone_utils/tokens.py @@ -3,9 +3,9 @@ import logging import requests -from keystoneclient.v2_0 import client as v2_client -from keystoneclient.v3 import client as v3_client -from orm_common.utils import dictator +from orm.common.client.keystone.mock_keystone.keystoneclient.v2_0 import client as v2_client +from orm.common.client.keystone.mock_keystone.keystoneclient.v3 import client as v3_client +from orm.common.orm_common.utils import dictator _verify = False diff --git a/orm/common/orm_common/hooks/api_error_hook.py b/orm/common/orm_common/hooks/api_error_hook.py index a43bcbe8..b578dc30 100755 --- a/orm/common/orm_common/hooks/api_error_hook.py +++ b/orm/common/orm_common/hooks/api_error_hook.py @@ -1,7 +1,7 @@ import json import logging -from orm_common.utils import api_error_utils as err_utils +from orm.common.orm_common.utils import api_error_utils as err_utils from pecan.hooks import PecanHook logger = logging.getLogger(__name__) diff --git a/orm/common/orm_common/hooks/transaction_id_hook.py b/orm/common/orm_common/hooks/transaction_id_hook.py index a7a180be..ba8711d1 100755 --- a/orm/common/orm_common/hooks/transaction_id_hook.py +++ b/orm/common/orm_common/hooks/transaction_id_hook.py @@ -1,4 +1,4 @@ -from orm_common.utils import utils +from orm.common.orm_common.utils import utils from pecan import abort from pecan.hooks import PecanHook diff --git a/orm/common/orm_common/injector/fang/resolver.py b/orm/common/orm_common/injector/fang/resolver.py index 44dc02f0..321aa061 100755 --- a/orm/common/orm_common/injector/fang/resolver.py +++ b/orm/common/orm_common/injector/fang/resolver.py @@ -1,5 +1,5 @@ import logging -from orm.common.orm_common.injector.errors import ProviderNotFoundError +from orm.common.orm_common.injector.fang.errors import ProviderNotFoundError # This is effectively what is sometimes termed a "dependency injection diff --git a/orm/common/orm_common/injector/injector.py b/orm/common/orm_common/injector/injector.py index 08309a92..6f10c2f8 100755 --- a/orm/common/orm_common/injector/injector.py +++ b/orm/common/orm_common/injector/injector.py @@ -1,10 +1,10 @@ import imp import os -from orm_common.injector import fang -from orm_common.utils.sanitize import sanitize_symbol_name +from orm.common.orm_common.injector.fang import di +from orm.common.orm_common.utils.sanitize import sanitize_symbol_name -_di = fang.Di() +_di = di.Di() logger = None diff --git a/orm/common/orm_common/policy/_checks.py b/orm/common/orm_common/policy/_checks.py index 4d161939..1ab7ffb3 100755 --- a/orm/common/orm_common/policy/_checks.py +++ b/orm/common/orm_common/policy/_checks.py @@ -20,8 +20,8 @@ import logging import six -from orm_common.utils import api_error_utils as err_utils -from orm_common.utils import dictator +from orm.common.orm_common.utils import api_error_utils as err_utils +from orm.common.orm_common.utils import dictator logger = logging.getLogger(__name__) diff --git a/orm/common/orm_common/policy/_parser.py b/orm/common/orm_common/policy/_parser.py index 4751cce1..7207f0f2 100755 --- a/orm/common/orm_common/policy/_parser.py +++ b/orm/common/orm_common/policy/_parser.py @@ -21,7 +21,6 @@ import re import six import _checks -from oslo_policy._i18n import _LE LOG = logging.getLogger(__name__) @@ -211,7 +210,7 @@ def _parse_check(rule): try: kind, match = rule.split(':', 1) except Exception: - LOG.exception(_LE('Failed to understand rule %s'), rule) + LOG.exception('Failed to understand rule %s', rule) # If the rule is invalid, we'll fail closed return _checks.FalseCheck() @@ -221,7 +220,7 @@ def _parse_check(rule): elif None in _checks.registered_checks: return _checks.registered_checks[None](kind, match) else: - LOG.error(_LE('No handler for matches of kind %s'), kind) + LOG.error('No handler for matches of kind %s', kind) return _checks.FalseCheck() @@ -337,7 +336,7 @@ def _parse_text_rule(rule): return state.result except ValueError: # Couldn't parse the rule - LOG.exception(_LE('Failed to understand rule %s'), rule) + LOG.exception('Failed to understand rule %s', rule) # Fail closed return _checks.FalseCheck() diff --git a/orm/common/orm_common/policy/policy.py b/orm/common/orm_common/policy/policy.py index 370e6c43..f82482dd 100755 --- a/orm/common/orm_common/policy/policy.py +++ b/orm/common/orm_common/policy/policy.py @@ -2,9 +2,9 @@ import logging -from keystone_utils import tokens -from orm_common.utils import api_error_utils as err_utils -from orm_common.utils import dictator +from orm.common.client.keystone.keystone_utils import tokens +from orm.common.orm_common.utils import api_error_utils as err_utils +from orm.common.orm_common.utils import dictator import qolicy from wsme.exc import ClientSideError diff --git a/orm/common/orm_common/tests/__init__.py b/orm/common/orm_common/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/orm/common/orm_common/tests/hooks/__init__.py b/orm/common/orm_common/tests/hooks/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/orm/common/orm_common/tests/injector/__init__.py b/orm/common/orm_common/tests/injector/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/orm/common/orm_common/tests/policy/__init__.py b/orm/common/orm_common/tests/policy/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/orm/common/tox.ini b/orm/common/tox.ini deleted file mode 100755 index 069b0d37..00000000 --- a/orm/common/tox.ini +++ /dev/null @@ -1,18 +0,0 @@ -[tox] -envlist=py27,cover - -[testenv] -setenv= CMS_ENV=mock - PYTHONPATH={toxinidir}:{toxinidir}/orm_common/extenal_mock/ -deps= -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt - -[testenv:pep8] -commands = - py.test --pep8 -m pep8 - -[testenv:cover] -commands= - coverage run setup.py test - coverage report --omit=orm_common/policy/_parser.py,orm_common/policy/qolicy.py - coverage html diff --git a/orm/common/orm_common/tests/hooks/test_api_error_hook.py b/orm/tests/unit/common/test_api_error_hook.py similarity index 98% rename from orm/common/orm_common/tests/hooks/test_api_error_hook.py rename to orm/tests/unit/common/test_api_error_hook.py index d49da1b6..3eabe613 100755 --- a/orm/common/orm_common/tests/hooks/test_api_error_hook.py +++ b/orm/tests/unit/common/test_api_error_hook.py @@ -3,7 +3,7 @@ import logging from unittest import TestCase import mock -from orm_common.hooks import api_error_hook +from orm.common.orm_common.hooks import api_error_hook logger = logging.getLogger(__name__) diff --git a/orm/common/orm_common/tests/policy/test_checks.py b/orm/tests/unit/common/test_checks.py similarity index 98% rename from orm/common/orm_common/tests/policy/test_checks.py rename to orm/tests/unit/common/test_checks.py index 3dcc6d0e..a3d617a3 100755 --- a/orm/common/orm_common/tests/policy/test_checks.py +++ b/orm/tests/unit/common/test_checks.py @@ -1,7 +1,7 @@ import unittest import mock -from orm_common.policy import _checks +from orm.common.orm_common.policy import _checks from wsme.exc import ClientSideError diff --git a/orm/common/orm_common/tests/injector/test_injector.py b/orm/tests/unit/common/test_injector.py similarity index 97% rename from orm/common/orm_common/tests/injector/test_injector.py rename to orm/tests/unit/common/test_injector.py index 994dea70..09303d70 100755 --- a/orm/common/orm_common/tests/injector/test_injector.py +++ b/orm/tests/unit/common/test_injector.py @@ -3,7 +3,7 @@ import os from unittest import TestCase import mock -from orm_common.injector import injector +from orm.common.orm_common.injector import injector logger = logging.getLogger(__name__) diff --git a/orm/common/orm_common/tests/policy/test_policy.py b/orm/tests/unit/common/test_policy.py similarity index 99% rename from orm/common/orm_common/tests/policy/test_policy.py rename to orm/tests/unit/common/test_policy.py index 21f7c621..ef44b8af 100755 --- a/orm/common/orm_common/tests/policy/test_policy.py +++ b/orm/tests/unit/common/test_policy.py @@ -1,7 +1,7 @@ import unittest import mock -from orm_common.policy import policy +from orm.common.orm_common.policy import policy class TestException(Exception): diff --git a/orm/common/orm_common/tests/hooks/test_security_headers_hook.py b/orm/tests/unit/common/test_security_headers_hook.py similarity index 94% rename from orm/common/orm_common/tests/hooks/test_security_headers_hook.py rename to orm/tests/unit/common/test_security_headers_hook.py index 66f1462b..bfabe453 100755 --- a/orm/common/orm_common/tests/hooks/test_security_headers_hook.py +++ b/orm/tests/unit/common/test_security_headers_hook.py @@ -1,7 +1,7 @@ from unittest import TestCase import mock -from orm_common.hooks import security_headers_hook +from orm.common.orm_common.hooks import security_headers_hook class MyHeaders(object): diff --git a/orm/common/orm_common/tests/hooks/test_transaction_id_hook.py b/orm/tests/unit/common/test_transaction_id_hook.py similarity index 89% rename from orm/common/orm_common/tests/hooks/test_transaction_id_hook.py rename to orm/tests/unit/common/test_transaction_id_hook.py index 2dacac48..d326c2df 100755 --- a/orm/common/orm_common/tests/hooks/test_transaction_id_hook.py +++ b/orm/tests/unit/common/test_transaction_id_hook.py @@ -2,7 +2,7 @@ import logging from unittest import TestCase import mock -from orm_common.hooks import transaction_id_hook +from orm.common.orm_common.hooks import transaction_id_hook logger = logging.getLogger(__name__)