class S3MockRawResponse(MockRawResponse): fixtures = StorageFileFixtures('s3') def _foo_bar_container_foo_bar_object(self, method, url, body, headers): # test_download_object_success body = '' self._data = self._generate_random_data(1000) return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _foo_bar_container_foo_test_upload_INVALID_HASH1( self, method, url, body, headers): body = '' # test_upload_object_invalid_hash1 return (httplib.BAD_REQUEST, body, headers, httplib.responses[httplib.OK]) def _foo_bar_container_foo_test_upload_INVALID_HASH2( self, method, url, body, headers): # test_upload_object_invalid_hash2 body = '' headers = {'etag': '"hash343hhash89h932439jsaa89"'} return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _foo_bar_container_foo_test_upload(self, method, url, body, headers): # test_upload_object_success body = '' headers = {'etag': '"0cc175b9c0f1b6a831c399e269772661"'} return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _foo_bar_container_foo_bar_object_INVALID_SIZE(self, method, url, body, headers): # test_upload_object_invalid_file_size body = '' return (httplib.OK, body, headers, httplib.responses[httplib.OK])
class CloudFilesMockRawResponse(MockRawResponse): fixtures = StorageFileFixtures('cloudfiles') base_headers = {'content-type': 'application/json; charset=UTF-8'} def _v1_MossoCloudFS_foo_bar_container_foo_test_upload( self, method, url, body, headers): # test_object_upload_success body = '' headers = {} headers.update(self.base_headers) headers['etag'] = 'hash343hhash89h932439jsaa89' return (httplib.CREATED, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_test_upload_INVALID_HASH( self, method, url, body, headers): # test_object_upload_invalid_hash body = '' headers = {} headers.update(self.base_headers) headers['etag'] = 'foobar' return (httplib.CREATED, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object( self, method, url, body, headers): # test_download_object_success body = 'test' self._data = self._generate_random_data(1000) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_INVALID_SIZE( self, method, url, body, headers): # test_download_object_invalid_file_size body = 'test' self._data = self._generate_random_data(100) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND( self, method, url, body, headers): body = '' return (httplib.NOT_FOUND, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_test_stream_data( self, method, url, body, headers): # test_upload_object_via_stream_success headers = {} headers.update(self.base_headers) headers['etag'] = '577ef1154f3240ad5b9b413aa7346a1e' body = 'test' return (httplib.CREATED, body, headers, httplib.responses[httplib.OK])
class CloudFilesMockRawResponse(MockRawResponse): fixtures = StorageFileFixtures('cloudfiles') base_headers = {'content-type': 'application/json; charset=UTF-8'} def _v1_MossoCloudFS_foo_bar_container_foo_test_upload( self, method, url, body, headers): # test_object_upload_success body = '' headers = copy.deepcopy(self.base_headers) headers.update(headers) return (httplib.CREATED, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_test_upload_INVALID_HASH( self, method, url, body, headers): # test_object_upload_invalid_hash body = '' headers = self.base_headers return (httplib.UNPROCESSABLE_ENTITY, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object( self, method, url, body, headers): # test_download_object_success body = 'test' self._data = self._generate_random_data(1000) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_INVALID_SIZE( self, method, url, body, headers): # test_download_object_invalid_file_size body = 'test' self._data = self._generate_random_data(100) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND( self, method, url, body, headers): body = '' return (httplib.NOT_FOUND, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_test_stream_data( self, method, url, body, headers): # test_upload_object_via_stream_success body = 'test' return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK])
class AtmosMockRawResponse(MockRawResponse): fixtures = StorageFileFixtures('atmos') def _rest_namespace_foo_bar_container_foo_bar_object( self, method, url, body, headers): body = 'test' self._data = self._generate_random_data(1000) return (httplib.OK, body, {}, httplib.responses[httplib.OK]) def _rest_namespace_foo_bar_container_foo_bar_object_NOT_FOUND( self, method, url, body, headers): body = self.fixtures.load('not_found.xml') return (httplib.NOT_FOUND, body, {}, httplib.responses[httplib.NOT_FOUND]) def _rest_namespace_fbc_ftu(self, method, url, body, headers): return (httplib.CREATED, '', {}, httplib.responses[httplib.CREATED])
class CloudFilesMockRawResponse(MockRawResponse): fixtures = StorageFileFixtures('cloudfiles') base_headers = {'content-type': 'application/json; charset=UTF-8'} def __init__(self, *args, **kwargs): super(CloudFilesMockRawResponse, self).__init__(*args, **kwargs) self._data = [] self._current_item = 0 def next(self): if self._current_item == len(self._data): raise StopIteration value = self._data[self._current_item] self._current_item += 1 return value def _generate_random_data(self, size): data = [] current_size = 0 while current_size < size: value = str(random.randint(0, 9)) value_size = len(value) data.append(value) current_size += value_size return data def _v1_MossoCloudFS_foo_bar_container_foo_test_upload( self, method, url, body, headers): # test_object_upload_success body = '' headers = copy.deepcopy(self.base_headers) headers.update(headers) return (httplib.CREATED, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_test_upload_INVALID_HASH( self, method, url, body, headers): # test_object_upload_invalid_hash body = '' headers = self.base_headers return (httplib.UNPROCESSABLE_ENTITY, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object( self, method, url, body, headers): # test_download_object_success body = 'test' self._data = self._generate_random_data(1000) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_INVALID_SIZE( self, method, url, body, headers): # test_download_object_invalid_file_size body = 'test' self._data = self._generate_random_data(100) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND( self, method, url, body, headers): body = '' return (httplib.NOT_FOUND, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_test_stream_data( self, method, url, body, headers): # test_upload_object_via_stream_success body = 'test' return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK])
class CloudFilesMockHttp(MockHttp): fixtures = StorageFileFixtures('cloudfiles') base_headers = {'content-type': 'application/json; charset=UTF-8'} def putrequest(self, method, action): pass def putheader(self, key, value): pass def endheaders(self): pass def send(self, data): pass # fake auth token response def _v1_0(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) headers.update({ 'x-server-management-url': 'https://servers.api.rackspacecloud.com/v1.0/slug', 'x-auth-token': 'FE011C19', 'x-cdn-management-url': 'https://cdn.clouddrive.com/v1/MossoCloudFS', 'x-storage-token': 'FE011C19', 'x-storage-url': 'https://storage4.clouddrive.com/v1/MossoCloudFS' }) return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT]) def _v1_MossoCloudFS_EMPTY(self, method, url, body, headers): body = self.fixtures.load('list_containers_empty.json') return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS(self, method, url, body, headers): if method == 'GET': # list_containers body = self.fixtures.load('list_containers.json') status_code = httplib.OK headers = copy.deepcopy(self.base_headers) elif method == 'HEAD': # get_meta_data body = self.fixtures.load('meta_data.json') status_code = httplib.NO_CONTENT headers = copy.deepcopy(self.base_headers) headers.update({ 'x-account-container-count': 10, 'x-account-object-count': 400, 'x-account-bytes-used': 1234567 }) return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_EMPTY(self, method, url, body, headers): body = self.fixtures.load('list_container_objects_empty.json') return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container(self, method, url, body, headers): if method == 'GET': # list_container_objects body = self.fixtures.load('list_container_objects.json') status_code = httplib.OK headers = copy.deepcopy(self.base_headers) elif method == 'HEAD': # get_container body = self.fixtures.load('list_container_objects_empty.json') status_code = httplib.NO_CONTENT headers = copy.deepcopy(self.base_headers) headers.update({ 'x-container-object-count': 800, 'x-container-bytes-used': 1234568 }) return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_test_object(self, method, url, body, headers): if method == 'HEAD': # get_object body = self.fixtures.load('list_container_objects_empty.json') status_code = httplib.NO_CONTENT headers = self.base_headers headers.update({ 'content-length': 555, 'last-modified': 'Tue, 25 Jan 2011 22:01:49 GMT', 'etag': '6b21c4a111ac178feacf9ec9d0c71f17', 'x-object-meta-foo-bar': 'test 1', 'x-object-meta-bar-foo': 'test 2', 'content-type': 'application/zip' }) return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_create_container(self, method, url, body, headers): # test_create_container_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers headers.update({ 'content-length': 18, 'date': 'Mon, 28 Feb 2011 07:52:57 GMT' }) status_code = httplib.CREATED return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_create_container_ALREADY_EXISTS( self, method, url, body, headers): # test_create_container_already_exists body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers headers.update({'content-type': 'text/plain'}) status_code = httplib.ACCEPTED return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container(self, method, url, body, headers): if method == 'DELETE': # test_delete_container_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NO_CONTENT return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_NOT_FOUND(self, method, url, body, headers): if method == 'DELETE': # test_delete_container_not_found body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NOT_FOUND return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_NOT_EMPTY(self, method, url, body, headers): if method == 'DELETE': # test_delete_container_not_empty body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.CONFLICT return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object( self, method, url, body, headers): if method == 'DELETE': # test_delete_object_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NO_CONTENT return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND( self, method, url, body, headers): if method == 'DELETE': # test_delete_object_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NOT_FOUND return (status_code, body, headers, httplib.responses[httplib.OK])
class CloudFilesMockHttp(StorageMockHttp): fixtures = StorageFileFixtures('cloudfiles') auth_fixtures = OpenStackFixtures() base_headers = {'content-type': 'application/json; charset=UTF-8'} # fake auth token response def _v1_0(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) headers.update({ 'x-server-management-url': 'https://servers.api.rackspacecloud.com/v1.0/slug', 'x-auth-token': 'FE011C19', 'x-cdn-management-url': 'https://cdn.clouddrive.com/v1/MossoCloudFS', 'x-storage-token': 'FE011C19', 'x-storage-url': 'https://storage4.clouddrive.com/v1/MossoCloudFS' }) return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT]) def _v1_MossoCloudFS_MALFORMED_JSON(self, method, url, body, headers): # test_invalid_json_throws_exception body = 'broken: json /*"' return (httplib.NO_CONTENT, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_EMPTY(self, method, url, body, headers): return (httplib.NO_CONTENT, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) if method == 'GET': # list_containers body = self.fixtures.load('list_containers.json') status_code = httplib.OK elif method == 'HEAD': # get_meta_data body = self.fixtures.load('meta_data.json') status_code = httplib.NO_CONTENT headers.update({ 'x-account-container-count': 10, 'x-account-object-count': 400, 'x-account-bytes-used': 1234567 }) return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_not_found(self, method, url, body, headers): # test_get_object_not_found if method == 'HEAD': body = '' else: raise ValueError('Invalid method') return (httplib.NOT_FOUND, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_EMPTY(self, method, url, body, headers): body = self.fixtures.load('list_container_objects_empty.json') return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) if method == 'GET': # list_container_objects if url.find('marker') == -1: body = self.fixtures.load('list_container_objects.json') status_code = httplib.OK else: body = '' status_code = httplib.NO_CONTENT elif method == 'HEAD': # get_container body = self.fixtures.load('list_container_objects_empty.json') status_code = httplib.NO_CONTENT headers.update({ 'x-container-object-count': 800, 'x-container-bytes-used': 1234568 }) return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_ITERATOR(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) # list_container_objects if url.find('foo-test-3') != -1: body = self.fixtures.load( 'list_container_objects_not_exhausted2.json') status_code = httplib.OK elif url.find('foo-test-5') != -1: body = '' status_code = httplib.NO_CONTENT else: # First request body = self.fixtures.load( 'list_container_objects_not_exhausted1.json') status_code = httplib.OK return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_not_found(self, method, url, body, headers): # test_get_container_not_found if method == 'HEAD': body = '' else: raise ValueError('Invalid method') return (httplib.NOT_FOUND, body, self.base_headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_container_test_object(self, method, url, body, headers): headers = copy.deepcopy(self.base_headers) if method == 'HEAD': # get_object body = self.fixtures.load('list_container_objects_empty.json') status_code = httplib.NO_CONTENT headers.update({ 'content-length': 555, 'last-modified': 'Tue, 25 Jan 2011 22:01:49 GMT', 'etag': '6b21c4a111ac178feacf9ec9d0c71f17', 'x-object-meta-foo-bar': 'test 1', 'x-object-meta-bar-foo': 'test 2', 'content-type': 'application/zip' }) return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_create_container(self, method, url, body, headers): # test_create_container_success headers = copy.deepcopy(self.base_headers) body = self.fixtures.load('list_container_objects_empty.json') headers = copy.deepcopy(self.base_headers) headers.update({ 'content-length': 18, 'date': 'Mon, 28 Feb 2011 07:52:57 GMT' }) status_code = httplib.CREATED return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_test_create_container_ALREADY_EXISTS( self, method, url, body, headers): # test_create_container_already_exists headers = copy.deepcopy(self.base_headers) body = self.fixtures.load('list_container_objects_empty.json') headers.update({'content-type': 'text/plain'}) status_code = httplib.ACCEPTED return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container(self, method, url, body, headers): if method == 'DELETE': # test_delete_container_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NO_CONTENT return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_NOT_FOUND(self, method, url, body, headers): if method == 'DELETE': # test_delete_container_not_found body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NOT_FOUND return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_NOT_EMPTY(self, method, url, body, headers): if method == 'DELETE': # test_delete_container_not_empty body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.CONFLICT return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object( self, method, url, body, headers): if method == 'DELETE': # test_delete_object_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NO_CONTENT return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_MossoCloudFS_foo_bar_container_foo_bar_object_NOT_FOUND( self, method, url, body, headers): if method == 'DELETE': # test_delete_object_success body = self.fixtures.load('list_container_objects_empty.json') headers = self.base_headers status_code = httplib.NOT_FOUND return (status_code, body, headers, httplib.responses[httplib.OK]) def _v1_1_auth(self, method, url, body, headers): body = self.auth_fixtures.load('_v1_1__auth.json') return (httplib.OK, body, { 'content-type': 'application/json; charset=UTF-8' }, httplib.responses[httplib.OK])
class AtmosMockHttp(StorageMockHttp, unittest.TestCase): fixtures = StorageFileFixtures('atmos') upload_created = False def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self) if kwargs.get('host', None) and kwargs.get('port', None): StorageMockHttp.__init__(self, *args, **kwargs) def runTest(self): pass def request(self, method, url, body=None, headers=None, raw=False): headers = headers or {} parsed = urlparse.urlparse(url) if parsed.query.startswith('metadata/'): parsed = list(parsed) parsed[2] = parsed[2] + '/' + parsed[4] parsed[4] = '' url = urlparse.urlunparse(parsed) return super(AtmosMockHttp, self).request(method, url, body, headers, raw) def _rest_namespace_EMPTY(self, method, url, body, headers): body = self.fixtures.load('empty_directory_listing.xml') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) def _rest_namespace(self, method, url, body, headers): body = self.fixtures.load('list_containers.xml') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) def _rest_namespace_test_container_EMPTY(self, method, url, body, headers): body = self.fixtures.load('empty_directory_listing.xml') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) def _rest_namespace_test_container(self, method, url, body, headers): body = self.fixtures.load('list_containers.xml') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) def _rest_namespace_test_container__metadata_system( self, method, url, body, headers): headers = { 'x-emc-meta': 'objectid=b21cb59a2ba339d1afdd4810010b0a5aba2ab6b9' } return (httplib.OK, '', headers, httplib.responses[httplib.OK]) def _rest_namespace_not_found__metadata_system(self, method, url, body, headers): body = self.fixtures.load('not_found.xml') return (httplib.NOT_FOUND, body, {}, httplib.responses[httplib.NOT_FOUND]) def _rest_namespace_test_create_container(self, method, url, body, headers): return (httplib.OK, '', {}, httplib.responses[httplib.OK]) def _rest_namespace_test_create_container__metadata_system( self, method, url, body, headers): headers = { 'x-emc-meta': 'objectid=31a27b593629a3fe59f887fd973fd953e80062ce' } return (httplib.OK, '', headers, httplib.responses[httplib.OK]) def _rest_namespace_test_create_container_ALREADY_EXISTS( self, method, url, body, headers): body = self.fixtures.load('already_exists.xml') return (httplib.BAD_REQUEST, body, {}, httplib.responses[httplib.BAD_REQUEST]) def _rest_namespace_foo_bar_container(self, method, url, body, headers): return (httplib.OK, '', {}, httplib.responses[httplib.OK]) def _rest_namespace_foo_bar_container_NOT_FOUND(self, method, url, body, headers): body = self.fixtures.load('not_found.xml') return (httplib.NOT_FOUND, body, {}, httplib.responses[httplib.NOT_FOUND]) def _rest_namespace_foo_bar_container_NOT_EMPTY(self, method, url, body, headers): body = self.fixtures.load('not_empty.xml') return (httplib.BAD_REQUEST, body, {}, httplib.responses[httplib.BAD_REQUEST]) def _rest_namespace_test_container_test_object_metadata_system( self, method, url, body, headers): meta = { 'objectid': '322dce3763aadc41acc55ef47867b8d74e45c31d6643', 'size': '555', 'mtime': '2011-01-25T22:01:49Z' } headers = { 'x-emc-meta': ', '.join([k + '=' + v for k, v in list(meta.items())]) } return (httplib.OK, '', headers, httplib.responses[httplib.OK]) def _rest_namespace_test_container_test_object_metadata_user( self, method, url, body, headers): meta = { 'md5': '6b21c4a111ac178feacf9ec9d0c71f17', 'foo-bar': 'test 1', 'bar-foo': 'test 2', } headers = { 'x-emc-meta': ', '.join([k + '=' + v for k, v in list(meta.items())]) } return (httplib.OK, '', headers, httplib.responses[httplib.OK]) def _rest_namespace_test_container_not_found_metadata_system( self, method, url, body, headers): body = self.fixtures.load('not_found.xml') return (httplib.NOT_FOUND, body, {}, httplib.responses[httplib.NOT_FOUND]) def _rest_namespace_foo_bar_container_foo_bar_object( self, method, url, body, headers): return (httplib.OK, '', {}, httplib.responses[httplib.OK]) def _rest_namespace_foo_bar_container_foo_bar_object_NOT_FOUND( self, method, url, body, headers): body = self.fixtures.load('not_found.xml') return (httplib.NOT_FOUND, body, {}, httplib.responses[httplib.NOT_FOUND]) def _rest_namespace_fbc_ftu_metadata_system(self, method, url, body, headers): if not self.upload_created: self.__class__.upload_created = True body = self.fixtures.load('not_found.xml') return (httplib.NOT_FOUND, body, {}, httplib.responses[httplib.NOT_FOUND]) self.__class__.upload_created = False meta = { 'objectid': '322dce3763aadc41acc55ef47867b8d74e45c31d6643', 'size': '555', 'mtime': '2011-01-25T22:01:49Z' } headers = { 'x-emc-meta': ', '.join([k + '=' + v for k, v in list(meta.items())]) } return (httplib.OK, '', headers, httplib.responses[httplib.OK]) def _rest_namespace_fbc_ftu_metadata_user(self, method, url, body, headers): self.assertTrue('x-emc-meta' in headers) return (httplib.OK, '', {}, httplib.responses[httplib.OK]) def _rest_namespace_fbc_ftsd(self, method, url, body, headers): self.assertTrue('Range' in headers) return (httplib.OK, '', {}, httplib.responses[httplib.OK]) def _rest_namespace_fbc_ftsd_metadata_user(self, method, url, body, headers): self.assertTrue('x-emc-meta' in headers) return (httplib.OK, '', {}, httplib.responses[httplib.OK]) def _rest_namespace_fbc_ftsd_metadata_system(self, method, url, body, headers): meta = { 'objectid': '322dce3763aadc41acc55ef47867b8d74e45c31d6643', 'size': '555', 'mtime': '2011-01-25T22:01:49Z' } headers = { 'x-emc-meta': ', '.join([k + '=' + v for k, v in list(meta.items())]) } return (httplib.OK, '', headers, httplib.responses[httplib.OK])
class GoogleStorageMockHttp(S3MockHttp): fixtures = StorageFileFixtures('google_storage')
class S3MockHttp(StorageMockHttp): fixtures = StorageFileFixtures('s3') base_headers = {} def _UNAUTHORIZED(self, method, url, body, headers): return (httplib.UNAUTHORIZED, '', self.base_headers, httplib.responses[httplib.OK]) def _DIFFERENT_REGION(self, method, url, body, headers): return (httplib.MOVED_PERMANENTLY, '', self.base_headers, httplib.responses[httplib.OK]) def _list_containers_EMPTY(self, method, url, body, headers): body = self.fixtures.load('list_containers_empty.xml') return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _list_containers(self, method, url, body, headers): body = self.fixtures.load('list_containers.xml') return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _test_container_EMPTY(self, method, url, body, headers): body = self.fixtures.load('list_container_objects_empty.xml') return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _test_container(self, method, url, body, headers): body = self.fixtures.load('list_container_objects.xml') return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _test_container_ITERATOR(self, method, url, body, headers): if url.find('3.zip') == -1: # First part of the response (first 3 objects) file_name = 'list_container_objects_not_exhausted1.xml' else: file_name = 'list_container_objects_not_exhausted2.xml' body = self.fixtures.load(file_name) return (httplib.OK, body, self.base_headers, httplib.responses[httplib.OK]) def _test2_test_list_containers(self, method, url, body, headers): # test_get_object body = self.fixtures.load('list_containers.xml') headers = {'content-type': 'application/zip', 'etag': '"e31208wqsdoj329jd"', 'content-length': 12345, } return (httplib.OK, body, headers, httplib.responses[httplib.OK]) def _new_container_INVALID_NAME(self, method, url, body, headers): # test_create_container return (httplib.BAD_REQUEST, body, headers, httplib.responses[httplib.OK]) def _new_container_ALREADY_EXISTS(self, method, url, body, headers): # test_create_container return (httplib.CONFLICT, body, headers, httplib.responses[httplib.OK]) def _new_container(self, method, url, body, headers): # test_create_container, test_delete_container if method == 'PUT': status = httplib.OK elif method == 'DELETE': status = httplib.NO_CONTENT return (status, body, headers, httplib.responses[httplib.OK]) def _new_container_DOESNT_EXIST(self, method, url, body, headers): # test_delete_container return (httplib.NOT_FOUND, body, headers, httplib.responses[httplib.OK]) def _new_container_NOT_EMPTY(self, method, url, body, headers): # test_delete_container return (httplib.CONFLICT, body, headers, httplib.responses[httplib.OK]) def _foo_bar_container(self, method, url, body, headers): # test_delete_container return (httplib.NO_CONTENT, body, headers, httplib.responses[httplib.OK]) def _foo_bar_container_NOT_FOUND(self, method, url, body, headers): # test_delete_container_not_found return (httplib.NOT_FOUND, body, headers, httplib.responses[httplib.OK]) def _foo_bar_container_foo_bar_object_NOT_FOUND(self, method, url, body, headers): # test_delete_object_not_found return (httplib.NOT_FOUND, body, headers, httplib.responses[httplib.OK]) def _foo_bar_container_foo_bar_object(self, method, url, body, headers): # test_delete_object return (httplib.NO_CONTENT, body, headers, httplib.responses[httplib.OK])