From 50b437a836e57ec67576f986fea3409d914b4960 Mon Sep 17 00:00:00 2001 From: Adrian Smith Date: Sun, 15 Apr 2012 09:49:35 +0100 Subject: [PATCH] Fixed TestObjectController.test_PUT_auto_content_type() The test was failing silently. To catch these errors the response from controller.PUT() is now checked. Fixes to the TestObjectController.test_PUT_auto_content_type(): * Check for the correct 'Content-Type' header in the fake connect() method * Pass in the correct number of responses to fake_http_connect() * Pass a 'transfer-encoding' header to PUT() so that constraints.check_object_creation() passes * Pass the correct number of elements in the 'expected' iter to the test_content_type() method Change-Id: I8dced7b2f3c7e1b1d292c6995b1faf46f5e863fe --- test/unit/proxy/test_server.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 99a5015816..508be24ba5 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -228,8 +228,8 @@ def fake_http_connect(*code_iter, **kwargs): def connect(*args, **ckwargs): if 'give_content_type' in kwargs: - if len(args) >= 7 and 'content_type' in args[6]: - kwargs['give_content_type'](args[6]['content-type']) + if len(args) >= 7 and 'Content-Type' in args[6]: + kwargs['give_content_type'](args[6]['Content-Type']) else: kwargs['give_content_type']('') if 'give_connect' in kwargs: @@ -795,17 +795,26 @@ class TestObjectController(unittest.TestCase): 'container', 'object') def test_content_type(filename, expected): - proxy_server.http_connect = fake_http_connect(201, 201, 201, + # The three responses here are for account_info() (HEAD to account server), + # container_info() (HEAD to container server) and three calls to + # _connect_put_node() (PUT to three object servers) + proxy_server.http_connect = fake_http_connect(201, 201, 201, 201, 201, give_content_type=lambda content_type: self.assertEquals(content_type, expected.next())) - req = Request.blank('/a/c/%s' % filename, {}) + # We need into include a transfer-encoding to get past + # constraints.check_object_creation() + req = Request.blank('/a/c/%s' % filename, {}, headers={'transfer-encoding': 'chunked'}) self.app.update_request(req) + self.app.memcache.store = {} res = controller.PUT(req) - test_content_type('test.jpg', iter(['', '', '', 'image/jpeg', + # If we don't check the response here we could miss problems in PUT() + self.assertEquals(res.status_int, 201) + + test_content_type('test.jpg', iter(['', '', 'image/jpeg', 'image/jpeg', 'image/jpeg'])) - test_content_type('test.html', iter(['', '', '', 'text/html', + test_content_type('test.html', iter(['', '', 'text/html', 'text/html', 'text/html'])) - test_content_type('test.css', iter(['', '', '', 'text/css', + test_content_type('test.css', iter(['', '', 'text/css', 'text/css', 'text/css'])) def test_custom_mime_types_files(self):