diff options
| author | Mark McLoughlin <markmc@redhat.com> | 2012-09-12 12:50:47 +0100 |
|---|---|---|
| committer | Mark McLoughlin <markmc@redhat.com> | 2012-09-13 16:10:07 +0100 |
| commit | e8d0f9940edd1043162c187ec92f93e8c9fafb02 (patch) | |
| tree | 21d3b5d89b6b0bba84e3da20a874b838740244f3 /nova | |
| parent | 511807ed248fbe63cb6642c1cff6e0bd4bb8ae5d (diff) | |
Add 422 test unit test for servers API
Add a straightforward test case to check the cases where we're returning
422 from the servers API.
Add a comment to ServersAllExtensionsTestCase which clarifies who it
differs from these new 422 tests.
Change-Id: Idb39e37f4a620199abb986793ae9415a5115dba9
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/tests/api/openstack/compute/test_servers.py | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index ae4d30cc1..fa811fd2c 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -900,13 +900,6 @@ class ServersControllerTest(test.TestCase): self.assertEqual(len(servers), 1) self.assertEqual(servers[0]['id'], server_uuid) - def test_update_server_no_body(self): - req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID) - req.method = 'PUT' - - self.assertRaises(webob.exc.HTTPUnprocessableEntity, - self.controller.update, req, FAKE_UUID, None) - def test_update_server_all_attributes(self): self.stubs.Set(nova.db, 'instance_get', fakes.fake_instance_get(name='server_test', @@ -4791,6 +4784,22 @@ class ServerXMLSerializationTest(test.TestCase): class ServersAllExtensionsTestCase(test.TestCase): """ Servers tests using default API router with all extensions enabled. + + The intent here is to catch cases where extensions end up throwing + an exception because of a malformed request before the core API + gets a chance to validate the request and return a 422 response. + + For example, ServerDiskConfigController extends servers.Controller: + + @wsgi.extends + def create(self, req, body): + if 'server' in body: + self._set_disk_config(body['server']) + resp_obj = (yield) + self._show(req, resp_obj) + + we want to ensure that the extension isn't barfing on an invalid + body. """ def setUp(self): @@ -4830,3 +4839,43 @@ class ServersAllExtensionsTestCase(test.TestCase): req.body = jsonutils.dumps(body) res = req.get_response(self.app) self.assertEqual(422, res.status_int) + + +class ServersUnprocessableEntityTestCase(test.TestCase): + """ + Tests of places we throw 422 Unprocessable Entity from + """ + + def setUp(self): + super(ServersUnprocessableEntityTestCase, self).setUp() + self.ext_mgr = extensions.ExtensionManager() + self.ext_mgr.extensions = {} + self.controller = servers.Controller(self.ext_mgr) + + def _unprocessable_server_create(self, body): + req = fakes.HTTPRequest.blank('/v2/fake/servers') + req.method = 'POST' + + self.assertRaises(webob.exc.HTTPUnprocessableEntity, + self.controller.create, req, body) + + def test_create_server_no_body(self): + self._unprocessable_server_create(body=None) + + def test_create_server_missing_server(self): + body = {'foo': {'a': 'b'}} + self._unprocessable_server_create(body=body) + + def _unprocessable_server_update(self, body): + req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID) + req.method = 'PUT' + + self.assertRaises(webob.exc.HTTPUnprocessableEntity, + self.controller.update, req, FAKE_UUID, body) + + def test_update_server_no_body(self): + self._unprocessable_server_update(body=None) + + def test_update_server_missing_server(self): + body = {'foo': {'a': 'b'}} + self._unprocessable_server_update(body=body) |
