diff options
author | Hongbin Lu <hongbin.lu@huawei.com> | 2018-03-07 23:02:59 +0000 |
---|---|---|
committer | Hongbin Lu <hongbin.lu@huawei.com> | 2018-03-12 18:47:21 +0000 |
commit | 03c5c1f537bdb31f1014721d0c07660b8c74f75b (patch) | |
tree | 5b00d1b6bdf3f6da967edd24cf9e79173e19ec7b | |
parent | f92e3b27921c7132bc39a44528314ec7483a666a (diff) | |
download | python-neutronclient-03c5c1f537bdb31f1014721d0c07660b8c74f75b.tar.gz |
Remove mox/mox3 usage from test_quota
Change-Id: I879a3ae40d13e0a41b655ee028640463aa809c8b
Partial-Bug: #1753504
-rw-r--r-- | neutronclient/tests/unit/test_cli20.py | 26 | ||||
-rw-r--r-- | neutronclient/tests/unit/test_quota.py | 28 |
2 files changed, 39 insertions, 15 deletions
diff --git a/neutronclient/tests/unit/test_cli20.py b/neutronclient/tests/unit/test_cli20.py index 0837a6c..7c56897 100644 --- a/neutronclient/tests/unit/test_cli20.py +++ b/neutronclient/tests/unit/test_cli20.py @@ -170,6 +170,32 @@ class MyComparator(mox.Comparator): return str(self.lhs) +class ContainsKeyValue(object): + """Checks whether key/value pair(s) are included in a dict parameter. + + This class just checks whether specifid key/value pairs passed in + __init__() are included in a dict parameter. The comparison does not + fail even if other key/value pair(s) exists in a target dict. + """ + + def __init__(self, expected): + self._expected = expected + + def __eq__(self, other): + if not isinstance(other, dict): + return False + for key, value in self._expected.items(): + if key not in other: + return False + if other[key] != value: + return False + return True + + def __repr__(self): + return ('<%s (expected: %s)>' % + (self.__class__.__name__, self._expected)) + + class CLITestV20Base(base.BaseTestCase): test_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' diff --git a/neutronclient/tests/unit/test_quota.py b/neutronclient/tests/unit/test_quota.py index d4bc4aa..6192bbb 100644 --- a/neutronclient/tests/unit/test_quota.py +++ b/neutronclient/tests/unit/test_quota.py @@ -16,7 +16,7 @@ import sys -from mox3 import mox +import mock from neutronclient.common import exceptions from neutronclient.neutron.v2_0 import quota as test_quota @@ -67,26 +67,24 @@ class CLITestV20Quota(test_cli20.CLITestV20Base): cmd = test_quota.ShowQuotaDefault( test_cli20.MyApp(sys.stdout), None) args = ['--tenant-id', self.test_id] - self.mox.StubOutWithMock(cmd, "get_client") - self.mox.StubOutWithMock(self.client.httpclient, "request") - cmd.get_client().MultipleTimes().AndReturn(self.client) expected_res = {'quota': {'port': 50, 'network': 10, 'subnet': 10}} resstr = self.client.serialize(expected_res) path = getattr(self.client, "quota_default_path") return_tup = (test_cli20.MyResp(200), resstr) - self.client.httpclient.request( + with mock.patch.object(cmd, 'get_client', + return_value=self.client) as mock_get_client, \ + mock.patch.object(self.client.httpclient, 'request', + return_value=return_tup) as mock_request: + cmd_parser = cmd.get_parser("test_" + resource) + parsed_args = cmd_parser.parse_args(args) + cmd.run(parsed_args) + + mock_get_client.assert_called_once_with() + mock_request.assert_called_once_with( test_cli20.end_url(path % self.test_id), 'GET', body=None, - headers=mox.ContainsKeyValue( - 'X-Auth-Token', test_cli20.TOKEN)).AndReturn(return_tup) - self.mox.ReplayAll() - - cmd_parser = cmd.get_parser("test_" + resource) - parsed_args = cmd_parser.parse_args(args) - cmd.run(parsed_args) - - self.mox.VerifyAll() - self.mox.UnsetStubs() + headers=test_cli20.ContainsKeyValue( + {'X-Auth-Token': test_cli20.TOKEN})) _str = self.fake_stdout.make_string() self.assertIn('network', _str) self.assertIn('subnet', _str) |