allow samples testing for PUT to not have a body

Previously all testing of the PUT method assumed that a body existed,
which is implied by the HTTP spec, but not strictly stated. The tags
api-wg spec specifies an interface with tags that uses PUT with no
payload.

This makes our _do_put able to handle that case, and removes empty
templates when not needed.

Change-Id: I3d869d63affd08e321944c0082ee9865124d38e2
This commit is contained in:
Sean Dague 2016-04-07 08:31:26 -04:00
parent 25ea19561b
commit 78307643ac
4 changed files with 10 additions and 4 deletions

View File

@ -76,8 +76,7 @@ class ServerTagsJsonTest(test_servers.ServersSampleBase):
tag = models.Tag()
tag.resource_id = uuid
tag.tag = 'OtherTag'
response = self._do_put('servers/%s/tags/%s' % (uuid, tag.tag),
'server-tags-put-req', {})
response = self._do_put('servers/%s/tags/%s' % (uuid, tag.tag))
self.assertEqual(201, response.status_code)
expected_location = "%s/servers/%s/tags/%s" % (
self._get_vers_compute_endpoint(), uuid, tag.tag)

View File

@ -466,8 +466,15 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
self._write_sample(name, body)
return self._get_response(url, method, body, headers=headers)
def _do_put(self, url, name, subs, headers=None):
return self._do_post(url, name, subs, method='PUT', headers=headers)
def _do_put(self, url, name=None, subs=None, headers=None):
# name indicates that we have a body document. While the HTTP
# spec implies that PUT is supposed to have one, we have some
# APIs which don't.
if name:
return self._do_post(
url, name, subs, method='PUT', headers=headers)
else:
return self._get_response(url, 'PUT', headers=headers)
def _do_delete(self, url, headers=None):
return self._get_response(url, 'DELETE', headers=headers)