From 32a7100358579b09e6cb612bd0524cb8a8ba3851 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Fri, 20 Mar 2020 15:01:15 -0500 Subject: [PATCH] Use unittest.mock instead of third party mock Now that we no longer support py27, we can use the standard library unittest.mock module instead of the third party mock lib. Change-Id: I2bb5204c1ee88d0b0cd6df830dac80d37bfddcf2 Signed-off-by: Sean McGinnis --- barbican/tests/api/controllers/test_secretmeta.py | 2 +- barbican/tests/api/controllers/test_secrets.py | 2 +- barbican/tests/api/controllers/test_secretstores.py | 3 ++- barbican/tests/api/middleware/test_context.py | 3 ++- barbican/tests/api/middleware/test_simple.py | 3 +-- barbican/tests/api/test_init.py | 2 +- barbican/tests/api/test_resources.py | 2 +- barbican/tests/api/test_resources_policy.py | 2 +- barbican/tests/api/test_transport_keys_resource.py | 3 ++- barbican/tests/cmd/test_barbican_manage.py | 3 ++- barbican/tests/cmd/test_cmd.py | 2 +- barbican/tests/cmd/test_db_cleanup.py | 11 ++++++----- barbican/tests/common/test_utils.py | 3 ++- .../tests/model/repositories/test_repositories.py | 9 ++++----- barbican/tests/plugin/crypto/test_crypto.py | 2 +- barbican/tests/plugin/crypto/test_manager.py | 2 +- barbican/tests/plugin/crypto/test_p11_crypto.py | 3 ++- barbican/tests/plugin/crypto/test_pkcs11.py | 3 ++- .../plugin/interface/test_certificate_manager.py | 2 +- barbican/tests/plugin/interface/test_secret_store.py | 3 ++- barbican/tests/plugin/test_castellan_secret_store.py | 3 ++- barbican/tests/plugin/test_dogtag.py | 3 +-- barbican/tests/plugin/test_kmip.py | 10 ++++------ barbican/tests/plugin/test_resource.py | 2 +- barbican/tests/plugin/test_snakeoil_ca.py | 2 +- barbican/tests/plugin/test_store_crypto.py | 2 +- barbican/tests/plugin/test_symantec.py | 2 +- barbican/tests/plugin/util/test_multiple_backends.py | 3 ++- barbican/tests/queue/test_client.py | 2 +- barbican/tests/queue/test_keystone_listener.py | 4 ++-- barbican/tests/queue/test_retry_scheduler.py | 2 +- barbican/tests/queue/test_server.py | 3 ++- barbican/tests/tasks/test_certificate_resources.py | 2 +- barbican/tests/tasks/test_keystone_consumer.py | 5 +++-- barbican/tests/tasks/test_resources.py | 3 ++- barbican/tests/test_hacking.py | 2 +- barbican/tests/utils.py | 7 ++----- lower-constraints.txt | 1 - test-requirements.txt | 1 - 39 files changed, 64 insertions(+), 60 deletions(-) diff --git a/barbican/tests/api/controllers/test_secretmeta.py b/barbican/tests/api/controllers/test_secretmeta.py index c7ff25b9e..c29ab2e85 100644 --- a/barbican/tests/api/controllers/test_secretmeta.py +++ b/barbican/tests/api/controllers/test_secretmeta.py @@ -14,8 +14,8 @@ # limitations under the License. import os +from unittest import mock -import mock from oslo_serialization import jsonutils as json from oslo_utils import uuidutils diff --git a/barbican/tests/api/controllers/test_secrets.py b/barbican/tests/api/controllers/test_secrets.py index 155fecf7b..34622216c 100644 --- a/barbican/tests/api/controllers/test_secrets.py +++ b/barbican/tests/api/controllers/test_secrets.py @@ -14,8 +14,8 @@ # limitations under the License. import base64 import os +from unittest import mock -import mock from oslo_utils import timeutils from barbican.api.controllers import secrets diff --git a/barbican/tests/api/controllers/test_secretstores.py b/barbican/tests/api/controllers/test_secretstores.py index a36e75b65..f9f37e607 100644 --- a/barbican/tests/api/controllers/test_secretstores.py +++ b/barbican/tests/api/controllers/test_secretstores.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from oslo_utils import uuidutils from barbican.model import models diff --git a/barbican/tests/api/middleware/test_context.py b/barbican/tests/api/middleware/test_context.py index b653d67a7..ea8aba326 100644 --- a/barbican/tests/api/middleware/test_context.py +++ b/barbican/tests/api/middleware/test_context.py @@ -12,7 +12,8 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock + import oslotest.base as oslotest from barbican.api.middleware import context diff --git a/barbican/tests/api/middleware/test_simple.py b/barbican/tests/api/middleware/test_simple.py index ba5b1ba06..fb87556ae 100644 --- a/barbican/tests/api/middleware/test_simple.py +++ b/barbican/tests/api/middleware/test_simple.py @@ -12,8 +12,7 @@ # limitations under the License. import unittest - -import mock +from unittest import mock from barbican.api.middleware import simple diff --git a/barbican/tests/api/test_init.py b/barbican/tests/api/test_init.py index 58c1ab6b7..f2d837c6a 100644 --- a/barbican/tests/api/test_init.py +++ b/barbican/tests/api/test_init.py @@ -14,7 +14,7 @@ """ This test module tests the barbican.api.__init__.py module functionality. """ -import mock +from unittest import mock from oslo_serialization import jsonutils as json diff --git a/barbican/tests/api/test_resources.py b/barbican/tests/api/test_resources.py index d5d076a72..800e10e48 100644 --- a/barbican/tests/api/test_resources.py +++ b/barbican/tests/api/test_resources.py @@ -19,8 +19,8 @@ resource classes. For RBAC tests of these classes, see the 'resources_policy_test.py' module. """ import mimetypes +from unittest import mock -import mock import pecan from testtools import testcase import webtest diff --git a/barbican/tests/api/test_resources_policy.py b/barbican/tests/api/test_resources_policy.py index 9a5a9f9f1..64fa25fe7 100644 --- a/barbican/tests/api/test_resources_policy.py +++ b/barbican/tests/api/test_resources_policy.py @@ -18,8 +18,8 @@ For typical-flow business logic tests of these classes, see the 'resources_test.py' module. """ import os +from unittest import mock -import mock from webob import exc from barbican.api.controllers import consumers diff --git a/barbican/tests/api/test_transport_keys_resource.py b/barbican/tests/api/test_transport_keys_resource.py index 38d9c3183..6c7aec8b2 100644 --- a/barbican/tests/api/test_transport_keys_resource.py +++ b/barbican/tests/api/test_transport_keys_resource.py @@ -18,7 +18,8 @@ This test module focuses on typical-flow business logic tests with the transport key resource classes. """ -import mock +from unittest import mock + import pecan from six import moves import webtest diff --git a/barbican/tests/cmd/test_barbican_manage.py b/barbican/tests/cmd/test_barbican_manage.py index d9b04e64a..69f9c6183 100644 --- a/barbican/tests/cmd/test_barbican_manage.py +++ b/barbican/tests/cmd/test_barbican_manage.py @@ -12,8 +12,9 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. +from unittest import mock + import fixtures -import mock from barbican.cmd import barbican_manage as manager from barbican.tests import utils diff --git a/barbican/tests/cmd/test_cmd.py b/barbican/tests/cmd/test_cmd.py index 6ae1729be..28f42923f 100644 --- a/barbican/tests/cmd/test_cmd.py +++ b/barbican/tests/cmd/test_cmd.py @@ -12,8 +12,8 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -import mock import sys +from unittest import mock from barbican.cmd import retry_scheduler from barbican.cmd import worker diff --git a/barbican/tests/cmd/test_db_cleanup.py b/barbican/tests/cmd/test_db_cleanup.py index b0ceeedb6..613608a6a 100644 --- a/barbican/tests/cmd/test_db_cleanup.py +++ b/barbican/tests/cmd/test_db_cleanup.py @@ -13,15 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +import datetime +from unittest import mock + +from oslo_db import exception as db_exc +from sqlalchemy.exc import IntegrityError + from barbican.model import clean from barbican.model import models from barbican.model import repositories as repos from barbican.tests import database_utils as utils -from oslo_db import exception as db_exc -from sqlalchemy.exc import IntegrityError - -import datetime -import mock def _create_project(project_name): diff --git a/barbican/tests/common/test_utils.py b/barbican/tests/common/test_utils.py index 9abd80695..d3ae0f5d8 100644 --- a/barbican/tests/common/test_utils.py +++ b/barbican/tests/common/test_utils.py @@ -12,7 +12,8 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock + from oslo_config import cfg import six diff --git a/barbican/tests/model/repositories/test_repositories.py b/barbican/tests/model/repositories/test_repositories.py index c34ab4882..11c0450a8 100644 --- a/barbican/tests/model/repositories/test_repositories.py +++ b/barbican/tests/model/repositories/test_repositories.py @@ -10,11 +10,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock -import six -import sqlalchemy +from unittest import mock from alembic import script as alembic_script +from oslo_config import cfg +import six +import sqlalchemy from barbican.common import config from barbican.common import exception @@ -24,8 +25,6 @@ from barbican.model import repositories from barbican.tests import database_utils from barbican.tests import utils -from oslo_config import cfg - class WhenCleaningRepositoryPagingParameters(utils.BaseTestCase): diff --git a/barbican/tests/plugin/crypto/test_crypto.py b/barbican/tests/plugin/crypto/test_crypto.py index 5a309353a..e733b4b1c 100644 --- a/barbican/tests/plugin/crypto/test_crypto.py +++ b/barbican/tests/plugin/crypto/test_crypto.py @@ -14,11 +14,11 @@ # limitations under the License. import os +from unittest import mock from cryptography import fernet from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization -import mock import six from barbican.model import models diff --git a/barbican/tests/plugin/crypto/test_manager.py b/barbican/tests/plugin/crypto/test_manager.py index 520eab573..42b38f6a5 100644 --- a/barbican/tests/plugin/crypto/test_manager.py +++ b/barbican/tests/plugin/crypto/test_manager.py @@ -11,8 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock import threading +from unittest import mock from barbican.common import utils as common_utils from barbican.plugin.crypto import base diff --git a/barbican/tests/plugin/crypto/test_p11_crypto.py b/barbican/tests/plugin/crypto/test_p11_crypto.py index eb937bd29..78ef5b9a5 100644 --- a/barbican/tests/plugin/crypto/test_p11_crypto.py +++ b/barbican/tests/plugin/crypto/test_p11_crypto.py @@ -13,7 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock + import six from barbican.common import exception as ex diff --git a/barbican/tests/plugin/crypto/test_pkcs11.py b/barbican/tests/plugin/crypto/test_pkcs11.py index 97ce44a2a..ab33eb48c 100644 --- a/barbican/tests/plugin/crypto/test_pkcs11.py +++ b/barbican/tests/plugin/crypto/test_pkcs11.py @@ -11,7 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock + import six from barbican.common import exception diff --git a/barbican/tests/plugin/interface/test_certificate_manager.py b/barbican/tests/plugin/interface/test_certificate_manager.py index dbf83fba4..8592def18 100644 --- a/barbican/tests/plugin/interface/test_certificate_manager.py +++ b/barbican/tests/plugin/interface/test_certificate_manager.py @@ -12,8 +12,8 @@ # limitations under the License. import datetime +from unittest import mock -import mock import testtools from barbican.common import utils as common_utils diff --git a/barbican/tests/plugin/interface/test_secret_store.py b/barbican/tests/plugin/interface/test_secret_store.py index 64a206716..fec5ef1ba 100644 --- a/barbican/tests/plugin/interface/test_secret_store.py +++ b/barbican/tests/plugin/interface/test_secret_store.py @@ -13,7 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock + import six from barbican.common import utils as common_utils diff --git a/barbican/tests/plugin/test_castellan_secret_store.py b/barbican/tests/plugin/test_castellan_secret_store.py index 11bb98c38..a55147b3f 100644 --- a/barbican/tests/plugin/test_castellan_secret_store.py +++ b/barbican/tests/plugin/test_castellan_secret_store.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from unittest import mock + from castellan.common import exception from castellan.common.objects import opaque_data -import mock import barbican.plugin.castellan_secret_store as css import barbican.plugin.interface.secret_store as ss diff --git a/barbican/tests/plugin/test_dogtag.py b/barbican/tests/plugin/test_dogtag.py index a057413a5..2464955c7 100644 --- a/barbican/tests/plugin/test_dogtag.py +++ b/barbican/tests/plugin/test_dogtag.py @@ -17,12 +17,11 @@ import base64 import datetime import os import tempfile +from unittest import mock from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives import serialization - -import mock from requests import exceptions as request_exceptions import testtools diff --git a/barbican/tests/plugin/test_kmip.py b/barbican/tests/plugin/test_kmip.py index cc7738b71..bccb30c57 100644 --- a/barbican/tests/plugin/test_kmip.py +++ b/barbican/tests/plugin/test_kmip.py @@ -16,19 +16,17 @@ import base64 import ssl import stat import testtools - -import mock - -from barbican.plugin.interface import secret_store -from barbican.tests import keys -from barbican.tests import utils +from unittest import mock from kmip.core import enums from kmip.pie import client from kmip.pie import objects +from barbican.plugin.interface import secret_store from barbican.plugin import kmip_secret_store as kss from barbican.plugin.util import translations +from barbican.tests import keys +from barbican.tests import utils def get_sample_opaque_secret(): diff --git a/barbican/tests/plugin/test_resource.py b/barbican/tests/plugin/test_resource.py index 19a98cb72..c14d48c63 100644 --- a/barbican/tests/plugin/test_resource.py +++ b/barbican/tests/plugin/test_resource.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import base64 +from unittest import mock -import mock import testtools from barbican.model import models diff --git a/barbican/tests/plugin/test_snakeoil_ca.py b/barbican/tests/plugin/test_snakeoil_ca.py index d507afdad..62517847c 100644 --- a/barbican/tests/plugin/test_snakeoil_ca.py +++ b/barbican/tests/plugin/test_snakeoil_ca.py @@ -15,11 +15,11 @@ import base64 import os +from unittest import mock from cryptography.hazmat.backends import default_backend from cryptography import x509 import fixtures -import mock from OpenSSL import crypto from oslo_config import fixture as oslo_fixture diff --git a/barbican/tests/plugin/test_store_crypto.py b/barbican/tests/plugin/test_store_crypto.py index a6338a667..584f2bfd4 100644 --- a/barbican/tests/plugin/test_store_crypto.py +++ b/barbican/tests/plugin/test_store_crypto.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import base64 +from unittest import mock -import mock import testtools from barbican.common import utils diff --git a/barbican/tests/plugin/test_symantec.py b/barbican/tests/plugin/test_symantec.py index 1b7b2bdac..8715e3138 100644 --- a/barbican/tests/plugin/test_symantec.py +++ b/barbican/tests/plugin/test_symantec.py @@ -13,8 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock import testtools +from unittest import mock try: import barbican.plugin.interface.certificate_manager as cm diff --git a/barbican/tests/plugin/util/test_multiple_backends.py b/barbican/tests/plugin/util/test_multiple_backends.py index d9c6529b4..4c4e9c626 100644 --- a/barbican/tests/plugin/util/test_multiple_backends.py +++ b/barbican/tests/plugin/util/test_multiple_backends.py @@ -14,7 +14,8 @@ # limitations under the License. import collections -import mock +from unittest import mock + from oslo_utils import uuidutils from barbican.common import config diff --git a/barbican/tests/queue/test_client.py b/barbican/tests/queue/test_client.py index 2eed809f5..cf0c62c40 100644 --- a/barbican/tests/queue/test_client.py +++ b/barbican/tests/queue/test_client.py @@ -12,7 +12,7 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock from barbican import queue from barbican.queue import client diff --git a/barbican/tests/queue/test_keystone_listener.py b/barbican/tests/queue/test_keystone_listener.py index c44d29d51..9f3bfe779 100644 --- a/barbican/tests/queue/test_keystone_listener.py +++ b/barbican/tests/queue/test_keystone_listener.py @@ -12,11 +12,11 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -from oslo_utils import uuidutils +from unittest import mock -import mock import oslo_messaging from oslo_service import service +from oslo_utils import uuidutils from barbican.common import config from barbican import queue diff --git a/barbican/tests/queue/test_retry_scheduler.py b/barbican/tests/queue/test_retry_scheduler.py index 893c643fc..1a9f6c6c4 100644 --- a/barbican/tests/queue/test_retry_scheduler.py +++ b/barbican/tests/queue/test_retry_scheduler.py @@ -13,9 +13,9 @@ import datetime import time +from unittest import mock import eventlet -import mock import oslotest.base as oslotest from barbican.model import models diff --git a/barbican/tests/queue/test_server.py b/barbican/tests/queue/test_server.py index 00abe5124..37b04f636 100644 --- a/barbican/tests/queue/test_server.py +++ b/barbican/tests/queue/test_server.py @@ -13,7 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import datetime -import mock +from unittest import mock + import six from barbican.model import models diff --git a/barbican/tests/tasks/test_certificate_resources.py b/barbican/tests/tasks/test_certificate_resources.py index bad132b3e..ff8559853 100644 --- a/barbican/tests/tasks/test_certificate_resources.py +++ b/barbican/tests/tasks/test_certificate_resources.py @@ -15,11 +15,11 @@ import base64 import datetime +from unittest import mock from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives import serialization -import mock from OpenSSL import crypto from oslo_utils import encodeutils diff --git a/barbican/tests/tasks/test_keystone_consumer.py b/barbican/tests/tasks/test_keystone_consumer.py index be929089b..4a0caa8cd 100644 --- a/barbican/tests/tasks/test_keystone_consumer.py +++ b/barbican/tests/tasks/test_keystone_consumer.py @@ -13,7 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock + +from oslo_utils import uuidutils import sqlalchemy from barbican.common import exception @@ -24,7 +26,6 @@ from barbican.plugin.crypto import manager from barbican.plugin import resources as plugin from barbican.tasks import keystone_consumer as consumer from barbican.tests import database_utils -from oslo_utils import uuidutils class InitializeDatabaseMixin(object): diff --git a/barbican/tests/tasks/test_resources.py b/barbican/tests/tasks/test_resources.py index 8a51f39e5..b4168f839 100644 --- a/barbican/tests/tasks/test_resources.py +++ b/barbican/tests/tasks/test_resources.py @@ -13,7 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock + from oslo_utils import timeutils import six diff --git a/barbican/tests/test_hacking.py b/barbican/tests/test_hacking.py index 228bdce26..2b73e1e44 100644 --- a/barbican/tests/test_hacking.py +++ b/barbican/tests/test_hacking.py @@ -13,9 +13,9 @@ # under the License. import textwrap +from unittest import mock import ddt -import mock import pep8 from barbican.hacking import checks diff --git a/barbican/tests/utils.py b/barbican/tests/utils.py index c7744e96e..d53757152 100644 --- a/barbican/tests/utils.py +++ b/barbican/tests/utils.py @@ -19,26 +19,23 @@ import os from os import path import time import types +from unittest import mock -import mock +from OpenSSL import crypto from oslo_config import cfg from oslo_utils import uuidutils import oslotest.base as oslotest from oslotest import createfile - import six from six.moves.urllib import parse import webtest -from OpenSSL import crypto - from barbican.api import app from barbican.common import config import barbican.context from barbican.model import repositories from barbican.plugin.crypto import manager as cm from barbican.plugin.crypto import p11_crypto - from barbican.plugin.interface import secret_store from barbican.plugin import kmip_secret_store as kss from barbican.tests import database_utils diff --git a/lower-constraints.txt b/lower-constraints.txt index a71a47178..27b789032 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -52,7 +52,6 @@ logutils==0.3.5 Mako==1.0.7 MarkupSafe==1.0 mccabe==0.2.1 -mock==2.0.0 monotonic==1.4 mox3==0.25.0 msgpack==0.5.6 diff --git a/test-requirements.txt b/test-requirements.txt index 385b17390..b25df2552 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,7 +7,6 @@ hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.0.1 # MIT -mock>=2.0.0 # BSD oslotest>=3.2.0 # Apache-2.0 pykmip>=0.7.0 # Apache 2.0 License stestr>=2.0.0 # Apache-2.0