Merge "Update test_xml_deprecation"
This commit is contained in:
commit
047fa2d00f
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Copyright 2015 Rackspace
|
||||
Copyright 2016 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -33,50 +33,57 @@ class XMLDeprecationTest(ComputeFixture):
|
|||
xml and ensure that the header is ignored returning a valid json
|
||||
response.
|
||||
|
||||
The following assertions occur:
|
||||
- The response content does not contain xml content
|
||||
"""
|
||||
|
||||
response_content = self._get_flavors_xml_response(accept='xml')
|
||||
self.assertNotIn('xml version', response_content,
|
||||
'Unexpected xml content was found in the response')
|
||||
|
||||
@tags(type='smoke', net='no')
|
||||
def test_get_request_content_type_xml_ignored(self):
|
||||
"""
|
||||
A GET request passing only the content-type header as xml is ignored
|
||||
|
||||
Request a list of available flavors passing only the content-type
|
||||
header as xml and ensure that the header is ignored returning a valid
|
||||
json response.
|
||||
|
||||
The following assertions occur:
|
||||
- The response content does not contain xml content
|
||||
"""
|
||||
|
||||
response_content = self._get_flavors_xml_response(content_type='xml')
|
||||
self.assertNotIn('xml version', response_content,
|
||||
'Unexpected xml content was found in the response')
|
||||
|
||||
@tags(type='smoke', net='no')
|
||||
def test_get_request_accept_and_content_type_xml_ignored(self):
|
||||
"""
|
||||
A GET request passing accept and content-type headers as xml is ignored
|
||||
|
||||
Request a list of available flavors passing both the accept and
|
||||
content-type headers as xml and ensure that the headers are ignored
|
||||
returning a valid json response.
|
||||
|
||||
The following assertions occur:
|
||||
- The response code is 200
|
||||
- The response content does not contain xml content
|
||||
"""
|
||||
|
||||
response_content = self._get_flavors_xml_response(
|
||||
accept='xml', content_type='xml')
|
||||
self.assertNotIn('xml version', response_content,
|
||||
self.flavors_client.default_headers['Accept'] = 'application/xml'
|
||||
self.flavors_client.default_headers['Content-Type'] = (
|
||||
'application/json')
|
||||
response = self.flavors_client.list_flavors()
|
||||
self.assertEqual(response.status_code, 200,
|
||||
'Unexpected status code returned. '
|
||||
'Expected: {0} Received: '
|
||||
'{1}'.format(200, response.status_code))
|
||||
self.assertNotIn('xml version', response,
|
||||
'Unexpected xml content was found in the response')
|
||||
|
||||
@tags(type='smoke', net='no')
|
||||
def test_get_request_content_type_xml_negative(self):
|
||||
"""
|
||||
A GET request passing only the content-type header as xml returns 400
|
||||
|
||||
Request a list of available flavors passing only the content-type
|
||||
header as xml and ensure that a bad request exception is returned.
|
||||
|
||||
The following assertions occur:
|
||||
- The response code is 400
|
||||
"""
|
||||
|
||||
self.flavors_client.default_headers['Accept'] = 'application/json'
|
||||
self.flavors_client.default_headers['Content-Type'] = 'application/xml'
|
||||
with self.assertRaises(BadRequest):
|
||||
self.flavors_client.list_flavors()
|
||||
|
||||
@tags(type='smoke', net='no')
|
||||
def test_get_request_accept_and_content_type_xml_negative(self):
|
||||
"""
|
||||
A GET request passing accept / content-type headers as xml returns 400
|
||||
|
||||
Request a list of available flavors passing both the accept and
|
||||
content-type headers as xml and ensure that a bad request exception is
|
||||
returned.
|
||||
|
||||
The following assertions occur:
|
||||
- The response code is 400
|
||||
"""
|
||||
|
||||
self.flavors_client.default_headers['Accept'] = 'application/xml'
|
||||
self.flavors_client.default_headers['Content-Type'] = 'application/xml'
|
||||
with self.assertRaises(BadRequest):
|
||||
self.flavors_client.list_flavors()
|
||||
|
||||
@tags(type='smoke', net='no')
|
||||
def test_post_request_accept_xml_ignored(self):
|
||||
"""
|
||||
|
@ -151,34 +158,3 @@ class XMLDeprecationTest(ComputeFixture):
|
|||
with self.assertRaises(BadRequest):
|
||||
self.servers_client.create_server(
|
||||
name, self.image_ref, self.flavor_ref)
|
||||
|
||||
def _get_flavors_xml_response(self, accept='json', content_type='json'):
|
||||
"""
|
||||
A GET request passing accept and content-type headers in given formats
|
||||
|
||||
Request a list of available flavors passing the accept and content-type
|
||||
headers in the given formats and ensure that a response code of 200 is
|
||||
returned.
|
||||
|
||||
The following assertions occur:
|
||||
- The response code is 200
|
||||
"""
|
||||
|
||||
if accept == 'xml':
|
||||
self.flavors_client.default_headers['Accept'] = 'application/xml'
|
||||
else:
|
||||
self.flavors_client.default_headers['Accept'] = 'application/json'
|
||||
if content_type == 'xml':
|
||||
self.flavors_client.default_headers['Content-Type'] = (
|
||||
'application/xml')
|
||||
else:
|
||||
self.flavors_client.default_headers['Content-Type'] = (
|
||||
'application/json')
|
||||
|
||||
response = self.flavors_client.list_flavors()
|
||||
self.assertEqual(response.status_code, 200,
|
||||
'Unexpected status code returned. '
|
||||
'Expected: {0} Received: '
|
||||
'{1}'.format(200, response.status_code))
|
||||
|
||||
return response.content
|
||||
|
|
Loading…
Reference in New Issue