File size: 2,989 Bytes
065fee7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
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()
# The callback should have been called enough times such that
# the total amount of bytes we've seen (via the "amount"
# arg to the callback function) should be the size
# of the file we uploaded.
self.assertEqual(subscriber.calculate_bytes_seen(), 20 * 1024 * 1024)
|