Index: tests/s3/mock_storage_service.py |
diff --git a/boto/tests/mock_storage_service.py b/tests/s3/mock_storage_service.py |
similarity index 78% |
rename from boto/tests/mock_storage_service.py |
rename to tests/s3/mock_storage_service.py |
index 10b5253467ce77d3b7d06b5e38139f19842e0a81..0f3ea7b8482ab85fcc38411e22ba75d95222ef43 100644 |
--- a/boto/tests/mock_storage_service.py |
+++ b/tests/s3/mock_storage_service.py |
@@ -92,7 +92,7 @@ class MockKey(object): |
cb=NOT_IMPL, num_cb=NOT_IMPL, |
policy=NOT_IMPL, md5=NOT_IMPL, |
res_upload_handler=NOT_IMPL): |
- self.data = fp.readlines() |
+ self.data = fp.read() |
self.size = len(self.data) |
self._handle_headers(headers) |
@@ -103,13 +103,31 @@ class MockKey(object): |
self.size = len(s) |
self._handle_headers(headers) |
+ def set_contents_from_filename(self, filename, headers=None, replace=NOT_IMPL, |
+ cb=NOT_IMPL, num_cb=NOT_IMPL, |
+ policy=NOT_IMPL, md5=NOT_IMPL, |
+ res_upload_handler=NOT_IMPL): |
+ fp = open(filename, 'rb') |
+ self.set_contents_from_file(fp, headers, replace, cb, num_cb, |
+ policy, md5, res_upload_handler) |
+ fp.close() |
+ |
+ def copy(self, dst_bucket_name, dst_key, metadata=NOT_IMPL, |
+ reduced_redundancy=NOT_IMPL, preserve_acl=NOT_IMPL): |
+ dst_bucket = self.bucket.connection.get_bucket(dst_bucket_name) |
+ return dst_bucket.copy_key(dst_key, self.bucket.name, |
+ self.name, metadata) |
+ |
class MockBucket(object): |
- def __init__(self, connection=NOT_IMPL, name=None, key_class=NOT_IMPL): |
+ def __init__(self, connection=None, name=None, key_class=NOT_IMPL): |
self.name = name |
self.keys = {} |
self.acls = {name: MockAcl()} |
+ self.subresources = {} |
+ self.connection = connection |
+ self.logging = False |
def copy_key(self, new_key_name, src_bucket_name, |
src_key_name, metadata=NOT_IMPL, src_version_id=NOT_IMPL, |
@@ -119,6 +137,13 @@ class MockBucket(object): |
src_bucket_name).get_key(src_key_name) |
new_key.data = copy.copy(src_key.data) |
new_key.size = len(new_key.data) |
+ return new_key |
+ |
+ def disable_logging(self): |
+ self.logging = False |
+ |
+ def enable_logging(self, target_bucket_prefix): |
+ self.logging = True |
def get_acl(self, key_name='', headers=NOT_IMPL, version_id=NOT_IMPL): |
if key_name: |
@@ -128,6 +153,13 @@ class MockBucket(object): |
# Return ACL for the bucket. |
return self.acls[self.name] |
+ def get_subresource(self, subresource, key_name=NOT_IMPL, headers=NOT_IMPL, |
+ version_id=NOT_IMPL): |
+ if subresource in self.subresources: |
+ return self.subresources[subresource] |
+ else: |
+ return '<Subresource/>' |
+ |
def new_key(self, key_name=None): |
mock_key = MockKey(self, key_name) |
self.keys[key_name] = mock_key |
@@ -173,6 +205,10 @@ class MockBucket(object): |
# Set ACL for the bucket. |
self.acls[self.name] = acl_or_str |
+ def set_subresource(self, subresource, value, key_name=NOT_IMPL, |
+ headers=NOT_IMPL, version_id=NOT_IMPL): |
+ self.subresources[subresource] = value |
+ |
class MockConnection(object): |
@@ -191,15 +227,17 @@ class MockConnection(object): |
policy=NOT_IMPL): |
if bucket_name in self.buckets: |
raise boto.exception.StorageCreateError( |
- 409, 'BucketAlreadyOwnedByYou', 'bucket already exists') |
- mock_bucket = MockBucket(name=bucket_name) |
+ 409, 'BucketAlreadyOwnedByYou', |
+ "<Message>Your previous request to create the named bucket " |
+ "succeeded and you already own it.</Message>") |
+ mock_bucket = MockBucket(name=bucket_name, connection=self) |
self.buckets[bucket_name] = mock_bucket |
return mock_bucket |
def delete_bucket(self, bucket, headers=NOT_IMPL): |
if bucket not in self.buckets: |
- raise boto.exception.StorageResponseError(404, 'NoSuchBucket', |
- 'no such bucket') |
+ raise boto.exception.StorageResponseError( |
+ 404, 'NoSuchBucket', '<Message>no such bucket</Message>') |
del self.buckets[bucket] |
def get_bucket(self, bucket_name, validate=NOT_IMPL, headers=NOT_IMPL): |
@@ -258,12 +296,25 @@ class MockBucketStorageUri(object): |
version_id=NOT_IMPL, mfa_token=NOT_IMPL): |
self.get_bucket().delete_key(self.object_name) |
+ def disable_logging(self, validate=NOT_IMPL, headers=NOT_IMPL, |
+ version_id=NOT_IMPL): |
+ self.get_bucket().disable_logging() |
+ |
+ def enable_logging(self, target_bucket, target_prefix, canned_acl=NOT_IMPL, |
+ validate=NOT_IMPL, headers=NOT_IMPL, |
+ version_id=NOT_IMPL): |
+ self.get_bucket().enable_logging(target_bucket) |
+ |
def equals(self, uri): |
return self.uri == uri.uri |
def get_acl(self, validate=NOT_IMPL, headers=NOT_IMPL, version_id=NOT_IMPL): |
return self.get_bucket().get_acl(self.object_name) |
+ def get_subresource(self, subresource, validate=NOT_IMPL, headers=NOT_IMPL, |
+ version_id=NOT_IMPL): |
+ return self.get_bucket().get_subresource(subresource, self.object_name) |
+ |
def get_all_buckets(self, headers=NOT_IMPL): |
return self.connect().get_all_buckets() |
@@ -296,3 +347,7 @@ class MockBucketStorageUri(object): |
def set_acl(self, acl_or_str, key_name='', validate=NOT_IMPL, |
headers=NOT_IMPL, version_id=NOT_IMPL): |
self.get_bucket().set_acl(acl_or_str, key_name) |
+ |
+ def set_subresource(self, subresource, value, validate=NOT_IMPL, |
+ headers=NOT_IMPL, version_id=NOT_IMPL): |
+ self.get_bucket().set_subresource(subresource, value, self.object_name) |