|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from s3transfer.manager import TransferConfig |
|
from tests import RecordingSubscriber |
|
from tests.integration import BaseTransferManagerIntegTest |
|
|
|
|
|
class TestCopy(BaseTransferManagerIntegTest): |
|
def setUp(self): |
|
super().setUp() |
|
self.multipart_threshold = 5 * 1024 * 1024 |
|
self.config = TransferConfig( |
|
multipart_threshold=self.multipart_threshold |
|
) |
|
|
|
def test_copy_below_threshold(self): |
|
transfer_manager = self.create_transfer_manager(self.config) |
|
key = '1mb.txt' |
|
new_key = '1mb-copy.txt' |
|
|
|
filename = self.files.create_file_with_size(key, filesize=1024 * 1024) |
|
self.upload_file(filename, key) |
|
|
|
future = transfer_manager.copy( |
|
copy_source={'Bucket': self.bucket_name, 'Key': key}, |
|
bucket=self.bucket_name, |
|
key=new_key, |
|
) |
|
|
|
future.result() |
|
self.assertTrue(self.object_exists(new_key)) |
|
|
|
def test_copy_above_threshold(self): |
|
transfer_manager = self.create_transfer_manager(self.config) |
|
key = '20mb.txt' |
|
new_key = '20mb-copy.txt' |
|
|
|
filename = self.files.create_file_with_size( |
|
key, filesize=20 * 1024 * 1024 |
|
) |
|
self.upload_file(filename, key) |
|
|
|
future = transfer_manager.copy( |
|
copy_source={'Bucket': self.bucket_name, 'Key': key}, |
|
bucket=self.bucket_name, |
|
key=new_key, |
|
) |
|
|
|
future.result() |
|
self.assertTrue(self.object_exists(new_key)) |
|
|
|
def test_progress_subscribers_on_copy(self): |
|
subscriber = RecordingSubscriber() |
|
transfer_manager = self.create_transfer_manager(self.config) |
|
key = '20mb.txt' |
|
new_key = '20mb-copy.txt' |
|
|
|
filename = self.files.create_file_with_size( |
|
key, filesize=20 * 1024 * 1024 |
|
) |
|
self.upload_file(filename, key) |
|
|
|
future = transfer_manager.copy( |
|
copy_source={'Bucket': self.bucket_name, 'Key': key}, |
|
bucket=self.bucket_name, |
|
key=new_key, |
|
subscribers=[subscriber], |
|
) |
|
|
|
future.result() |
|
|
|
|
|
|
|
|
|
self.assertEqual(subscriber.calculate_bytes_seen(), 20 * 1024 * 1024) |
|
|