summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHongbin Lu <hongbin.lu@huawei.com>2018-03-15 18:16:21 +0000
committerHongbin Lu <hongbin.lu@huawei.com>2018-03-19 17:46:08 +0000
commit02b6e6f841dcc262fb42e88d5ead06025edb0190 (patch)
tree485aa4f18fdb1e4fc733988f899260772bf2c31b
parent93e4ef2e7de95aa16e13331df14b2d157c9a24a5 (diff)
downloadpython-neutronclient-02b6e6f841dcc262fb42e88d5ead06025edb0190.tar.gz
Remove mox/mox3 usage from test_cli20_subnet.py
Change-Id: I783260f6853a7ba6f911f718ce759b292595da4f Partial-Bug: #1753504
-rw-r--r--neutronclient/tests/unit/test_cli20_subnet.py55
1 files changed, 27 insertions, 28 deletions
diff --git a/neutronclient/tests/unit/test_cli20_subnet.py b/neutronclient/tests/unit/test_cli20_subnet.py
index 33b5777..ab37cbd 100644
--- a/neutronclient/tests/unit/test_cli20_subnet.py
+++ b/neutronclient/tests/unit/test_cli20_subnet.py
@@ -16,7 +16,7 @@
import sys
-from mox3 import mox
+import mock
from neutronclient.common import exceptions
from neutronclient.neutron import v2_0 as neutronV20
@@ -418,12 +418,11 @@ class CLITestV20SubnetJSON(test_cli20.CLITestV20Base):
args = ['--gateway', gateway, netid, cidr]
position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
position_values = [4, netid, cidr, gateway]
- self.mox.StubOutWithMock(cmd.log, 'warning')
- cmd.log.warning(mox.IgnoreArg(), {'ip': 4, 'cidr': '/32'})
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
- self.mox.VerifyAll()
- self.mox.UnsetStubs()
+ with mock.patch.object(cmd.log, 'warning') as mock_warning:
+ self._test_create_resource(resource, cmd, name, myid, args,
+ position_names, position_values)
+ mock_warning.assert_called_once_with(mock.ANY,
+ {'ip': 4, 'cidr': '/32'})
def test_create_subnet_with_ipv6_ra_mode(self):
resource = 'subnet'
@@ -520,7 +519,9 @@ class CLITestV20SubnetJSON(test_cli20.CLITestV20Base):
position_values, tenant_id='tenantid',
no_api_call=True, expected_exception=exceptions.CommandError)
- def test_create_subnet_with_subnetpool_ipv6_and_ip_ver_ignored(self):
+ @mock.patch.object(neutronV20, 'find_resource_by_name_or_id')
+ def test_create_subnet_with_subnetpool_ipv6_and_ip_ver_ignored(
+ self, mock_find_resource):
resource = 'subnet'
cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
@@ -532,17 +533,17 @@ class CLITestV20SubnetJSON(test_cli20.CLITestV20Base):
netid]
position_names = ['ip_version', 'network_id', 'subnetpool_id']
position_values = [6, netid, 'subnetpool_id']
- self.mox.StubOutWithMock(neutronV20, 'find_resource_by_name_or_id')
- neutronV20.find_resource_by_name_or_id(
- self.client,
- 'subnetpool',
- 'subnetpool_id').AndReturn({'id': 'subnetpool_id',
- 'ip_version': 6})
+ mock_find_resource.return_value = {
+ 'id': 'subnetpool_id', 'ip_version': 6}
self._test_create_resource(
resource, cmd, name, myid, args, position_names,
position_values, tenant_id='tenantid')
+ mock_find_resource.assert_called_once_with(
+ self.client, 'subnetpool', 'subnetpool_id')
- def test_create_subnet_with_subnetpool_ipv4_with_cidr_wildcard(self):
+ @mock.patch.object(neutronV20, 'find_resource_by_name_or_id')
+ def test_create_subnet_with_subnetpool_ipv4_with_cidr_wildcard(
+ self, mock_find_resource):
resource = 'subnet'
cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
@@ -557,18 +558,18 @@ class CLITestV20SubnetJSON(test_cli20.CLITestV20Base):
position_names = ['ip_version', 'ipv6_address_mode',
'network_id', 'subnetpool_id', 'cidr']
position_values = [4, None, netid, 'subnetpool_id', cidr]
- self.mox.StubOutWithMock(neutronV20, 'find_resource_by_name_or_id')
- neutronV20.find_resource_by_name_or_id(
- self.client,
- 'subnetpool',
- 'subnetpool_id').AndReturn({'id': 'subnetpool_id',
- 'ip_version': 4})
+ mock_find_resource.return_value = {'id': 'subnetpool_id',
+ 'ip_version': 4}
self._test_create_resource(
resource, cmd, name, myid, args, position_names,
position_values, tenant_id='tenantid',
no_api_call=True, expected_exception=exceptions.CommandError)
+ mock_find_resource.assert_called_once_with(
+ self.client, 'subnetpool', 'subnetpool_id')
- def test_create_subnet_with_subnetpool_ipv4_with_prefixlen(self):
+ @mock.patch.object(neutronV20, 'find_resource_by_name_or_id')
+ def test_create_subnet_with_subnetpool_ipv4_with_prefixlen(
+ self, mock_find_resource):
resource = 'subnet'
cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
name = 'myname'
@@ -583,16 +584,14 @@ class CLITestV20SubnetJSON(test_cli20.CLITestV20Base):
position_names = ['ip_version', 'ipv6_address_mode',
'network_id', 'subnetpool_id']
position_values = [4, None, netid, 'subnetpool_id']
- self.mox.StubOutWithMock(neutronV20, 'find_resource_by_name_or_id')
- neutronV20.find_resource_by_name_or_id(
- self.client,
- 'subnetpool',
- 'subnetpool_id').AndReturn({'id': 'subnetpool_id',
- 'ip_version': 4})
+ mock_find_resource.return_value = {'id': 'subnetpool_id',
+ 'ip_version': 4}
self._test_create_resource(
resource, cmd, name, myid, args, position_names,
position_values, tenant_id='tenantid',
no_api_call=True, expected_exception=exceptions.CommandError)
+ mock_find_resource.assert_called_once_with(
+ self.client, 'subnetpool', 'subnetpool_id')
def test_list_subnets_detail(self):
# List subnets: -D.