Fix using wrong status code in some tests

Some client tests uses status code 204 although it expects the
API returns a body with status code 200, for instance,
test_add_interface_by_subnet, test_add_peer_to_bgp_speaker, and so on.

This patch makes the tests use correct status code and also changes
default status code into 200 because it's an usual code of PUT operation.

Change-Id: I5dbcad8769a32e8834347fb57695db72b313b0a5
Closes-bug: #1611167
This commit is contained in:
Hirofumi Ichihara 2016-08-09 11:00:26 +09:00 committed by Kevin Benton
parent c91f9f2ccd
commit 4d4e4decc3
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

@ -531,7 +531,8 @@ class CLITestV20Base(base.BaseTestCase):
self.assertIn(myid, _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)
@ -543,7 +544,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("delete_" + cmd_resource)
shell.run_command(cmd, cmd_parser, args)

View File

@ -290,11 +290,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

@ -305,8 +305,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']