Beispiel #1
0
def upload_file(self,
                Filename,
                Bucket,
                Key,
                ExtraArgs=None,
                Callback=None,
                Config=None):
    """Upload a file to an S3 object.

    Usage::

        import boto3_wasabi
        s3 = boto3_wasabi.resource('s3')
        s3.meta.client.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt')

    Similar behavior as S3Transfer's upload_file() method,
    except that parameters are capitalized. Detailed examples can be found at
    :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
    """
    with S3Transfer(self, Config) as transfer:
        return transfer.upload_file(filename=Filename,
                                    bucket=Bucket,
                                    key=Key,
                                    extra_args=ExtraArgs,
                                    callback=Callback)
Beispiel #2
0
 def test_context_manager(self):
     manager = mock.Mock()
     manager.__exit__ = mock.Mock()
     with S3Transfer(manager=manager):
         pass
     # The underlying transfer manager should have had its __exit__
     # called as well.
     self.assertEqual(
         manager.__exit__.call_args, mock.call(None, None, None))
Beispiel #3
0
 def test_context_manager_with_errors(self):
     manager = mock.Mock()
     manager.__exit__ = mock.Mock()
     raised_exception = ValueError()
     with self.assertRaises(type(raised_exception)):
         with S3Transfer(manager=manager):
             raise raised_exception
     # The underlying transfer manager should have had its __exit__
     # called as well and pass on the error as well.
     self.assertEqual(
         manager.__exit__.call_args,
         mock.call(type(raised_exception), raised_exception, mock.ANY))
Beispiel #4
0
 def setUp(self):
     self.client = mock.Mock()
     self.manager = mock.Mock(TransferManager(self.client))
     self.transfer = S3Transfer(manager=self.manager)
     self.callback = mock.Mock()
Beispiel #5
0
 def test_download_requires_string_filename(self):
     transfer = S3Transfer(client=mock.Mock())
     with self.assertRaises(ValueError):
         transfer.download_file(bucket='foo', key='bar', filename=object())
Beispiel #6
0
 def test_osutil_and_manager_are_mutually_exclusive(self):
     with self.assertRaises(ValueError):
         S3Transfer(osutil=mock.Mock(), manager=self.manager)
Beispiel #7
0
 def test_client_and_manager_are_mutually_exclusive(self):
     with self.assertRaises(ValueError):
         S3Transfer(self.client, manager=self.manager)
Beispiel #8
0
 def test_client_or_manager_is_required(self):
     with self.assertRaises(ValueError):
         S3Transfer()
Beispiel #9
0
 def test_can_create_with_extra_configurations(self):
     transfer = S3Transfer(
         client=mock.Mock(), config=TransferConfig(), osutil=OSUtils())
     self.assertIsInstance(transfer, S3Transfer)
Beispiel #10
0
 def test_can_create_with_just_client(self):
     transfer = S3Transfer(client=mock.Mock())
     self.assertIsInstance(transfer, S3Transfer)