From bcec1f4a7ec92e48c4230e6d0a2a608243aef19f Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Fri, 13 Jan 2017 14:44:04 +0000 Subject: [PATCH] Fix object server tests to include content-type headers In [1] it was necessary to override the monkey patching of mimetools so that mimetools would apply a default Content-Type=text/plain header when missing from object server requests. Otherwise some tests fail due to Content-Type=None. This patch fixes the fragile tests by adding a Content-Type header, and thus removes the need to override the mimetool monkey patching. This is closer to the real world in which mimetools is patched in the object server and PUT requests should have a Content-Type. Drive-by fix some typos and apply config assertions to all policies. [1] Related-Change: I5b5f90bb898a335e6336f043710a05a44e3b810f Change-Id: I4c5bca42f753be4165cb731b8e3957eb4cdd28d5 --- test/unit/obj/test_server.py | 43 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index f54af59f17..d0902f0d8f 100644 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -6204,7 +6204,7 @@ class TestObjectController(unittest.TestCase): suffix = pickle.loads(resp.body).keys()[0] self.assertEqual(suffix, os.path.basename( os.path.dirname(objfile._datadir))) - # tombsone still exists + # tombstone still exists self.assertTrue(os.path.exists(tombstone_file)) # after reclaim REPLICATE will rehash @@ -6219,7 +6219,7 @@ class TestObjectController(unittest.TestCase): resp = replicate_request.get_response(self.object_controller) self.assertEqual(resp.status_int, 200) self.assertEqual({}, pickle.loads(resp.body)) - # and tombsone is reaped! + # and tombstone is reaped! self.assertFalse(os.path.exists(tombstone_file)) # N.B. with a small reclaim age like this - if proxy clocks get far @@ -6859,6 +6859,7 @@ class TestObjectServer(unittest.TestCase): headers = { 'Expect': '100-continue', 'Content-Length': len(test_body), + 'Content-Type': 'application/test', 'X-Timestamp': utils.Timestamp(time()).internal, } conn = bufferedhttp.http_connect('127.0.0.1', self.port, 'sda1', '0', @@ -6876,6 +6877,7 @@ class TestObjectServer(unittest.TestCase): headers = { 'Expect': '100-continue', 'Content-Length': len(test_body), + 'Content-Type': 'application/test', 'X-Timestamp': utils.Timestamp(time()).internal, 'X-Backend-Obj-Metadata-Footer': 'yes', 'X-Backend-Obj-Multipart-Mime-Boundary': 'boundary123', @@ -6894,6 +6896,7 @@ class TestObjectServer(unittest.TestCase): headers = { 'Expect': '100-continue', 'Content-Length': len(test_body), + 'Content-Type': 'application/test', 'X-Timestamp': put_timestamp.internal, } conn = bufferedhttp.http_connect('127.0.0.1', self.port, 'sda1', '0', @@ -7526,7 +7529,8 @@ class TestZeroCopy(unittest.TestCase): url_path = '/sda1/2100/a/c/o' self.http_conn.request('PUT', url_path, 'obj contents', - {'X-Timestamp': '127082564.24709'}) + {'X-Timestamp': '127082564.24709', + 'Content-Type': 'application/test'}) response = self.http_conn.getresponse() self.assertEqual(response.status, 201) response.read() @@ -7544,7 +7548,8 @@ class TestZeroCopy(unittest.TestCase): url_path = '/sda1/2100/a/c/o' self.http_conn.request('PUT', url_path, obj_contents, - {'X-Timestamp': '1402600322.52126'}) + {'X-Timestamp': '1402600322.52126', + 'Content-Type': 'application/test'}) response = self.http_conn.getresponse() self.assertEqual(response.status, 201) response.read() @@ -7561,7 +7566,8 @@ class TestZeroCopy(unittest.TestCase): ts = '1402601849.47475' self.http_conn.request('PUT', url_path, 'obj contents', - {'X-Timestamp': ts}) + {'X-Timestamp': ts, + 'Content-Type': 'application/test'}) response = self.http_conn.getresponse() self.assertEqual(response.status, 201) response.read() @@ -7592,7 +7598,8 @@ class TestZeroCopy(unittest.TestCase): self.http_conn.request( 'PUT', url_path, '', - {'X-Timestamp': ts, 'Content-Length': '0'}) + {'X-Timestamp': ts, 'Content-Length': '0', + 'Content-Type': 'application/test'}) response = self.http_conn.getresponse() self.assertEqual(response.status, 201) response.read() @@ -7623,9 +7630,7 @@ class TestConfigOptionHandling(unittest.TestCase): conf_file = os.path.join(self.tmpdir, 'object-server.conf') with open(conf_file, 'w') as f: f.write(contents) - with mock.patch('swift.common.wsgi.monkey_patch_mimetools'): - app = init_request_processor(conf_file, 'object-server')[:2] - return app + return init_request_processor(conf_file, 'object-server')[:2] def test_default(self): config = """ @@ -7639,8 +7644,8 @@ class TestConfigOptionHandling(unittest.TestCase): """ app, config = self._app_config(config) self.assertNotIn('reclaim_age', config) - self.assertEqual(app._diskfile_router[POLICIES.legacy].reclaim_age, - 604800) + for policy in POLICIES: + self.assertEqual(app._diskfile_router[policy].reclaim_age, 604800) def test_option_in_app(self): config = """ @@ -7655,8 +7660,8 @@ class TestConfigOptionHandling(unittest.TestCase): """ app, config = self._app_config(config) self.assertEqual(config['reclaim_age'], '100') - self.assertEqual(app._diskfile_router[POLICIES.legacy].reclaim_age, - 100) + for policy in POLICIES: + self.assertEqual(app._diskfile_router[policy].reclaim_age, 100) def test_option_in_default(self): config = """ @@ -7671,8 +7676,8 @@ class TestConfigOptionHandling(unittest.TestCase): """ app, config = self._app_config(config) self.assertEqual(config['reclaim_age'], '200') - self.assertEqual(app._diskfile_router[POLICIES.legacy].reclaim_age, - 200) + for policy in POLICIES: + self.assertEqual(app._diskfile_router[policy].reclaim_age, 200) def test_option_in_both(self): config = """ @@ -7688,8 +7693,8 @@ class TestConfigOptionHandling(unittest.TestCase): """ app, config = self._app_config(config) self.assertEqual(config['reclaim_age'], '300') - self.assertEqual(app._diskfile_router[POLICIES.legacy].reclaim_age, - 300) + for policy in POLICIES: + self.assertEqual(app._diskfile_router[policy].reclaim_age, 300) # use paste "set" syntax to override global config value config = """ @@ -7705,8 +7710,8 @@ class TestConfigOptionHandling(unittest.TestCase): """ app, config = self._app_config(config) self.assertEqual(config['reclaim_age'], '600') - self.assertEqual(app._diskfile_router[POLICIES.legacy].reclaim_age, - 600) + for policy in POLICIES: + self.assertEqual(app._diskfile_router[policy].reclaim_age, 600) if __name__ == '__main__':