Merge "Fix using wrong status code in some tests"

This commit is contained in:
Jenkins 2017-04-16 12:14:59 +00:00 committed by Gerrit Code Review
commit 700c0b4057
4 changed files with 19 additions and 7 deletions

View File

@ -210,10 +210,14 @@ class CLITestV20BGPSpeakerJSON(test_cli20.CLITestV20Base):
body = {'bgp_peer_id': 'peerid'}
if action == 'add':
retval = {'bgp_peer': 'peerid'}
retval = self.client.serialize(retval)
expected_code = 200
else:
retval = None
expected_code = 204
self._test_update_resource_action(resource, cmd, 'myid',
subcmd, args, body, retval)
subcmd, args, body, expected_code,
retval)
def test_add_peer_to_bgp_speaker(self):
# Add peer to BGP speaker: myid peer_id=peerid
@ -236,10 +240,14 @@ class CLITestV20BGPSpeakerJSON(test_cli20.CLITestV20Base):
body = {'network_id': 'netid'}
if action == 'add':
retval = {'network': 'netid'}
retval = self.client.serialize(retval)
expected_code = 200
else:
retval = None
expected_code = 204
self._test_update_resource_action(resource, cmd, 'myid',
subcmd, args, body, retval)
subcmd, args, body, expected_code,
retval)
def test_add_network_to_bgp_speaker(self):
# Add peer to BGP speaker: myid network_id=netid

View File

@ -554,7 +554,8 @@ class CLITestV20Base(base.BaseTestCase):
self.assertIn(extra_id, _str)
def _test_update_resource_action(self, resource, cmd, myid, action, args,
body, retval=None, cmd_resource=None):
body, expected_code=200, retval=None,
cmd_resource=None):
self.mox.StubOutWithMock(cmd, "get_client")
self.mox.StubOutWithMock(self.client.httpclient, "request")
cmd.get_client().MultipleTimes().AndReturn(self.client)
@ -566,7 +567,8 @@ class CLITestV20Base(base.BaseTestCase):
end_url(path % path_action, format=self.format), 'PUT',
body=MyComparator(body, self.client),
headers=mox.ContainsKeyValue(
'X-Auth-Token', TOKEN)).AndReturn((MyResp(204), retval))
'X-Auth-Token', TOKEN)).AndReturn((MyResp(expected_code),
retval))
self.mox.ReplayAll()
cmd_parser = cmd.get_parser("update_" + cmd_resource)
shell.run_command(cmd, cmd_parser, args)

View File

@ -303,11 +303,14 @@ class CLITestV20RouterJSON(test_cli20.CLITestV20Base):
body = {'subnet_id': 'subnetid'}
if action == 'add':
retval = {'subnet_id': 'subnetid', 'port_id': 'portid'}
retval = self.client.serialize(retval)
expected_code = 200
else:
retval = None
expected_code = 204
self._test_update_resource_action(resource, cmd, 'myid',
subcmd, args,
body, retval)
body, expected_code, retval)
def test_add_interface_compat(self):
# Add interface to router: myid subnetid.

View File

@ -312,8 +312,7 @@ class ClientBase(object):
def deserialize(self, data, status_code):
"""Deserializes a JSON string into a dictionary."""
# TODO(hichihara): Remove checking 204 in bug 1611167
if status_code == 204 or not data:
if not data:
return data
return serializer.Serializer().deserialize(
data)['body']