Changed exception handling mechanism
* The tests were use a context manager with assertException, but that was not catching the exception. Changed to a explicit try/except, and test fails and logs unexpected response if exception is not caught. Change-Id: Ia18a917d8e32bd83c734ad672d8007607c03382a
This commit is contained in:
parent
33f91ae6b7
commit
d87b6a3350
|
@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from cafe.drivers.unittest.decorators import tags
|
from cafe.drivers.unittest.decorators import tags
|
||||||
from cloudcafe.common.tools.datagen import rand_name
|
from cloudcafe.common.tools.datagen import rand_name
|
||||||
from cloudcafe.compute.common.exceptions import BadMediaType
|
from cloudcafe.compute.common.exceptions import BadMediaType
|
||||||
|
@ -58,13 +57,20 @@ class XMLDeprecationTest(ComputeFixture):
|
||||||
header as xml and ensure that a bad request exception is returned.
|
header as xml and ensure that a bad request exception is returned.
|
||||||
|
|
||||||
The following assertions occur:
|
The following assertions occur:
|
||||||
- The response code is 400
|
- The response code is 415
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.flavors_client.default_headers['Accept'] = 'application/json'
|
self.flavors_client.default_headers['Accept'] = 'application/json'
|
||||||
self.flavors_client.default_headers['Content-Type'] = 'application/xml'
|
self.flavors_client.default_headers['Content-Type'] = 'application/xml'
|
||||||
with self.assertRaises(BadMediaType):
|
try:
|
||||||
self.flavors_client.list_flavors()
|
self.flavors_client.list_flavors()
|
||||||
|
except BadMediaType:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.assertFalse(
|
||||||
|
True,
|
||||||
|
"Did not receive expected response: '{0}'".format(
|
||||||
|
BadMediaType().message))
|
||||||
|
|
||||||
@tags(type='smoke', net='no')
|
@tags(type='smoke', net='no')
|
||||||
def test_get_request_accept_and_content_type_xml_negative(self):
|
def test_get_request_accept_and_content_type_xml_negative(self):
|
||||||
|
@ -76,13 +82,20 @@ class XMLDeprecationTest(ComputeFixture):
|
||||||
returned.
|
returned.
|
||||||
|
|
||||||
The following assertions occur:
|
The following assertions occur:
|
||||||
- The response code is 400
|
- The response code is 415
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.flavors_client.default_headers['Accept'] = 'application/xml'
|
self.flavors_client.default_headers['Accept'] = 'application/xml'
|
||||||
self.flavors_client.default_headers['Content-Type'] = 'application/xml'
|
self.flavors_client.default_headers['Content-Type'] = 'application/xml'
|
||||||
with self.assertRaises(BadMediaType):
|
try:
|
||||||
self.flavors_client.list_flavors()
|
self.flavors_client.list_flavors()
|
||||||
|
except BadMediaType:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.assertFalse(
|
||||||
|
True,
|
||||||
|
"Did not receive expected response: '{0}'".format(
|
||||||
|
BadMediaType().message))
|
||||||
|
|
||||||
@tags(type='smoke', net='no')
|
@tags(type='smoke', net='no')
|
||||||
def test_post_request_accept_xml_ignored(self):
|
def test_post_request_accept_xml_ignored(self):
|
||||||
|
@ -130,15 +143,22 @@ class XMLDeprecationTest(ComputeFixture):
|
||||||
xml and ensure that a bad request exception is returned.
|
xml and ensure that a bad request exception is returned.
|
||||||
|
|
||||||
The following assertions occur:
|
The following assertions occur:
|
||||||
- The response code is 400
|
- The response code is 415
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = rand_name('testserver')
|
name = rand_name('testserver')
|
||||||
self.servers_client.default_headers['Accept'] = 'application/json'
|
self.servers_client.default_headers['Accept'] = 'application/json'
|
||||||
self.servers_client.default_headers['Content-Type'] = 'application/xml'
|
self.servers_client.default_headers['Content-Type'] = 'application/xml'
|
||||||
with self.assertRaises(BadMediaType):
|
try:
|
||||||
self.servers_client.create_server(
|
self.servers_client.create_server(
|
||||||
name, self.image_ref, self.flavor_ref)
|
name, self.image_ref, self.flavor_ref)
|
||||||
|
except BadMediaType:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.assertFalse(
|
||||||
|
True,
|
||||||
|
"Did not receive expected response: '{0}'".format(
|
||||||
|
BadMediaType().message))
|
||||||
|
|
||||||
@tags(type='smoke', net='no')
|
@tags(type='smoke', net='no')
|
||||||
def test_post_request_accept_and_content_type_xml_negative(self):
|
def test_post_request_accept_and_content_type_xml_negative(self):
|
||||||
|
@ -149,12 +169,19 @@ class XMLDeprecationTest(ComputeFixture):
|
||||||
headers as xml and ensure that a bad request exception is returned.
|
headers as xml and ensure that a bad request exception is returned.
|
||||||
|
|
||||||
The following assertions occur:
|
The following assertions occur:
|
||||||
- The response code is 400
|
- The response code is 415
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = rand_name('testserver')
|
name = rand_name('testserver')
|
||||||
self.servers_client.default_headers['Accept'] = 'application/xml'
|
self.servers_client.default_headers['Accept'] = 'application/xml'
|
||||||
self.servers_client.default_headers['Content-Type'] = 'application/xml'
|
self.servers_client.default_headers['Content-Type'] = 'application/xml'
|
||||||
with self.assertRaises(BadMediaType):
|
try:
|
||||||
self.servers_client.create_server(
|
self.servers_client.create_server(
|
||||||
name, self.image_ref, self.flavor_ref)
|
name, self.image_ref, self.flavor_ref)
|
||||||
|
except BadMediaType:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.assertFalse(
|
||||||
|
True,
|
||||||
|
"Did not receive expected response: '{0}'".format(
|
||||||
|
BadMediaType().message))
|
||||||
|
|
Loading…
Reference in New Issue