From b70ab3381123ccaa689ce4a08ba4f144d74eeac3 Mon Sep 17 00:00:00 2001 From: kgriffs Date: Tue, 22 Apr 2014 17:37:47 -0500 Subject: [PATCH] fix(metadata): Fix inconsistent error response under v1.1 This patch modifies the v1.1 `on_put` responder to raise an instance of falcon.HTTPError, including setting the Allow header as required by RFC 2616. This ensures that the structured JSON response body is consistent with error bodies returned elsewhere in the API. A test was also added to cover the v1.1 implementation of `on_put`. Change-Id: I05e15cd3c676db8f9fc3fb7d1ba6fcd31613fc30 Partially-Implements: blueprint api-v1.1-remove-queue-metadata --- .../queues/transport/wsgi/v1_1/metadata.py | 16 ++++++++--- tests/unit/queues/transport/wsgi/test_v1_1.py | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/marconi/queues/transport/wsgi/v1_1/metadata.py b/marconi/queues/transport/wsgi/v1_1/metadata.py index 15407c30c..cc617f9d6 100644 --- a/marconi/queues/transport/wsgi/v1_1/metadata.py +++ b/marconi/queues/transport/wsgi/v1_1/metadata.py @@ -60,8 +60,16 @@ class Resource(object): u'project: %(project)s', {'queue': queue_name, 'project': project_id}) - resp.status = falcon.HTTP_405 resp.location = req.path - resp.body = ("Queue's metadata has been deprecated. " - "It will be removed completely in the next " - "version of the API.") + + description = ("Queue metadata has been deprecated. " + "It will be removed completely in the next " + "version of the API.") + + # TODO(kgriffs): There is a falcon bug that causes + # HTTPMethodNotAllowed to always ignore the kwargs, such + # as "description". Once that is fixed, we can use + # that class instead of the generic error. + raise falcon.HTTPError(falcon.HTTP_405, 'Method not allowed', + headers={'Allow': 'GET'}, + description=description) diff --git a/tests/unit/queues/transport/wsgi/test_v1_1.py b/tests/unit/queues/transport/wsgi/test_v1_1.py index ac49ce60b..d943a4ef6 100644 --- a/tests/unit/queues/transport/wsgi/test_v1_1.py +++ b/tests/unit/queues/transport/wsgi/test_v1_1.py @@ -159,3 +159,31 @@ class TestHealth(wsgi.TestBase): response = self.simulate_head('/v1.1/health') self.assertEqual(self.srmock.status, falcon.HTTP_204) self.assertEqual(response, []) + + +class TestDeprecated(wsgi.TestBase): + + config_file = 'wsgi_sqlalchemy.conf' + queue_path = '/v1.1/queues/test-queue' + + def setUp(self): + super(TestDeprecated, self).setUp() + + self.simulate_put(self.queue_path) + self.assertEqual(self.srmock.status, falcon.HTTP_201) + + def tearDown(self): + self.simulate_delete(self.queue_path) + self.assertEqual(self.srmock.status, falcon.HTTP_204) + + super(TestDeprecated, self).tearDown() + + def test_queue_metadata(self): + self.simulate_get(self.queue_path + '/metadata') + self.assertEqual(self.srmock.status, falcon.HTTP_200) + + # NOTE(kgriffs): Ensure that metadata created in v1.0 + # is read-only in v1.1. + self.simulate_put(self.queue_path + '/metadata') + self.assertEqual(self.srmock.status, falcon.HTTP_405) + self.assertEqual(self.srmock.headers_dict['Allow'], 'GET')