Remove mox/mox3 usage from test_cli20_tag

Change-Id: I2570d45b155d968c6711a10012cd38619e83e4a2
Partial-Bug: #1753504
This commit is contained in:
Hongbin Lu
2018-03-07 23:45:29 +00:00
parent 03c5c1f537
commit 06961da731

View File

@@ -12,7 +12,7 @@
import sys import sys
from mox3 import mox import mock
from neutronclient.common import exceptions from neutronclient.common import exceptions
from neutronclient.neutron.v2_0 import network from neutronclient.neutron.v2_0 import network
@@ -24,43 +24,43 @@ from neutronclient.tests.unit import test_cli20
class CLITestV20Tag(test_cli20.CLITestV20Base): class CLITestV20Tag(test_cli20.CLITestV20Base):
def _test_tag_operation(self, cmd, path, method, args, prog_name, def _test_tag_operation(self, cmd, path, method, args, prog_name,
body=None): body=None):
self.mox.StubOutWithMock(cmd, "get_client") with mock.patch.object(cmd, 'get_client',
self.mox.StubOutWithMock(self.client.httpclient, "request") return_value=self.client) as mock_get_client, \
cmd.get_client().MultipleTimes().AndReturn(self.client) mock.patch.object(self.client.httpclient, 'request',
if body: return_value=(test_cli20.MyResp(204), None)
body = test_cli20.MyComparator(body, self.client) ) as mock_request:
self.client.httpclient.request( if body:
body = test_cli20.MyComparator(body, self.client)
cmd_parser = cmd.get_parser(prog_name)
shell.run_command(cmd, cmd_parser, args)
mock_get_client.assert_called_once_with()
mock_request.assert_called_once_with(
test_cli20.MyUrlComparator(test_cli20.end_url(path), self.client), test_cli20.MyUrlComparator(test_cli20.end_url(path), self.client),
method, body=body, method, body=body,
headers=mox.ContainsKeyValue( headers=test_cli20.ContainsKeyValue(
'X-Auth-Token', test_cli20.TOKEN)).AndReturn( {'X-Auth-Token': test_cli20.TOKEN}))
(test_cli20.MyResp(204), None))
self.mox.ReplayAll()
cmd_parser = cmd.get_parser(prog_name)
shell.run_command(cmd, cmd_parser, args)
self.mox.VerifyAll()
self.mox.UnsetStubs()
def _test_tags_query(self, cmd, resources, args, query): def _test_tags_query(self, cmd, resources, args, query):
self.mox.StubOutWithMock(cmd, "get_client")
self.mox.StubOutWithMock(self.client.httpclient, "request")
cmd.get_client().MultipleTimes().AndReturn(self.client)
path = getattr(self.client, resources + "_path") path = getattr(self.client, resources + "_path")
res = {resources: [{'id': 'myid'}]} res = {resources: [{'id': 'myid'}]}
resstr = self.client.serialize(res) resstr = self.client.serialize(res)
self.client.httpclient.request( with mock.patch.object(cmd, 'get_client',
test_cli20.MyUrlComparator( return_value=self.client) as mock_get_client, \
test_cli20.end_url(path, query), mock.patch.object(self.client.httpclient, 'request',
self.client), return_value=(test_cli20.MyResp(200), resstr)
) as mock_request:
cmd_parser = cmd.get_parser("list_networks")
shell.run_command(cmd, cmd_parser, args)
mock_get_client.assert_called_once_with()
mock_request.assert_called_once_with(
test_cli20.MyUrlComparator(test_cli20.end_url(path, query),
self.client),
'GET', body=None, 'GET', body=None,
headers=mox.ContainsKeyValue( headers=test_cli20.ContainsKeyValue(
'X-Auth-Token', test_cli20.TOKEN)).AndReturn( {'X-Auth-Token': test_cli20.TOKEN}))
(test_cli20.MyResp(200), resstr))
self.mox.ReplayAll()
cmd_parser = cmd.get_parser("list_networks")
shell.run_command(cmd, cmd_parser, args)
self.mox.VerifyAll()
self.mox.UnsetStubs()
_str = self.fake_stdout.make_string() _str = self.fake_stdout.make_string()
self.assertIn('myid', _str) self.assertIn('myid', _str)
@@ -124,9 +124,8 @@ class CLITestV20Tag(test_cli20.CLITestV20Base):
# is not converted to '_'. # is not converted to '_'.
resources = 'networks' resources = 'networks'
cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None) cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
self.mox.StubOutWithMock(network.ListNetwork, "extend_list") with mock.patch.object(network.ListNetwork, 'extend_list'):
network.ListNetwork.extend_list(mox.IsA(list), mox.IgnoreArg()) args = ['--not-tags', 'red,blue', '--tags-any', 'green',
args = ['--not-tags', 'red,blue', '--tags-any', 'green', '--not-tags-any', 'black']
'--not-tags-any', 'black'] query = "not-tags=red,blue&tags-any=green&not-tags-any=black"
query = "not-tags=red,blue&tags-any=green&not-tags-any=black" self._test_tags_query(cmd, resources, args, query)
self._test_tags_query(cmd, resources, args, query)