Fixes for v3 API servers tests

Fixes some v3 API servers unittests to correctly use the
fake v3 wsgi_app rather than the v2 one. Also fixes
xml in test_update_server_invalid_xml_raises_lookup so
that it will only cause a LookupError rather than a LookupError
and an ExpatError as the latter will mask the failure of the former
to be raised.

Also adds checking of the actual error message returned for the two
unittests affected.

partially implements blueprint v3-api-unittests

Change-Id: I2abf8875e2cc3feda14f93d8c1e7a88c5a278ca8
This commit is contained in:
Chris Yeoh
2013-07-23 11:57:55 +09:30
parent fd7f885271
commit 80d355a7e3
@@ -1090,19 +1090,22 @@ class ServersControllerTest(ControllerTest):
self.assertEqual(res_dict['server']['accessIPv6'], 'beef::123')
def test_update_server_invalid_xml_raises_lookup(self):
req = fakes.HTTPRequestV3.blank('/servers/%s' % FAKE_UUID)
req = webob.Request.blank('/v3/servers/%s' % FAKE_UUID)
req.method = 'PUT'
req.content_type = 'application/xml'
#xml request which raises LookupError
req.body = """<?xml version="1.0" encoding="TF-8"?>
<metadata
xmlns="http://docs.openstack.org/compute/api/v1.1"
key="Label"></meta>"""
res = req.get_response(fakes.wsgi_app())
key="Label"></metadata>"""
res = req.get_response(fakes.wsgi_app_v3())
self.assertEqual(res.status_int, 400)
res_dict = jsonutils.loads(res.body)
self.assertEqual(res_dict['badRequest']['message'],
"Malformed request body")
def test_update_server_invalid_xml_raises_expat(self):
req = fakes.HTTPRequestV3.blank('/servers/%s' % FAKE_UUID)
req = webob.Request.blank('/v3/servers/%s' % FAKE_UUID)
req.method = 'PUT'
req.content_type = 'application/xml'
#xml request which raises ExpatError
@@ -1110,8 +1113,11 @@ class ServersControllerTest(ControllerTest):
<metadata
xmlns="http://docs.openstack.org/compute/api/v1.1"
key="Label"></meta>"""
res = req.get_response(fakes.wsgi_app())
res = req.get_response(fakes.wsgi_app_v3())
self.assertEqual(res.status_int, 400)
res_dict = jsonutils.loads(res.body)
self.assertEqual(res_dict['badRequest']['message'],
"Malformed request body")
def test_update_server_name(self):
self.stubs.Set(db, 'instance_get',