From a4a5494fd2fe8a43a5d50a21a1951266cc7c4212 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Mon, 9 Oct 2017 11:33:28 +0100 Subject: [PATCH] test account autocreate listing format Related-Change: Id3ce37aa0402e2d8dd5784ce329d7cb4fbaf700d Change-Id: I50c22225bbebff71600bea9158bda1edd18b48b0 --- test/unit/proxy/test_server.py | 37 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 12e96c8c9f..5c84293409 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -7636,8 +7636,7 @@ class TestContainerController(unittest.TestCase): # return 404 (as account is not found) and don't cache container test_status_map((404, 404, 404), 404, None, 404) - # cache a 204 for the account because it's sort of like it - # exists + # cache a 200 for the account because it appears to be created self.app.account_autocreate = True test_status_map((404, 404, 404), 404, None, 200) @@ -8809,15 +8808,39 @@ class TestAccountController(unittest.TestCase): # ALL nodes are asked to create the account # If successful, the GET request is repeated. controller.app.account_autocreate = True - self.assert_status_map(controller.GET, - (404, 404, 404), 200) - self.assert_status_map(controller.GET, - (404, 503, 404), 200) - + expected = 200 + self.assert_status_map(controller.GET, (404, 404, 404), expected) + self.assert_status_map(controller.GET, (404, 503, 404), expected) # We always return 503 if no majority between 4xx, 3xx or 2xx found self.assert_status_map(controller.GET, (500, 500, 400), 503) + def _check_autocreate_listing_with_query_string(self, query_string): + controller = proxy_server.AccountController(self.app, 'a') + controller.app.account_autocreate = True + statuses = (404, 404, 404) + expected = 200 + # get the response to check it has json content + with save_globals(): + set_http_connect(*statuses) + req = Request.blank('/v1/a' + query_string) + self.app.update_request(req) + res = controller.GET(req) + headers = res.headers + self.assertEqual( + 'yes', headers.get('X-Backend-Fake-Account-Listing')) + self.assertEqual( + 'application/json; charset=utf-8', + headers.get('Content-Type')) + self.assertEqual([], json.loads(res.body)) + self.assertEqual(res.status_int, expected) + + def test_auto_create_account_listing_response_is_json(self): + self._check_autocreate_listing_with_query_string('') + self._check_autocreate_listing_with_query_string('?format=plain') + self._check_autocreate_listing_with_query_string('?format=json') + self._check_autocreate_listing_with_query_string('?format=xml') + def test_HEAD(self): # Same behaviour as GET with save_globals():