Add V2.1 API tests parity with V2 API tests

There are some basic wsgi stack tests in test_api.py. But it is only
for V2 API. This patch adds V2.1 API tests on it.

Partial-Bug: #1462901
Change-Id: Ib0d9c15ca37a12c661a8abc8b8e59deab91f0d80
This commit is contained in:
He Jie Xu 2015-08-13 15:10:14 +08:00
parent 99ac112db8
commit f65ffa28ff
1 changed files with 18 additions and 3 deletions

View File

@ -28,6 +28,10 @@ from nova.tests.unit.api.openstack import fakes
class APITest(test.NoDBTestCase):
def setUp(self):
super(APITest, self).setUp()
self.wsgi_app = fakes.wsgi_app()
def _wsgi_app(self, inner_app):
# simpler version of the app than fakes.wsgi_app
return openstack_api.FaultWrapper(inner_app)
@ -38,7 +42,7 @@ class APITest(test.NoDBTestCase):
req.body = '{'
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
res = req.get_response(self.wsgi_app)
self.assertEqual(res.status_int, 400)
def test_malformed_xml(self):
@ -47,7 +51,7 @@ class APITest(test.NoDBTestCase):
req.body = '<hi im not xml>'
req.headers["content-type"] = "application/xml"
res = req.get_response(fakes.wsgi_app())
res = req.get_response(self.wsgi_app)
self.assertEqual(res.status_int, 400)
def test_vendor_content_type_json(self):
@ -56,7 +60,7 @@ class APITest(test.NoDBTestCase):
req = webob.Request.blank('/')
req.headers['Accept'] = ctype
res = req.get_response(fakes.wsgi_app())
res = req.get_response(self.wsgi_app)
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, ctype)
@ -161,3 +165,14 @@ class APITest(test.NoDBTestCase):
api = self._wsgi_app(fail)
resp = webob.Request.blank('/').get_response(api)
self.assertEqual(500, resp.status_int)
class APITestV21(APITest):
def setUp(self):
super(APITestV21, self).setUp()
self.wsgi_app = fakes.wsgi_app_v21()
# TODO(alex_xu): Get rid of the case translate NovaException to
# HTTPException after V2 api code removed. Because V2.1 API required raise
# HTTPException explicitly, so V2.1 API needn't such translation.