From 80709fd9a488d83563ed5c5354cca6628c08445a Mon Sep 17 00:00:00 2001 From: Morgan Fainberg Date: Wed, 15 Feb 2017 13:20:09 -0800 Subject: [PATCH] Convert test_object to use .register_uris Convert test_object tests to use .register_uris. .register_uri is no longer used and deleted. Change-Id: Iee156afd5ee5931ca4087a70dd92bb3b0df2f62d --- shade/tests/unit/base.py | 4 - shade/tests/unit/test_object.py | 997 ++++++++++++++++---------------- 2 files changed, 489 insertions(+), 512 deletions(-) diff --git a/shade/tests/unit/base.py b/shade/tests/unit/base.py index 1e5fd53de..242e44ef6 100644 --- a/shade/tests/unit/base.py +++ b/shade/tests/unit/base.py @@ -425,10 +425,6 @@ class RequestsMockTestCase(BaseTestCase): mock_method, mock_uri, params['response_list'], **params['kw_params']) - def register_uri(self, method, uri, **kwargs): - self.__do_register_uris([ - dict(method=method, uri=uri, **kwargs)]) - def assert_calls(self, stop_after=None): for (x, (call, history)) in enumerate( zip(self.calls, self.adapter.request_history)): diff --git a/shade/tests/unit/test_object.py b/shade/tests/unit/test_object.py index 3e1117e51..54fb65b6e 100644 --- a/shade/tests/unit/test_object.py +++ b/shade/tests/unit/test_object.py @@ -40,87 +40,81 @@ class TestObject(BaseTestObject): def test_create_container(self): """Test creating a (private) container""" - self.register_uri( - 'HEAD', self.container_endpoint, status_code=404), - - self.register_uri( - 'PUT', self.container_endpoint, - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }) - - self.register_uri( - 'HEAD', self.container_endpoint, - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}) + self.register_uris([ + dict(method='HEAD', uri=self.container_endpoint, status_code=404), + dict(method='PUT', uri=self.container_endpoint, + status_code=201, + headers={ + 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', + 'Content-Length': '0', + 'Content-Type': 'text/html; charset=UTF-8', + }), + dict(method='HEAD', uri=self.container_endpoint, + headers={ + 'Content-Length': '0', + 'X-Container-Object-Count': '0', + 'Accept-Ranges': 'bytes', + 'X-Storage-Policy': 'Policy-0', + 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', + 'X-Timestamp': '1481912480.41664', + 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', + 'X-Container-Bytes-Used': '0', + 'Content-Type': 'text/plain; charset=utf-8'}) + ]) self.cloud.create_container(self.container) self.assert_calls() def test_create_container_public(self): """Test creating a public container""" - self.register_uri( - 'HEAD', self.container_endpoint, - status_code=404) - - self.register_uri( - 'PUT', self.container_endpoint, - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }) - - self.register_uri( - 'POST', self.container_endpoint, - status_code=201, - validate=dict( - headers={ - 'x-container-read': - shade.openstackcloud.OBJECT_CONTAINER_ACLS['public']})) - - self.register_uri( - 'HEAD', self.container_endpoint, - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}) + self.register_uris([ + dict(method='HEAD', uri=self.container_endpoint, + status_code=404), + dict(method='PUT', uri=self.container_endpoint, + status_code=201, + headers={ + 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', + 'Content-Length': '0', + 'Content-Type': 'text/html; charset=UTF-8', + }), + dict(method='POST', uri=self.container_endpoint, + status_code=201, + validate=dict( + headers={ + 'x-container-read': + shade.openstackcloud.OBJECT_CONTAINER_ACLS[ + 'public']})), + dict(method='HEAD', uri=self.container_endpoint, + headers={ + 'Content-Length': '0', + 'X-Container-Object-Count': '0', + 'Accept-Ranges': 'bytes', + 'X-Storage-Policy': 'Policy-0', + 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', + 'X-Timestamp': '1481912480.41664', + 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', + 'X-Container-Bytes-Used': '0', + 'Content-Type': 'text/plain; charset=utf-8'}) + ]) self.cloud.create_container(self.container, public=True) self.assert_calls() def test_create_container_exists(self): """Test creating a container that exists.""" - self.register_uri( - 'HEAD', self.container_endpoint, - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}) + self.register_uris([ + dict(method='HEAD', uri=self.container_endpoint, + headers={ + 'Content-Length': '0', + 'X-Container-Object-Count': '0', + 'Accept-Ranges': 'bytes', + 'X-Storage-Policy': 'Policy-0', + 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', + 'X-Timestamp': '1481912480.41664', + 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', + 'X-Container-Bytes-Used': '0', + 'Content-Type': 'text/plain; charset=utf-8'}) + ]) container = self.cloud.create_container(self.container) @@ -128,16 +122,17 @@ class TestObject(BaseTestObject): self.assertIsNotNone(container) def test_delete_container(self): - self.register_uri('DELETE', self.container_endpoint) + self.register_uris([ + dict(method='DELETE', uri=self.container_endpoint)]) self.assertTrue(self.cloud.delete_container(self.container)) self.assert_calls() def test_delete_container_404(self): """No exception when deleting a container that does not exist""" - self.register_uri( - 'DELETE', self.container_endpoint, - status_code=404) + self.register_uris([ + dict(method='DELETE', uri=self.container_endpoint, + status_code=404)]) self.assertFalse(self.cloud.delete_container(self.container)) self.assert_calls() @@ -145,9 +140,9 @@ class TestObject(BaseTestObject): def test_delete_container_error(self): """Non-404 swift error re-raised as OSCE""" # 409 happens if the container is not empty - self.register_uri( - 'DELETE', self.container_endpoint, - status_code=409) + self.register_uris([ + dict(method='DELETE', uri=self.container_endpoint, + status_code=409)]) self.assertRaises( shade.OpenStackCloudException, self.cloud.delete_container, self.container) @@ -157,10 +152,10 @@ class TestObject(BaseTestObject): headers = { 'x-container-read': shade.openstackcloud.OBJECT_CONTAINER_ACLS['public']} - self.register_uri( - 'POST', self.container_endpoint, - status_code=204, - validate=dict(headers=headers)) + self.register_uris([ + dict(method='POST', uri=self.container_endpoint, + status_code=204, + validate=dict(headers=headers))]) self.cloud.update_container(self.container, headers) self.assert_calls() @@ -172,35 +167,37 @@ class TestObject(BaseTestObject): # method, and I cannot make a synthetic failure to validate a real # error code. So we're really just testing the shade adapter error # raising logic here, rather than anything specific to swift. - self.register_uri( - 'POST', self.container_endpoint, - status_code=409) + self.register_uris([ + dict(method='POST', uri=self.container_endpoint, + status_code=409)]) self.assertRaises( shade.OpenStackCloudException, self.cloud.update_container, self.container, dict(foo='bar')) self.assert_calls() def test_set_container_access_public(self): - self.register_uri( - 'POST', self.container_endpoint, - status_code=204, - validate=dict( - headers={ - 'x-container-read': - shade.openstackcloud.OBJECT_CONTAINER_ACLS['public']})) + self.register_uris([ + dict(method='POST', uri=self.container_endpoint, + status_code=204, + validate=dict( + headers={ + 'x-container-read': + shade.openstackcloud.OBJECT_CONTAINER_ACLS[ + 'public']}))]) self.cloud.set_container_access(self.container, 'public') self.assert_calls() def test_set_container_access_private(self): - self.register_uri( - 'POST', self.container_endpoint, - status_code=204, - validate=dict( - headers={ - 'x-container-read': - shade.openstackcloud.OBJECT_CONTAINER_ACLS['private']})) + self.register_uris([ + dict(method='POST', uri=self.container_endpoint, + status_code=204, + validate=dict( + headers={ + 'x-container-read': + shade.openstackcloud.OBJECT_CONTAINER_ACLS[ + 'private']}))]) self.cloud.set_container_access(self.container, 'private') @@ -212,20 +209,19 @@ class TestObject(BaseTestObject): self.cloud.set_container_access, self.container, 'invalid') def test_get_container_access(self): - self.register_uri( - 'HEAD', self.container_endpoint, - headers={ - 'x-container-read': - str(shade.openstackcloud.OBJECT_CONTAINER_ACLS['public'])}) - + self.register_uris([ + dict(method='HEAD', uri=self.container_endpoint, + headers={ + 'x-container-read': + str(shade.openstackcloud.OBJECT_CONTAINER_ACLS[ + 'public'])})]) access = self.cloud.get_container_access(self.container) self.assertEqual('public', access) def test_get_container_invalid(self): - self.register_uri( - 'HEAD', self.container_endpoint, - headers={ - 'x-container-read': 'invalid'}) + self.register_uris([ + dict(method='HEAD', uri=self.container_endpoint, + headers={'x-container-read': 'invalid'})]) with testtools.ExpectedException( exc.OpenStackCloudException, @@ -234,9 +230,9 @@ class TestObject(BaseTestObject): self.cloud.get_container_access(self.container) def test_get_container_access_not_found(self): - self.register_uri( - 'HEAD', self.container_endpoint, - status_code=404) + self.register_uris([ + dict(method='HEAD', uri=self.container_endpoint, + status_code=404)]) with testtools.ExpectedException( exc.OpenStackCloudException, "Container not found: %s" % self.container @@ -249,7 +245,8 @@ class TestObject(BaseTestObject): containers = [ {u'count': 0, u'bytes': 0, u'name': self.container}] - self.register_uri('GET', endpoint, complete_qs=True, json=containers) + self.register_uris([dict(method='GET', uri=endpoint, complete_qs=True, + json=containers)]) ret = self.cloud.list_containers() @@ -259,7 +256,8 @@ class TestObject(BaseTestObject): def test_list_containers_exception(self): endpoint = '{endpoint}/?format=json'.format( endpoint=self.endpoint) - self.register_uri('GET', endpoint, complete_qs=True, status_code=416) + self.register_uris([dict(method='GET', uri=endpoint, complete_qs=True, + status_code=416)]) self.assertRaises( exc.OpenStackCloudException, self.cloud.list_containers) @@ -276,7 +274,8 @@ class TestObject(BaseTestObject): u'name': self.object, u'content_type': u'application/octet-stream'}] - self.register_uri('GET', endpoint, complete_qs=True, json=objects) + self.register_uris([dict(method='GET', uri=endpoint, complete_qs=True, + json=objects)]) ret = self.cloud.list_objects(self.container) @@ -286,24 +285,26 @@ class TestObject(BaseTestObject): def test_list_objects_exception(self): endpoint = '{endpoint}?format=json'.format( endpoint=self.container_endpoint) - self.register_uri('GET', endpoint, complete_qs=True, status_code=416) + self.register_uris([dict(method='GET', uri=endpoint, complete_qs=True, + status_code=416)]) self.assertRaises( exc.OpenStackCloudException, self.cloud.list_objects, self.container) self.assert_calls() def test_delete_object(self): - self.register_uri( - 'HEAD', self.object_endpoint, - headers={'X-Object-Meta': 'foo'}) - self.register_uri('DELETE', self.object_endpoint, status_code=204) + self.register_uris([ + dict(method='HEAD', uri=self.object_endpoint, + headers={'X-Object-Meta': 'foo'}), + dict(method='DELETE', uri=self.object_endpoint, status_code=204)]) self.assertTrue(self.cloud.delete_object(self.container, self.object)) self.assert_calls() def test_delete_object_not_found(self): - self.register_uri('HEAD', self.object_endpoint, status_code=404) + self.register_uris([dict(method='HEAD', uri=self.object_endpoint, + status_code=404)]) self.assertFalse(self.cloud.delete_object(self.container, self.object)) @@ -324,21 +325,21 @@ class TestObject(BaseTestObject): } response_headers = {k.lower(): v for k, v in headers.items()} text = 'test body' - self.register_uri( - 'GET', self.object_endpoint, - headers={ - 'Content-Length': '20304400896', - 'Content-Type': 'application/octet-stream', - 'Accept-Ranges': 'bytes', - 'Last-Modified': 'Thu, 15 Dec 2016 13:34:14 GMT', - 'Etag': '"b5c454b44fbd5344793e3fb7e3850768"', - 'X-Timestamp': '1481808853.65009', - 'X-Trans-Id': 'tx68c2a2278f0c469bb6de1-005857ed80dfw1', - 'Date': 'Mon, 19 Dec 2016 14:24:00 GMT', - 'X-Static-Large-Object': 'True', - 'X-Object-Meta-Mtime': '1481513709.168512', - }, - text='test body') + self.register_uris([ + dict(method='GET', uri=self.object_endpoint, + headers={ + 'Content-Length': '20304400896', + 'Content-Type': 'application/octet-stream', + 'Accept-Ranges': 'bytes', + 'Last-Modified': 'Thu, 15 Dec 2016 13:34:14 GMT', + 'Etag': '"b5c454b44fbd5344793e3fb7e3850768"', + 'X-Timestamp': '1481808853.65009', + 'X-Trans-Id': 'tx68c2a2278f0c469bb6de1-005857ed80dfw1', + 'Date': 'Mon, 19 Dec 2016 14:24:00 GMT', + 'X-Static-Large-Object': 'True', + 'X-Object-Meta-Mtime': '1481513709.168512', + }, + text='test body')]) resp = self.cloud.get_object(self.container, self.object) @@ -347,14 +348,16 @@ class TestObject(BaseTestObject): self.assertEqual((response_headers, text), resp) def test_get_object_not_found(self): - self.register_uri('GET', self.object_endpoint, status_code=404) + self.register_uris([dict(method='GET', + uri=self.object_endpoint, status_code=404)]) self.assertIsNone(self.cloud.get_object(self.container, self.object)) self.assert_calls() def test_get_object_exception(self): - self.register_uri('GET', self.object_endpoint, status_code=416) + self.register_uris([dict(method='GET', uri=self.object_endpoint, + status_code=416)]) self.assertRaises( shade.OpenStackCloudException, @@ -367,31 +370,29 @@ class TestObject(BaseTestObject): # Register directly becuase we make multiple calls. The number # of calls we make isn't interesting - what we do with the return # values is. Don't run assert_calls for the same reason. - self.adapter.register_uri( - 'GET', 'https://object-store.example.com/info', - json=dict( - swift={'max_file_size': 1000}, - slo={'min_segment_size': 500}), - headers={'Content-Type': 'application/json'}) + self.register_uris([ + dict(method='GET', uri='https://object-store.example.com/info', + json=dict( + swift={'max_file_size': 1000}, + slo={'min_segment_size': 500}), + headers={'Content-Type': 'application/json'})]) self.assertEqual(500, self.cloud.get_object_segment_size(400)) self.assertEqual(900, self.cloud.get_object_segment_size(900)) self.assertEqual(1000, self.cloud.get_object_segment_size(1000)) self.assertEqual(1000, self.cloud.get_object_segment_size(1100)) def test_get_object_segment_size_http_404(self): - self.register_uri( - 'GET', 'https://object-store.example.com/info', - status_code=404, - reason='Not Found') + self.register_uris([ + dict(method='GET', uri='https://object-store.example.com/info', + status_code=404, reason='Not Found')]) self.assertEqual(shade.openstackcloud.DEFAULT_OBJECT_SEGMENT_SIZE, self.cloud.get_object_segment_size(None)) self.assert_calls() def test_get_object_segment_size_http_412(self): - self.register_uri( - 'GET', 'https://object-store.example.com/info', - status_code=412, - reason='Precondition failed') + self.register_uris([ + dict(method='GET', uri='https://object-store.example.com/info', + status_code=412, reason='Precondition failed')]) self.assertEqual(shade.openstackcloud.DEFAULT_OBJECT_SEGMENT_SIZE, self.cloud.get_object_segment_size(None)) self.assert_calls() @@ -412,59 +413,55 @@ class TestObjectUploads(BaseTestObject): def test_create_object(self): - self.register_uri( - 'GET', 'https://object-store.example.com/info', - json=dict( - swift={'max_file_size': 1000}, - slo={'min_segment_size': 500})) - - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404) - - self.register_uri( - 'PUT', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }) - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}) - - self.register_uri( - 'HEAD', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=404) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=201, - validate=dict( - headers={ - 'x-object-meta-x-shade-md5': self.md5, - 'x-object-meta-x-shade-sha256': self.sha256, - })) + self.register_uris([ + dict(method='GET', + uri='https://object-store.example.com/info', + json=dict( + swift={'max_file_size': 1000}, + slo={'min_segment_size': 500})), + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container), + status_code=404), + dict(method='PUT', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, container=self.container), + status_code=201, + headers={ + 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', + 'Content-Length': '0', + 'Content-Type': 'text/html; charset=UTF-8', + }), + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, container=self.container), + headers={ + 'Content-Length': '0', + 'X-Container-Object-Count': '0', + 'Accept-Ranges': 'bytes', + 'X-Storage-Policy': 'Policy-0', + 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', + 'X-Timestamp': '1481912480.41664', + 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', + 'X-Container-Bytes-Used': '0', + 'Content-Type': 'text/plain; charset=utf-8'}), + dict(method='HEAD', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, container=self.container, + object=self.object), + status_code=404), + dict(method='PUT', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, + container=self.container, object=self.object), + status_code=201, + validate=dict( + headers={ + 'x-object-meta-x-shade-md5': self.md5, + 'x-object-meta-x-shade-sha256': self.sha256, + })) + ]) self.cloud.create_object( container=self.container, name=self.object, @@ -477,74 +474,75 @@ class TestObjectUploads(BaseTestObject): max_file_size = 2 min_file_size = 1 - self.register_uri( - 'GET', 'https://object-store.example.com/info', - json=dict( - swift={'max_file_size': max_file_size}, - slo={'min_segment_size': min_file_size})) + uris_to_mock = [ + dict(method='GET', + uri='https://object-store.example.com/info', + json=dict( + swift={'max_file_size': max_file_size}, + slo={'min_segment_size': min_file_size})), - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404) + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container), + status_code=404), + dict(method='PUT', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container, ), + status_code=201, + headers={ + 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', + 'Content-Length': '0', + 'Content-Type': 'text/html; charset=UTF-8', + }), + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container), + headers={ + 'Content-Length': '0', + 'X-Container-Object-Count': '0', + 'Accept-Ranges': 'bytes', + 'X-Storage-Policy': 'Policy-0', + 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', + 'X-Timestamp': '1481912480.41664', + 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', + 'X-Container-Bytes-Used': '0', + 'Content-Type': 'text/plain; charset=utf-8'}), + dict(method='HEAD', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, container=self.container, + object=self.object), + status_code=404) + ] - self.register_uri( - 'PUT', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container,), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }) - - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}) - - self.register_uri( - 'HEAD', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=404) - - for index, offset in enumerate( - range(0, len(self.content), max_file_size)): - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/{index:0>6}'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object, - index=index), - status_code=201) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=201, - validate=dict( - headers={ - 'x-object-manifest': '{container}/{object}'.format( - container=self.container, object=self.object), - 'x-object-meta-x-shade-md5': self.md5, - 'x-object-meta-x-shade-sha256': self.sha256, - })) + uris_to_mock.extend( + [dict(method='PUT', + uri='{endpoint}/{container}/{object}/{index:0>6}'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object, + index=index), + status_code=201) + for index, offset in enumerate( + range(0, len(self.content), max_file_size))] + ) + uris_to_mock.append( + dict(method='PUT', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, + container=self.container, object=self.object), + status_code=201, + validate=dict( + headers={ + 'x-object-manifest': '{container}/{object}'.format( + container=self.container, object=self.object), + 'x-object-meta-x-shade-md5': self.md5, + 'x-object-meta-x-shade-sha256': self.sha256, + }))) + self.register_uris(uris_to_mock) self.cloud.create_object( container=self.container, name=self.object, filename=self.object_file.name, use_slo=False) @@ -562,75 +560,75 @@ class TestObjectUploads(BaseTestObject): max_file_size = 25 min_file_size = 1 - self.register_uri( - 'GET', 'https://object-store.example.com/info', - json=dict( - swift={'max_file_size': max_file_size}, - slo={'min_segment_size': min_file_size})) + uris_to_mock = [ + dict(method='GET', uri='https://object-store.example.com/info', + json=dict( + swift={'max_file_size': max_file_size}, + slo={'min_segment_size': min_file_size})), + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container), + status_code=404), + dict(method='PUT', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container, ), + status_code=201, + headers={ + 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', + 'Content-Length': '0', + 'Content-Type': 'text/html; charset=UTF-8', + }), + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container), + headers={ + 'Content-Length': '0', + 'X-Container-Object-Count': '0', + 'Accept-Ranges': 'bytes', + 'X-Storage-Policy': 'Policy-0', + 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', + 'X-Timestamp': '1481912480.41664', + 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', + 'X-Container-Bytes-Used': '0', + 'Content-Type': 'text/plain; charset=utf-8'}), + dict(method='HEAD', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, + container=self.container, object=self.object), + status_code=404) + ] - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404) + uris_to_mock.extend([ + dict(method='PUT', + uri='{endpoint}/{container}/{object}/{index:0>6}'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object, + index=index), + status_code=201, + headers=dict(Etag='etag{index}'.format(index=index))) + for index, offset in enumerate( + range(0, len(self.content), max_file_size)) + ]) - self.register_uri( - 'PUT', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container,), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }) - - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}), - - self.register_uri( - 'HEAD', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=404) - - for index, offset in enumerate( - range(0, len(self.content), max_file_size)): - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/{index:0>6}'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object, - index=index), - status_code=201, - headers=dict(Etag='etag{index}'.format(index=index))) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=201, - validate=dict( - params={ - 'multipart-manifest', 'put' - }, - headers={ - 'x-object-meta-x-shade-md5': self.md5, - 'x-object-meta-x-shade-sha256': self.sha256, - })) + uris_to_mock.append( + dict(method='PUT', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, + container=self.container, object=self.object), + status_code=201, + validate=dict( + params={ + 'multipart-manifest', 'put' + }, + headers={ + 'x-object-meta-x-shade-md5': self.md5, + 'x-object-meta-x-shade-sha256': self.sha256, + }))) + self.register_uris(uris_to_mock) self.cloud.create_object( container=self.container, name=self.object, @@ -681,83 +679,75 @@ class TestObjectUploads(BaseTestObject): max_file_size = 25 min_file_size = 1 - self.register_uri( - 'GET', 'https://object-store.example.com/info', - json=dict( - swift={'max_file_size': max_file_size}, - slo={'min_segment_size': min_file_size})) - - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404) - - self.register_uri( - 'PUT', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container,), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }) - - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}) - - self.register_uri( - 'HEAD', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=404) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/000000'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object), - status_code=201) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/000001'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object), - status_code=201) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/000002'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object), - status_code=201) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/000003'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object), - status_code=501) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=201) + self.register_uris([ + dict(method='GET', uri='https://object-store.example.com/info', + json=dict( + swift={'max_file_size': max_file_size}, + slo={'min_segment_size': min_file_size})), + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container), + status_code=404), + dict(method='PUT', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container, ), + status_code=201, + headers={ + 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', + 'Content-Length': '0', + 'Content-Type': 'text/html; charset=UTF-8', + }), + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container), + headers={ + 'Content-Length': '0', + 'X-Container-Object-Count': '0', + 'Accept-Ranges': 'bytes', + 'X-Storage-Policy': 'Policy-0', + 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', + 'X-Timestamp': '1481912480.41664', + 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', + 'X-Container-Bytes-Used': '0', + 'Content-Type': 'text/plain; charset=utf-8'}), + dict(method='HEAD', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, + container=self.container, object=self.object), + status_code=404), + dict(method='PUT', + uri='{endpoint}/{container}/{object}/000000'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object), + status_code=201), + dict(method='PUT', + uri='{endpoint}/{container}/{object}/000001'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object), + status_code=201), + dict(method='PUT', + uri='{endpoint}/{container}/{object}/000002'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object), + status_code=201), + dict(method='PUT', + uri='{endpoint}/{container}/{object}/000003'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object), + status_code=501), + dict(method='PUT', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, + container=self.container, object=self.object), + status_code=201) + ]) self.assertRaises( exc.OpenStackCloudException, @@ -773,102 +763,93 @@ class TestObjectUploads(BaseTestObject): max_file_size = 25 min_file_size = 1 - self.register_uri( - 'GET', 'https://object-store.example.com/info', - json=dict( - swift={'max_file_size': max_file_size}, - slo={'min_segment_size': min_file_size})) - - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - status_code=404) - - self.register_uri( - 'PUT', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container,), - status_code=201, - headers={ - 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', - 'Content-Length': '0', - 'Content-Type': 'text/html; charset=UTF-8', - }) - - self.register_uri( - 'HEAD', '{endpoint}/{container}'.format( - endpoint=self.endpoint, - container=self.container), - headers={ - 'Content-Length': '0', - 'X-Container-Object-Count': '0', - 'Accept-Ranges': 'bytes', - 'X-Storage-Policy': 'Policy-0', - 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', - 'X-Timestamp': '1481912480.41664', - 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', - 'X-Container-Bytes-Used': '0', - 'Content-Type': 'text/plain; charset=utf-8'}) - - self.register_uri( - 'HEAD', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=404) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/000000'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object), - headers={'etag': 'etag0'}, - status_code=201) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/000001'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object), - headers={'etag': 'etag1'}, - status_code=201) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/000002'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object), - headers={'etag': 'etag2'}, - status_code=201) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/000003'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object), - status_code=501) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}/000003'.format( - endpoint=self.endpoint, - container=self.container, - object=self.object), - status_code=201, - headers={'etag': 'etag3'}) - - self.register_uri( - 'PUT', '{endpoint}/{container}/{object}'.format( - endpoint=self.endpoint, - container=self.container, object=self.object), - status_code=201, - validate=dict( - params={ - 'multipart-manifest', 'put' - }, - headers={ - 'x-object-meta-x-shade-md5': self.md5, - 'x-object-meta-x-shade-sha256': self.sha256, - })) + self.register_uris([ + dict(method='GET', uri='https://object-store.example.com/info', + json=dict( + swift={'max_file_size': max_file_size}, + slo={'min_segment_size': min_file_size})), + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container), + status_code=404), + dict(method='PUT', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container, ), + status_code=201, + headers={ + 'Date': 'Fri, 16 Dec 2016 18:21:20 GMT', + 'Content-Length': '0', + 'Content-Type': 'text/html; charset=UTF-8', + }), + dict(method='HEAD', + uri='{endpoint}/{container}'.format( + endpoint=self.endpoint, + container=self.container), + headers={ + 'Content-Length': '0', + 'X-Container-Object-Count': '0', + 'Accept-Ranges': 'bytes', + 'X-Storage-Policy': 'Policy-0', + 'Date': 'Fri, 16 Dec 2016 18:29:05 GMT', + 'X-Timestamp': '1481912480.41664', + 'X-Trans-Id': 'tx60ec128d9dbf44b9add68-0058543271dfw1', + 'X-Container-Bytes-Used': '0', + 'Content-Type': 'text/plain; charset=utf-8'}), + dict(method='HEAD', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, + container=self.container, object=self.object), + status_code=404), + dict(method='PUT', + uri='{endpoint}/{container}/{object}/000000'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object), + headers={'etag': 'etag0'}, + status_code=201), + dict(method='PUT', + uri='{endpoint}/{container}/{object}/000001'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object), + headers={'etag': 'etag1'}, + status_code=201), + dict(method='PUT', + uri='{endpoint}/{container}/{object}/000002'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object), + headers={'etag': 'etag2'}, + status_code=201), + dict(method='PUT', + uri='{endpoint}/{container}/{object}/000003'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object), + status_code=501), + dict(method='PUT', + uri='{endpoint}/{container}/{object}/000003'.format( + endpoint=self.endpoint, + container=self.container, + object=self.object), + status_code=201, + headers={'etag': 'etag3'}), + dict(method='PUT', + uri='{endpoint}/{container}/{object}'.format( + endpoint=self.endpoint, + container=self.container, object=self.object), + status_code=201, + validate=dict( + params={ + 'multipart-manifest', 'put' + }, + headers={ + 'x-object-meta-x-shade-md5': self.md5, + 'x-object-meta-x-shade-sha256': self.sha256, + })) + ]) self.cloud.create_object( container=self.container, name=self.object,