Remove mox/mox3 usage from lb modules

Change-Id: I667dd870b615d4a9ccefd35fcb1ebf15760b1d6d
Partial-Bug: #1753504
This commit is contained in:
Hongbin Lu 2018-03-16 19:26:18 +00:00 committed by Slawek Kaplonski
parent 9ba6f655c2
commit ce623030ee
3 changed files with 65 additions and 66 deletions

View File

@ -16,7 +16,7 @@
import sys
from mox3 import mox
import mock
from neutronclient.neutron.v2_0.lb import healthmonitor
from neutronclient.tests.unit import test_cli20
@ -149,10 +149,6 @@ class CLITestV20LbHealthmonitorJSON(test_cli20.CLITestV20Base):
pool_id = 'p_id'
args = [health_monitor_id, pool_id]
self.mox.StubOutWithMock(cmd, "get_client")
self.mox.StubOutWithMock(self.client.httpclient, "request")
cmd.get_client().MultipleTimes().AndReturn(self.client)
body = {resource: {'id': health_monitor_id}}
result = {resource: {'id': health_monitor_id}, }
result_str = self.client.serialize(result)
@ -160,17 +156,21 @@ class CLITestV20LbHealthmonitorJSON(test_cli20.CLITestV20Base):
path = getattr(self.client,
"associate_pool_health_monitors_path") % pool_id
return_tup = (test_cli20.MyResp(200), result_str)
self.client.httpclient.request(
test_cli20.end_url(path), 'POST',
body=test_cli20.MyComparator(body, self.client),
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()
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.run(parsed_args)
mock_get_client.assert_called_once_with()
mock_request.assert_called_once_with(
test_cli20.end_url(path), 'POST',
body=test_cli20.MyComparator(body, self.client),
headers=test_cli20.ContainsKeyValue(
{'X-Auth-Token': test_cli20.TOKEN}))
def test_disassociate_healthmonitor(self):
cmd = healthmonitor.DisassociateHealthMonitor(
@ -181,22 +181,22 @@ class CLITestV20LbHealthmonitorJSON(test_cli20.CLITestV20Base):
pool_id = 'p_id'
args = [health_monitor_id, pool_id]
self.mox.StubOutWithMock(cmd, "get_client")
self.mox.StubOutWithMock(self.client.httpclient, "request")
cmd.get_client().MultipleTimes().AndReturn(self.client)
path = (getattr(self.client,
"disassociate_pool_health_monitors_path") %
{'pool': pool_id, 'health_monitor': health_monitor_id})
return_tup = (test_cli20.MyResp(204), None)
self.client.httpclient.request(
test_cli20.end_url(path), 'DELETE',
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()
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.run(parsed_args)
mock_get_client.assert_called_once_with()
mock_request.assert_called_once_with(
test_cli20.end_url(path), 'DELETE',
body=None,
headers=test_cli20.ContainsKeyValue(
{'X-Auth-Token': test_cli20.TOKEN}))

View File

@ -16,7 +16,7 @@
import sys
from mox3 import mox
import mock
from neutronclient.neutron.v2_0.lb import pool
from neutronclient.tests.unit import test_cli20
@ -139,27 +139,28 @@ class CLITestV20LbPoolJSON(test_cli20.CLITestV20Base):
fields = ['bytes_in', 'bytes_out']
args = ['--fields', 'bytes_in', '--fields', 'bytes_out', my_id]
self.mox.StubOutWithMock(cmd, "get_client")
self.mox.StubOutWithMock(self.client.httpclient, "request")
cmd.get_client().MultipleTimes().AndReturn(self.client)
query = "&".join(["fields=%s" % field for field in fields])
expected_res = {'stats': {'bytes_in': '1234', 'bytes_out': '4321'}}
resstr = self.client.serialize(expected_res)
path = getattr(self.client, "pool_path_stats")
return_tup = (test_cli20.MyResp(200), resstr)
self.client.httpclient.request(
test_cli20.end_url(path % my_id, query), '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()
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.run(parsed_args)
self.assert_mock_multiple_calls_with_same_arguments(
mock_get_client, mock.call(), 2)
mock_request.assert_called_once_with(
test_cli20.end_url(path % my_id, query), 'GET',
body=None,
headers=test_cli20.ContainsKeyValue(
{'X-Auth-Token': test_cli20.TOKEN}))
_str = self.fake_stdout.make_string()
self.assertIn('bytes_in', _str)
self.assertIn('bytes_out', _str)

View File

@ -16,7 +16,7 @@
import sys
from mox3 import mox
import mock
from neutronclient.neutron.v2_0.lb.v2 import loadbalancer as lb
from neutronclient.tests.unit import test_cli20
@ -150,27 +150,27 @@ class CLITestV20LbLoadBalancerJSON(test_cli20.CLITestV20Base):
fields = ['bytes_in', 'bytes_out']
args = ['--fields', 'bytes_in', '--fields', 'bytes_out', my_id]
self.mox.StubOutWithMock(cmd, "get_client")
self.mox.StubOutWithMock(self.client.httpclient, "request")
cmd.get_client().MultipleTimes().AndReturn(self.client)
query = "&".join(["fields=%s" % field for field in fields])
expected_res = {'stats': {'bytes_in': '1234', 'bytes_out': '4321'}}
resstr = self.client.serialize(expected_res)
path = getattr(self.client, "lbaas_loadbalancer_path_stats")
return_tup = (test_cli20.MyResp(200), resstr)
self.client.httpclient.request(
test_cli20.end_url(path % my_id, query), '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)
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.run(parsed_args)
self.mox.VerifyAll()
self.mox.UnsetStubs()
self.assert_mock_multiple_calls_with_same_arguments(
mock_get_client, mock.call(), 2)
mock_request.assert_called_once_with(
test_cli20.end_url(path % my_id, query), 'GET',
body=None,
headers=test_cli20.ContainsKeyValue(
{'X-Auth-Token': test_cli20.TOKEN}))
_str = self.fake_stdout.make_string()
self.assertIn('bytes_in', _str)
self.assertIn('1234', _str)
@ -184,10 +184,6 @@ class CLITestV20LbLoadBalancerJSON(test_cli20.CLITestV20Base):
my_id = self.test_id
args = [my_id]
self.mox.StubOutWithMock(cmd, "get_client")
self.mox.StubOutWithMock(self.client.httpclient, "request")
cmd.get_client().MultipleTimes().AndReturn(self.client)
expected_res = {'statuses': {'operating_status': 'ONLINE',
'provisioning_status': 'ACTIVE'}}
@ -195,19 +191,21 @@ class CLITestV20LbLoadBalancerJSON(test_cli20.CLITestV20Base):
path = getattr(self.client, "lbaas_loadbalancer_path_status")
return_tup = (test_cli20.MyResp(200), resstr)
self.client.httpclient.request(
test_cli20.end_url(path % my_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)
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.run(parsed_args)
self.mox.VerifyAll()
self.mox.UnsetStubs()
mock_get_client.assert_called_once_with()
mock_request.assert_called_once_with(
test_cli20.end_url(path % my_id), 'GET',
body=None,
headers=test_cli20.ContainsKeyValue(
{'X-Auth-Token': test_cli20.TOKEN}))
_str = self.fake_stdout.make_string()
self.assertIn('operating_status', _str)
self.assertIn('ONLINE', _str)