Browse Source

Use unittest.mock instead of third party lib

mock was adopted into standard python
in version 3.3 [1]. Since python-manilaclient
no longer supports python2.7, we can use the inbuilt
mock package rather than the third party
lib.

Also fix some issues with imports that
weren't following our import conventions
of grouping imports [3]

[1] https://docs.python.org/3/library/unittest.mock.html
[2] http://lists.openstack.org/pipermail/openstack-discuss/2020-March/013281.html
[3] https://docs.openstack.org/hacking/latest/user/hacking.html#imports

Change-Id: I3e199e1a117ddf7739fce8858694a801a26ed08f
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
changes/28/720628/6
Goutham Pacha Ravi 10 months ago
parent
commit
2d4df937d5
39 changed files with 79 additions and 48 deletions
  1. +5
    -1
      lower-constraints.txt
  2. +3
    -2
      manilaclient/tests/unit/common/test_httpclient.py
  3. +2
    -2
      manilaclient/tests/unit/osc/osc_fakes.py
  4. +1
    -1
      manilaclient/tests/unit/osc/v2/fakes.py
  5. +2
    -4
      manilaclient/tests/unit/osc/v2/test_share.py
  6. +2
    -2
      manilaclient/tests/unit/osc/v2/test_share_type.py
  7. +2
    -1
      manilaclient/tests/unit/test_api_versions.py
  8. +2
    -1
      manilaclient/tests/unit/test_base.py
  9. +2
    -1
      manilaclient/tests/unit/test_client.py
  10. +1
    -1
      manilaclient/tests/unit/test_shell.py
  11. +1
    -1
      manilaclient/tests/unit/utils.py
  12. +2
    -1
      manilaclient/tests/unit/v2/test_availability_zones.py
  13. +2
    -2
      manilaclient/tests/unit/v2/test_client.py
  14. +2
    -1
      manilaclient/tests/unit/v2/test_limits.py
  15. +1
    -1
      manilaclient/tests/unit/v2/test_messages.py
  16. +2
    -1
      manilaclient/tests/unit/v2/test_quota_classes.py
  17. +2
    -1
      manilaclient/tests/unit/v2/test_quotas.py
  18. +1
    -1
      manilaclient/tests/unit/v2/test_scheduler_stats.py
  19. +2
    -1
      manilaclient/tests/unit/v2/test_security_services.py
  20. +2
    -1
      manilaclient/tests/unit/v2/test_services.py
  21. +2
    -1
      manilaclient/tests/unit/v2/test_share_export_locations.py
  22. +1
    -1
      manilaclient/tests/unit/v2/test_share_group_snapshots.py
  23. +1
    -1
      manilaclient/tests/unit/v2/test_share_group_type_access.py
  24. +1
    -1
      manilaclient/tests/unit/v2/test_share_group_types.py
  25. +1
    -1
      manilaclient/tests/unit/v2/test_share_groups.py
  26. +2
    -1
      manilaclient/tests/unit/v2/test_share_instance_export_locations.py
  27. +2
    -1
      manilaclient/tests/unit/v2/test_share_instances.py
  28. +2
    -1
      manilaclient/tests/unit/v2/test_share_network_subnets.py
  29. +3
    -2
      manilaclient/tests/unit/v2/test_share_networks.py
  30. +2
    -1
      manilaclient/tests/unit/v2/test_share_replica_export_locations.py
  31. +3
    -1
      manilaclient/tests/unit/v2/test_share_replicas.py
  32. +2
    -1
      manilaclient/tests/unit/v2/test_share_servers.py
  33. +2
    -1
      manilaclient/tests/unit/v2/test_share_snapshot_instances.py
  34. +2
    -1
      manilaclient/tests/unit/v2/test_share_snapshots.py
  35. +2
    -1
      manilaclient/tests/unit/v2/test_shares.py
  36. +3
    -2
      manilaclient/tests/unit/v2/test_shell.py
  37. +2
    -1
      manilaclient/tests/unit/v2/test_type_access.py
  38. +3
    -2
      manilaclient/tests/unit/v2/test_types.py
  39. +4
    -0
      test-requirements.txt

+ 5
- 1
lower-constraints.txt View File

@ -30,7 +30,6 @@ jsonschema==2.6.0
keystoneauth1==3.4.0
linecache2==1.0.0
MarkupSafe==1.0
mock==2.0.0
monotonic==0.6
msgpack-python==0.4.0
munch==2.1.0
@ -85,3 +84,8 @@ unittest2==1.1.0
urllib3==1.21.1
warlock==1.2.0
wrapt==1.7.0
# Can be removed in Victoria cycle, when we raise the requirement of
# python-openstackclient in test-requirements to a version that no longer
# requires mock. See: https://review.opendev.org/#/c/717410/
mock==2.0.0

+ 3
- 2
manilaclient/tests/unit/common/test_httpclient.py View File

@ -10,9 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
import re
from unittest import mock
import ddt
import requests
import manilaclient


+ 2
- 2
manilaclient/tests/unit/osc/osc_fakes.py View File

@ -13,11 +13,11 @@
# under the License.
#
import mock
from oslo_serialization import jsonutils
import sys
from unittest import mock
from keystoneauth1 import fixture
from oslo_serialization import jsonutils
import requests
AUTH_TOKEN = "foobar"


+ 1
- 1
manilaclient/tests/unit/osc/v2/fakes.py View File

@ -13,8 +13,8 @@
import copy
import datetime
import mock
import random
from unittest import mock
import uuid
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes


+ 2
- 4
manilaclient/tests/unit/osc/v2/test_share.py View File

@ -14,11 +14,9 @@
#
import argparse
import mock
from unittest import mock
import uuid
from mock import call
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
from manilaclient.common import cliutils
@ -189,7 +187,7 @@ class TestShareDelete(TestShare):
result = self.cmd.take_action(parsed_args)
calls = [call(s, None) for s in shares]
calls = [mock.call(s, None) for s in shares]
self.shares_mock.delete.assert_has_calls(calls)
self.assertIsNone(result)


+ 2
- 2
manilaclient/tests/unit/osc/v2/test_share_type.py View File

@ -11,7 +11,7 @@
# under the License.
#
from mock import call
from unittest import mock
from osc_lib import exceptions
from osc_lib import utils as oscutils
@ -278,7 +278,7 @@ class TestShareTypeDelete(TestShareType):
calls = []
for t in self.share_types:
calls.append(call(t))
calls.append(mock.call(t))
self.shares_mock.delete.assert_has_calls(calls)
self.assertIsNone(result)


+ 2
- 1
manilaclient/tests/unit/test_api_versions.py View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
import six
import manilaclient


+ 2
- 1
manilaclient/tests/unit/test_base.py View File

@ -9,7 +9,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from mock import mock
from unittest import mock
from manilaclient.common.apiclient import base as common_base
from manilaclient import exceptions


+ 2
- 1
manilaclient/tests/unit/test_client.py View File

@ -10,8 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient import client


+ 1
- 1
manilaclient/tests/unit/test_shell.py View File

@ -12,10 +12,10 @@
import re
import sys
from unittest import mock
import ddt
import fixtures
import mock
from six import moves
from tempest.lib.cli import output_parser
from testtools import matchers


+ 1
- 1
manilaclient/tests/unit/utils.py View File

@ -11,9 +11,9 @@
# under the License.
import os
from unittest import mock
import fixtures
import mock
import requests
import testtools


+ 2
- 1
manilaclient/tests/unit/v2/test_availability_zones.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient.tests.unit import utils


+ 2
- 2
manilaclient/tests/unit/v2/test_client.py View File

@ -10,15 +10,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from oslo_utils import uuidutils
import manilaclient
from manilaclient import exceptions
from manilaclient.tests.unit import utils
from manilaclient.v2 import client
from oslo_utils import uuidutils
@ddt.ddt


+ 2
- 1
manilaclient/tests/unit/v2/test_limits.py View File

@ -13,8 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest import mock
import ddt
import mock
from manilaclient.tests.unit import utils
from manilaclient.v2 import limits


+ 1
- 1
manilaclient/tests/unit/v2/test_messages.py View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import ddt
import six


+ 2
- 1
manilaclient/tests/unit/v2/test_quota_classes.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient.tests.unit import utils


+ 2
- 1
manilaclient/tests/unit/v2/test_quotas.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient.tests.unit import utils


+ 1
- 1
manilaclient/tests/unit/v2/test_scheduler_stats.py View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from manilaclient.tests.unit import utils
from manilaclient.tests.unit.v2 import fakes


+ 2
- 1
manilaclient/tests/unit/v2/test_security_services.py View File

@ -12,7 +12,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from manilaclient import exceptions
from manilaclient.tests.unit import utils


+ 2
- 1
manilaclient/tests/unit/v2/test_services.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient.tests.unit import utils


+ 2
- 1
manilaclient/tests/unit/v2/test_share_export_locations.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient import extension


+ 1
- 1
manilaclient/tests/unit/v2/test_share_group_snapshots.py View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import ddt
import six


+ 1
- 1
manilaclient/tests/unit/v2/test_share_group_type_access.py View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import ddt
import six


+ 1
- 1
manilaclient/tests/unit/v2/test_share_group_types.py View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import ddt
import six


+ 1
- 1
manilaclient/tests/unit/v2/test_share_groups.py View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import ddt
import six


+ 2
- 1
manilaclient/tests/unit/v2/test_share_instance_export_locations.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient import extension


+ 2
- 1
manilaclient/tests/unit/v2/test_share_instances.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient import extension


+ 2
- 1
manilaclient/tests/unit/v2/test_share_network_subnets.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient.tests.unit import utils
from manilaclient.tests.unit.v2 import fakes


+ 3
- 2
manilaclient/tests/unit/v2/test_share_networks.py View File

@ -13,9 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import itertools
import mock
from unittest import mock
import ddt
from manilaclient import api_versions
from manilaclient import exceptions


+ 2
- 1
manilaclient/tests/unit/v2/test_share_replica_export_locations.py View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient.tests.unit import utils


+ 3
- 1
manilaclient/tests/unit/v2/test_share_replicas.py View File

@ -12,8 +12,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient.tests.unit import utils


+ 2
- 1
manilaclient/tests/unit/v2/test_share_servers.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient.common.apiclient import base as common_base
from manilaclient.common import constants


+ 2
- 1
manilaclient/tests/unit/v2/test_share_snapshot_instances.py View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient import exceptions


+ 2
- 1
manilaclient/tests/unit/v2/test_share_snapshots.py View File

@ -15,8 +15,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient import extension


+ 2
- 1
manilaclient/tests/unit/v2/test_shares.py View File

@ -15,8 +15,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient.common.apiclient import exceptions as client_exceptions


+ 3
- 2
manilaclient/tests/unit/v2/test_shell.py View File

@ -15,10 +15,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import itertools
from unittest import mock
import ddt
import fixtures
import itertools
import mock
from oslo_utils import strutils
import six


+ 2
- 1
manilaclient/tests/unit/v2/test_type_access.py View File

@ -14,8 +14,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from manilaclient import api_versions
from manilaclient.tests.unit import utils


+ 3
- 2
manilaclient/tests/unit/v2/test_types.py View File

@ -12,9 +12,10 @@
# limitations under the License.
import copy
import ddt
import itertools
import mock
from unittest import mock
import ddt
from manilaclient import api_versions
from manilaclient import config


+ 4
- 0
test-requirements.txt View File

@ -8,8 +8,12 @@ hacking>=3.0.1,<3.1.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
ddt>=1.0.1 # MIT
fixtures>=3.0.0 # Apache-2.0/BSD
# Can be removed in Victoria cycle, when we raise the requirement of
# python-openstackclient in this file to a version that no longer
# requires mock. See: https://review.opendev.org/717410/
mock>=2.0.0 # BSD
os-testr>=1.0.0 # Apache-2.0
tempest>=17.1.0 # Apache-2.0
testtools>=2.2.0 # MIT
python-openstackclient>=3.12.0 # Apache-2.0

Loading…
Cancel
Save