Remove mox/mox3 usage from test_cli20_tag
Change-Id: I2570d45b155d968c6711a10012cd38619e83e4a2 Partial-Bug: #1753504
This commit is contained in:
@@ -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',
|
||||||
|
return_value=(test_cli20.MyResp(204), None)
|
||||||
|
) as mock_request:
|
||||||
if body:
|
if body:
|
||||||
body = test_cli20.MyComparator(body, self.client)
|
body = test_cli20.MyComparator(body, self.client)
|
||||||
self.client.httpclient.request(
|
|
||||||
test_cli20.MyUrlComparator(test_cli20.end_url(path), self.client),
|
|
||||||
method, body=body,
|
|
||||||
headers=mox.ContainsKeyValue(
|
|
||||||
'X-Auth-Token', test_cli20.TOKEN)).AndReturn(
|
|
||||||
(test_cli20.MyResp(204), None))
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
cmd_parser = cmd.get_parser(prog_name)
|
cmd_parser = cmd.get_parser(prog_name)
|
||||||
shell.run_command(cmd, cmd_parser, args)
|
shell.run_command(cmd, cmd_parser, args)
|
||||||
self.mox.VerifyAll()
|
|
||||||
self.mox.UnsetStubs()
|
mock_get_client.assert_called_once_with()
|
||||||
|
mock_request.assert_called_once_with(
|
||||||
|
test_cli20.MyUrlComparator(test_cli20.end_url(path), self.client),
|
||||||
|
method, body=body,
|
||||||
|
headers=test_cli20.ContainsKeyValue(
|
||||||
|
{'X-Auth-Token': test_cli20.TOKEN}))
|
||||||
|
|
||||||
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)
|
||||||
'GET', body=None,
|
) as mock_request:
|
||||||
headers=mox.ContainsKeyValue(
|
|
||||||
'X-Auth-Token', test_cli20.TOKEN)).AndReturn(
|
|
||||||
(test_cli20.MyResp(200), resstr))
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
cmd_parser = cmd.get_parser("list_networks")
|
cmd_parser = cmd.get_parser("list_networks")
|
||||||
shell.run_command(cmd, cmd_parser, args)
|
shell.run_command(cmd, cmd_parser, args)
|
||||||
self.mox.VerifyAll()
|
|
||||||
self.mox.UnsetStubs()
|
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,
|
||||||
|
headers=test_cli20.ContainsKeyValue(
|
||||||
|
{'X-Auth-Token': test_cli20.TOKEN}))
|
||||||
|
|
||||||
_str = self.fake_stdout.make_string()
|
_str = self.fake_stdout.make_string()
|
||||||
self.assertIn('myid', _str)
|
self.assertIn('myid', _str)
|
||||||
|
|
||||||
@@ -124,8 +124,7 @@ 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¬-tags-any=black"
|
query = "not-tags=red,blue&tags-any=green¬-tags-any=black"
|
||||||
|
Reference in New Issue
Block a user