|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from concurrent import futures |
|
from functools import partial |
|
from threading import Event |
|
|
|
from s3transfer.futures import BoundedExecutor, TransferCoordinator |
|
from s3transfer.subscribers import BaseSubscriber |
|
from s3transfer.tasks import ( |
|
CompleteMultipartUploadTask, |
|
CreateMultipartUploadTask, |
|
SubmissionTask, |
|
Task, |
|
) |
|
from s3transfer.utils import CallArgs, FunctionContainer, get_callbacks |
|
from tests import ( |
|
BaseSubmissionTaskTest, |
|
BaseTaskTest, |
|
RecordingSubscriber, |
|
unittest, |
|
) |
|
|
|
|
|
class TaskFailureException(Exception): |
|
pass |
|
|
|
|
|
class SuccessTask(Task): |
|
def _main( |
|
self, return_value='success', callbacks=None, failure_cleanups=None |
|
): |
|
if callbacks: |
|
for callback in callbacks: |
|
callback() |
|
if failure_cleanups: |
|
for failure_cleanup in failure_cleanups: |
|
self._transfer_coordinator.add_failure_cleanup(failure_cleanup) |
|
return return_value |
|
|
|
|
|
class FailureTask(Task): |
|
def _main(self, exception=TaskFailureException): |
|
raise exception() |
|
|
|
|
|
class ReturnKwargsTask(Task): |
|
def _main(self, **kwargs): |
|
return kwargs |
|
|
|
|
|
class SubmitMoreTasksTask(Task): |
|
def _main(self, executor, tasks_to_submit): |
|
for task_to_submit in tasks_to_submit: |
|
self._transfer_coordinator.submit(executor, task_to_submit) |
|
|
|
|
|
class NOOPSubmissionTask(SubmissionTask): |
|
def _submit(self, transfer_future, **kwargs): |
|
pass |
|
|
|
|
|
class ExceptionSubmissionTask(SubmissionTask): |
|
def _submit( |
|
self, |
|
transfer_future, |
|
executor=None, |
|
tasks_to_submit=None, |
|
additional_callbacks=None, |
|
exception=TaskFailureException, |
|
): |
|
if executor and tasks_to_submit: |
|
for task_to_submit in tasks_to_submit: |
|
self._transfer_coordinator.submit(executor, task_to_submit) |
|
if additional_callbacks: |
|
for callback in additional_callbacks: |
|
callback() |
|
raise exception() |
|
|
|
|
|
class StatusRecordingTransferCoordinator(TransferCoordinator): |
|
def __init__(self, transfer_id=None): |
|
super().__init__(transfer_id) |
|
self.status_changes = [self._status] |
|
|
|
def set_status_to_queued(self): |
|
super().set_status_to_queued() |
|
self._record_status_change() |
|
|
|
def set_status_to_running(self): |
|
super().set_status_to_running() |
|
self._record_status_change() |
|
|
|
def _record_status_change(self): |
|
self.status_changes.append(self._status) |
|
|
|
|
|
class RecordingStateSubscriber(BaseSubscriber): |
|
def __init__(self, transfer_coordinator): |
|
self._transfer_coordinator = transfer_coordinator |
|
self.status_during_on_queued = None |
|
|
|
def on_queued(self, **kwargs): |
|
self.status_during_on_queued = self._transfer_coordinator.status |
|
|
|
|
|
class TestSubmissionTask(BaseSubmissionTaskTest): |
|
def setUp(self): |
|
super().setUp() |
|
self.executor = BoundedExecutor(1000, 5) |
|
self.call_args = CallArgs(subscribers=[]) |
|
self.transfer_future = self.get_transfer_future(self.call_args) |
|
self.main_kwargs = {'transfer_future': self.transfer_future} |
|
|
|
def test_transitions_from_not_started_to_queued_to_running(self): |
|
self.transfer_coordinator = StatusRecordingTransferCoordinator() |
|
submission_task = self.get_task( |
|
NOOPSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
|
|
self.assertEqual(self.transfer_coordinator.status, 'not-started') |
|
|
|
submission_task() |
|
|
|
self.assertEqual(self.transfer_coordinator.status, 'running') |
|
|
|
|
|
self.assertEqual( |
|
self.transfer_coordinator.status_changes, |
|
['not-started', 'queued', 'running'], |
|
) |
|
|
|
def test_on_queued_callbacks(self): |
|
submission_task = self.get_task( |
|
NOOPSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
|
|
subscriber = RecordingSubscriber() |
|
self.call_args.subscribers.append(subscriber) |
|
submission_task() |
|
|
|
self.assertEqual( |
|
subscriber.on_queued_calls, [{'future': self.transfer_future}] |
|
) |
|
|
|
def test_on_queued_status_in_callbacks(self): |
|
submission_task = self.get_task( |
|
NOOPSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
|
|
subscriber = RecordingStateSubscriber(self.transfer_coordinator) |
|
self.call_args.subscribers.append(subscriber) |
|
submission_task() |
|
|
|
self.assertEqual(subscriber.status_during_on_queued, 'queued') |
|
|
|
def test_sets_exception_from_submit(self): |
|
submission_task = self.get_task( |
|
ExceptionSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
submission_task() |
|
|
|
|
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
|
|
|
|
|
|
with self.assertRaises(TaskFailureException): |
|
self.transfer_future.result() |
|
|
|
def test_catches_and_sets_keyboard_interrupt_exception_from_submit(self): |
|
self.main_kwargs['exception'] = KeyboardInterrupt |
|
submission_task = self.get_task( |
|
ExceptionSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
submission_task() |
|
|
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
with self.assertRaises(KeyboardInterrupt): |
|
self.transfer_future.result() |
|
|
|
def test_calls_done_callbacks_on_exception(self): |
|
submission_task = self.get_task( |
|
ExceptionSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
|
|
subscriber = RecordingSubscriber() |
|
self.call_args.subscribers.append(subscriber) |
|
|
|
|
|
|
|
done_callbacks = get_callbacks(self.transfer_future, 'done') |
|
for done_callback in done_callbacks: |
|
self.transfer_coordinator.add_done_callback(done_callback) |
|
submission_task() |
|
|
|
|
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
|
|
|
|
self.assertEqual( |
|
subscriber.on_done_calls, [{'future': self.transfer_future}] |
|
) |
|
|
|
def test_calls_failure_cleanups_on_exception(self): |
|
submission_task = self.get_task( |
|
ExceptionSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
|
|
|
|
|
|
invocations_of_cleanup = [] |
|
cleanup_callback = FunctionContainer( |
|
invocations_of_cleanup.append, 'cleanup happened' |
|
) |
|
self.transfer_coordinator.add_failure_cleanup(cleanup_callback) |
|
submission_task() |
|
|
|
|
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
|
|
|
|
self.assertEqual(invocations_of_cleanup, ['cleanup happened']) |
|
|
|
def test_cleanups_only_ran_once_on_exception(self): |
|
|
|
|
|
|
|
|
|
|
|
final_task = self.get_task(FailureTask, is_final=True) |
|
self.main_kwargs['executor'] = self.executor |
|
self.main_kwargs['tasks_to_submit'] = [final_task] |
|
|
|
submission_task = self.get_task( |
|
ExceptionSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
|
|
subscriber = RecordingSubscriber() |
|
self.call_args.subscribers.append(subscriber) |
|
|
|
|
|
|
|
done_callbacks = get_callbacks(self.transfer_future, 'done') |
|
for done_callback in done_callbacks: |
|
self.transfer_coordinator.add_done_callback(done_callback) |
|
|
|
submission_task() |
|
|
|
|
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
|
|
|
|
self.assertEqual( |
|
subscriber.on_done_calls, [{'future': self.transfer_future}] |
|
) |
|
|
|
def test_done_callbacks_only_ran_once_on_exception(self): |
|
|
|
|
|
|
|
|
|
|
|
final_task = self.get_task(FailureTask, is_final=True) |
|
self.main_kwargs['executor'] = self.executor |
|
self.main_kwargs['tasks_to_submit'] = [final_task] |
|
|
|
submission_task = self.get_task( |
|
ExceptionSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
|
|
|
|
|
|
invocations_of_cleanup = [] |
|
cleanup_callback = FunctionContainer( |
|
invocations_of_cleanup.append, 'cleanup happened' |
|
) |
|
self.transfer_coordinator.add_failure_cleanup(cleanup_callback) |
|
submission_task() |
|
|
|
|
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
|
|
|
|
self.assertEqual(invocations_of_cleanup, ['cleanup happened']) |
|
|
|
def test_handles_cleanups_submitted_in_other_tasks(self): |
|
invocations_of_cleanup = [] |
|
event = Event() |
|
cleanup_callback = FunctionContainer( |
|
invocations_of_cleanup.append, 'cleanup happened' |
|
) |
|
|
|
|
|
task = self.get_task( |
|
SuccessTask, |
|
main_kwargs={ |
|
'callbacks': [event.set], |
|
'failure_cleanups': [cleanup_callback], |
|
}, |
|
) |
|
|
|
self.main_kwargs['executor'] = self.executor |
|
self.main_kwargs['tasks_to_submit'] = [task] |
|
self.main_kwargs['additional_callbacks'] = [event.wait] |
|
|
|
submission_task = self.get_task( |
|
ExceptionSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
|
|
submission_task() |
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
|
|
|
|
|
|
self.assertEqual(invocations_of_cleanup, ['cleanup happened']) |
|
|
|
def test_waits_for_tasks_submitted_by_other_tasks_on_exception(self): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invocations_of_cleanup = [] |
|
event = Event() |
|
cleanup_callback = FunctionContainer( |
|
invocations_of_cleanup.append, 'cleanup happened' |
|
) |
|
|
|
cleanup_task = self.get_task( |
|
SuccessTask, |
|
main_kwargs={ |
|
'callbacks': [event.set], |
|
'failure_cleanups': [cleanup_callback], |
|
}, |
|
) |
|
task_for_submitting_cleanup_task = self.get_task( |
|
SubmitMoreTasksTask, |
|
main_kwargs={ |
|
'executor': self.executor, |
|
'tasks_to_submit': [cleanup_task], |
|
}, |
|
) |
|
|
|
self.main_kwargs['executor'] = self.executor |
|
self.main_kwargs['tasks_to_submit'] = [ |
|
task_for_submitting_cleanup_task |
|
] |
|
self.main_kwargs['additional_callbacks'] = [event.wait] |
|
|
|
submission_task = self.get_task( |
|
ExceptionSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
|
|
submission_task() |
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
self.assertEqual(invocations_of_cleanup, ['cleanup happened']) |
|
|
|
def test_submission_task_announces_done_if_cancelled_before_main(self): |
|
invocations_of_done = [] |
|
done_callback = FunctionContainer( |
|
invocations_of_done.append, 'done announced' |
|
) |
|
self.transfer_coordinator.add_done_callback(done_callback) |
|
|
|
self.transfer_coordinator.cancel() |
|
submission_task = self.get_task( |
|
NOOPSubmissionTask, main_kwargs=self.main_kwargs |
|
) |
|
submission_task() |
|
|
|
|
|
|
|
|
|
self.assertEqual(invocations_of_done, ['done announced']) |
|
|
|
|
|
class TestTask(unittest.TestCase): |
|
def setUp(self): |
|
self.transfer_id = 1 |
|
self.transfer_coordinator = TransferCoordinator( |
|
transfer_id=self.transfer_id |
|
) |
|
|
|
def test_repr(self): |
|
main_kwargs = {'bucket': 'mybucket', 'param_to_not_include': 'foo'} |
|
task = ReturnKwargsTask( |
|
self.transfer_coordinator, main_kwargs=main_kwargs |
|
) |
|
|
|
|
|
self.assertEqual( |
|
repr(task), |
|
'ReturnKwargsTask(transfer_id={}, {})'.format( |
|
self.transfer_id, {'bucket': 'mybucket'} |
|
), |
|
) |
|
|
|
def test_transfer_id(self): |
|
task = SuccessTask(self.transfer_coordinator) |
|
|
|
|
|
self.assertEqual(task.transfer_id, self.transfer_id) |
|
|
|
def test_context_status_transitioning_success(self): |
|
|
|
self.transfer_coordinator.set_status_to_running() |
|
self.assertEqual(self.transfer_coordinator.status, 'running') |
|
|
|
|
|
SuccessTask(self.transfer_coordinator)() |
|
self.assertEqual(self.transfer_coordinator.status, 'running') |
|
|
|
|
|
SuccessTask(self.transfer_coordinator, is_final=True)() |
|
self.assertEqual(self.transfer_coordinator.status, 'success') |
|
|
|
def test_context_status_transitioning_failed(self): |
|
self.transfer_coordinator.set_status_to_running() |
|
|
|
SuccessTask(self.transfer_coordinator)() |
|
self.assertEqual(self.transfer_coordinator.status, 'running') |
|
|
|
|
|
FailureTask(self.transfer_coordinator)() |
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
|
|
|
|
SuccessTask(self.transfer_coordinator, is_final=True)() |
|
self.assertEqual(self.transfer_coordinator.status, 'failed') |
|
|
|
def test_result_setting_for_success(self): |
|
override_return = 'foo' |
|
SuccessTask(self.transfer_coordinator)() |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={'return_value': override_return}, |
|
is_final=True, |
|
)() |
|
|
|
|
|
|
|
self.assertEqual(self.transfer_coordinator.result(), override_return) |
|
|
|
def test_result_setting_for_error(self): |
|
FailureTask(self.transfer_coordinator)() |
|
|
|
|
|
|
|
FailureTask( |
|
self.transfer_coordinator, main_kwargs={'exception': Exception} |
|
)() |
|
|
|
|
|
|
|
SuccessTask(self.transfer_coordinator, is_final=True)() |
|
with self.assertRaises(TaskFailureException): |
|
self.transfer_coordinator.result() |
|
|
|
def test_done_callbacks_success(self): |
|
callback_results = [] |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
done_callbacks=[ |
|
partial(callback_results.append, 'first'), |
|
partial(callback_results.append, 'second'), |
|
], |
|
)() |
|
|
|
self.assertEqual(callback_results, ['first', 'second']) |
|
|
|
def test_done_callbacks_failure(self): |
|
callback_results = [] |
|
FailureTask( |
|
self.transfer_coordinator, |
|
done_callbacks=[ |
|
partial(callback_results.append, 'first'), |
|
partial(callback_results.append, 'second'), |
|
], |
|
)() |
|
|
|
self.assertEqual(callback_results, ['first', 'second']) |
|
|
|
|
|
SuccessTask( |
|
self.transfer_coordinator, |
|
done_callbacks=[ |
|
partial(callback_results.append, 'third'), |
|
partial(callback_results.append, 'fourth'), |
|
], |
|
)() |
|
self.assertEqual( |
|
callback_results, ['first', 'second', 'third', 'fourth'] |
|
) |
|
|
|
def test_failure_cleanups_on_failure(self): |
|
callback_results = [] |
|
self.transfer_coordinator.add_failure_cleanup( |
|
callback_results.append, 'first' |
|
) |
|
self.transfer_coordinator.add_failure_cleanup( |
|
callback_results.append, 'second' |
|
) |
|
FailureTask(self.transfer_coordinator)() |
|
|
|
|
|
self.assertEqual(callback_results, []) |
|
|
|
|
|
SuccessTask(self.transfer_coordinator, is_final=True)() |
|
self.assertEqual(callback_results, ['first', 'second']) |
|
|
|
def test_no_failure_cleanups_on_success(self): |
|
callback_results = [] |
|
self.transfer_coordinator.add_failure_cleanup( |
|
callback_results.append, 'first' |
|
) |
|
self.transfer_coordinator.add_failure_cleanup( |
|
callback_results.append, 'second' |
|
) |
|
SuccessTask(self.transfer_coordinator, is_final=True)() |
|
|
|
|
|
self.assertEqual(callback_results, []) |
|
|
|
def test_passing_main_kwargs(self): |
|
main_kwargs = {'foo': 'bar', 'baz': 'biz'} |
|
ReturnKwargsTask( |
|
self.transfer_coordinator, main_kwargs=main_kwargs, is_final=True |
|
)() |
|
|
|
self.assertEqual(self.transfer_coordinator.result(), main_kwargs) |
|
|
|
def test_passing_pending_kwargs_single_futures(self): |
|
pending_kwargs = {} |
|
ref_main_kwargs = {'foo': 'bar', 'baz': 'biz'} |
|
|
|
|
|
with futures.ThreadPoolExecutor(1) as executor: |
|
pending_kwargs['foo'] = executor.submit( |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={'return_value': ref_main_kwargs['foo']}, |
|
) |
|
) |
|
pending_kwargs['baz'] = executor.submit( |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={'return_value': ref_main_kwargs['baz']}, |
|
) |
|
) |
|
|
|
|
|
ReturnKwargsTask( |
|
self.transfer_coordinator, |
|
pending_main_kwargs=pending_kwargs, |
|
is_final=True, |
|
)() |
|
|
|
|
|
self.assertEqual(self.transfer_coordinator.result(), ref_main_kwargs) |
|
|
|
def test_passing_pending_kwargs_list_of_futures(self): |
|
pending_kwargs = {} |
|
ref_main_kwargs = {'foo': ['first', 'second']} |
|
|
|
|
|
with futures.ThreadPoolExecutor(1) as executor: |
|
first_future = executor.submit( |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={'return_value': ref_main_kwargs['foo'][0]}, |
|
) |
|
) |
|
second_future = executor.submit( |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={'return_value': ref_main_kwargs['foo'][1]}, |
|
) |
|
) |
|
|
|
pending_kwargs['foo'] = [first_future, second_future] |
|
|
|
|
|
ReturnKwargsTask( |
|
self.transfer_coordinator, |
|
pending_main_kwargs=pending_kwargs, |
|
is_final=True, |
|
)() |
|
|
|
|
|
self.assertEqual(self.transfer_coordinator.result(), ref_main_kwargs) |
|
|
|
def test_passing_pending_and_non_pending_kwargs(self): |
|
main_kwargs = {'nonpending_value': 'foo'} |
|
pending_kwargs = {} |
|
ref_main_kwargs = { |
|
'nonpending_value': 'foo', |
|
'pending_value': 'bar', |
|
'pending_list': ['first', 'second'], |
|
} |
|
|
|
|
|
with futures.ThreadPoolExecutor(1) as executor: |
|
pending_kwargs['pending_value'] = executor.submit( |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={ |
|
'return_value': ref_main_kwargs['pending_value'] |
|
}, |
|
) |
|
) |
|
|
|
first_future = executor.submit( |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={ |
|
'return_value': ref_main_kwargs['pending_list'][0] |
|
}, |
|
) |
|
) |
|
second_future = executor.submit( |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={ |
|
'return_value': ref_main_kwargs['pending_list'][1] |
|
}, |
|
) |
|
) |
|
|
|
pending_kwargs['pending_list'] = [first_future, second_future] |
|
|
|
|
|
|
|
ReturnKwargsTask( |
|
self.transfer_coordinator, |
|
main_kwargs=main_kwargs, |
|
pending_main_kwargs=pending_kwargs, |
|
is_final=True, |
|
)() |
|
|
|
|
|
self.assertEqual(self.transfer_coordinator.result(), ref_main_kwargs) |
|
|
|
def test_single_failed_pending_future(self): |
|
pending_kwargs = {} |
|
|
|
|
|
|
|
with futures.ThreadPoolExecutor(1) as executor: |
|
pending_kwargs['foo'] = executor.submit( |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={'return_value': 'bar'}, |
|
) |
|
) |
|
pending_kwargs['baz'] = executor.submit( |
|
FailureTask(self.transfer_coordinator) |
|
) |
|
|
|
|
|
ReturnKwargsTask( |
|
self.transfer_coordinator, |
|
pending_main_kwargs=pending_kwargs, |
|
is_final=True, |
|
)() |
|
|
|
|
|
with self.assertRaises(TaskFailureException): |
|
self.transfer_coordinator.result() |
|
|
|
def test_single_failed_pending_future_in_list(self): |
|
pending_kwargs = {} |
|
|
|
|
|
|
|
with futures.ThreadPoolExecutor(1) as executor: |
|
first_future = executor.submit( |
|
SuccessTask( |
|
self.transfer_coordinator, |
|
main_kwargs={'return_value': 'bar'}, |
|
) |
|
) |
|
second_future = executor.submit( |
|
FailureTask(self.transfer_coordinator) |
|
) |
|
|
|
pending_kwargs['pending_list'] = [first_future, second_future] |
|
|
|
|
|
ReturnKwargsTask( |
|
self.transfer_coordinator, |
|
pending_main_kwargs=pending_kwargs, |
|
is_final=True, |
|
)() |
|
|
|
|
|
with self.assertRaises(TaskFailureException): |
|
self.transfer_coordinator.result() |
|
|
|
|
|
class BaseMultipartTaskTest(BaseTaskTest): |
|
def setUp(self): |
|
super().setUp() |
|
self.bucket = 'mybucket' |
|
self.key = 'foo' |
|
|
|
|
|
class TestCreateMultipartUploadTask(BaseMultipartTaskTest): |
|
def test_main(self): |
|
upload_id = 'foo' |
|
extra_args = {'Metadata': {'foo': 'bar'}} |
|
response = {'UploadId': upload_id} |
|
task = self.get_task( |
|
CreateMultipartUploadTask, |
|
main_kwargs={ |
|
'client': self.client, |
|
'bucket': self.bucket, |
|
'key': self.key, |
|
'extra_args': extra_args, |
|
}, |
|
) |
|
self.stubber.add_response( |
|
method='create_multipart_upload', |
|
service_response=response, |
|
expected_params={ |
|
'Bucket': self.bucket, |
|
'Key': self.key, |
|
'Metadata': {'foo': 'bar'}, |
|
}, |
|
) |
|
result_id = task() |
|
self.stubber.assert_no_pending_responses() |
|
|
|
self.assertEqual(upload_id, result_id) |
|
|
|
|
|
self.assertEqual(len(self.transfer_coordinator.failure_cleanups), 1) |
|
|
|
|
|
self.stubber.add_response( |
|
method='abort_multipart_upload', |
|
service_response={}, |
|
expected_params={ |
|
'Bucket': self.bucket, |
|
'Key': self.key, |
|
'UploadId': upload_id, |
|
}, |
|
) |
|
self.transfer_coordinator.failure_cleanups[0]() |
|
self.stubber.assert_no_pending_responses() |
|
|
|
|
|
class TestCompleteMultipartUploadTask(BaseMultipartTaskTest): |
|
def test_main(self): |
|
upload_id = 'my-id' |
|
parts = [{'ETag': 'etag', 'PartNumber': 0}] |
|
task = self.get_task( |
|
CompleteMultipartUploadTask, |
|
main_kwargs={ |
|
'client': self.client, |
|
'bucket': self.bucket, |
|
'key': self.key, |
|
'upload_id': upload_id, |
|
'parts': parts, |
|
'extra_args': {}, |
|
}, |
|
) |
|
self.stubber.add_response( |
|
method='complete_multipart_upload', |
|
service_response={}, |
|
expected_params={ |
|
'Bucket': self.bucket, |
|
'Key': self.key, |
|
'UploadId': upload_id, |
|
'MultipartUpload': {'Parts': parts}, |
|
}, |
|
) |
|
task() |
|
self.stubber.assert_no_pending_responses() |
|
|
|
def test_includes_extra_args(self): |
|
upload_id = 'my-id' |
|
parts = [{'ETag': 'etag', 'PartNumber': 0}] |
|
task = self.get_task( |
|
CompleteMultipartUploadTask, |
|
main_kwargs={ |
|
'client': self.client, |
|
'bucket': self.bucket, |
|
'key': self.key, |
|
'upload_id': upload_id, |
|
'parts': parts, |
|
'extra_args': {'RequestPayer': 'requester'}, |
|
}, |
|
) |
|
self.stubber.add_response( |
|
method='complete_multipart_upload', |
|
service_response={}, |
|
expected_params={ |
|
'Bucket': self.bucket, |
|
'Key': self.key, |
|
'UploadId': upload_id, |
|
'MultipartUpload': {'Parts': parts}, |
|
'RequestPayer': 'requester', |
|
}, |
|
) |
|
task() |
|
self.stubber.assert_no_pending_responses() |
|
|