libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [1/2] libcloud git commit: guess s3 multipart upload content type.
Date Fri, 30 Mar 2018 05:07:22 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk f95203052 -> 9ffc89c6d


guess s3 multipart upload content type.

Signed-off-by: Quentin Pradet <quentinp@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/100f45fa
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/100f45fa
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/100f45fa

Branch: refs/heads/trunk
Commit: 100f45fa53bd1a048b470bf4a1823afe12539c61
Parents: f952030
Author: Iuri de Silvio <iurisilvio@gmail.com>
Authored: Mon Nov 6 15:53:21 2017 -0200
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Fri Mar 30 09:06:47 2018 +0400

----------------------------------------------------------------------
 libcloud/storage/drivers/s3.py   |  4 ++++
 libcloud/test/storage/test_s3.py | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/100f45fa/libcloud/storage/drivers/s3.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/s3.py b/libcloud/storage/drivers/s3.py
index e4d48a4..6b94157 100644
--- a/libcloud/storage/drivers/s3.py
+++ b/libcloud/storage/drivers/s3.py
@@ -869,6 +869,10 @@ class BaseS3StorageDriver(StorageDriver):
         meta_data = extra.get('meta_data', None)
         acl = extra.get('acl', None)
 
+        if not content_type:
+            content_type, _ = libcloud.utils.files.guess_file_mime_type(
+                object_name)
+
         if content_type:
             headers['Content-Type'] = content_type
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/100f45fa/libcloud/test/storage/test_s3.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_s3.py b/libcloud/test/storage/test_s3.py
index 984b8ad..2b0a5da 100644
--- a/libcloud/test/storage/test_s3.py
+++ b/libcloud/test/storage/test_s3.py
@@ -21,8 +21,10 @@ import sys
 from io import BytesIO
 from hashlib import sha1
 
+import mock
 from mock import Mock
 from mock import PropertyMock
+import libcloud.utils.files
 
 from libcloud.utils.py3 import ET
 from libcloud.utils.py3 import httplib
@@ -905,6 +907,25 @@ class S3Tests(unittest.TestCase):
         self.assertEqual(obj.name, object_name)
         self.assertEqual(obj.size, CHUNK_SIZE * 3)
 
+    def test_upload_object_via_stream_guess_file_mime_type(self):
+        if self.driver.supports_s3_multipart_upload:
+            self.mock_response_klass.type = 'MULTIPART'
+        else:
+            self.mock_response_klass.type = None
+
+        container = Container(name='foo_bar_container', extra={},
+                              driver=self.driver)
+        object_name = 'foo_test_stream_data'
+        iterator = BytesIO(b('234'))
+
+        with mock.patch('libcloud.utils.files.guess_file_mime_type', autospec=True) as mock_guess_file_mime_type:
+            mock_guess_file_mime_type.return_value = ('application/zip', None)
+
+            self.driver.upload_object_via_stream(container=container,
+                                                 object_name=object_name,
+                                                 iterator=iterator)
+            mock_guess_file_mime_type.assert_called_with(object_name)
+
     def test_upload_object_via_stream_abort(self):
         if not self.driver.supports_s3_multipart_upload:
             return


Mime
View raw message