libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/6] git commit: LIBCLOUD-433: Make storage backend send content-type of "application/octet-stream" if none is supplied and none can be guessed.
Date Mon, 09 Dec 2013 14:25:02 GMT
Updated Branches:
  refs/heads/trunk 9e4397034 -> 90df4f66c


LIBCLOUD-433: Make storage backend send content-type of
"application/octet-stream" if none is supplied and none can be guessed.

Also update affected tests.

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


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

Branch: refs/heads/trunk
Commit: c5b2383847eded88f1f570c6dca4450848a82508
Parents: 9e43970
Author: Michael Farrell <micolous+git@gmail.com>
Authored: Wed Nov 6 12:01:20 2013 +1030
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Mon Dec 9 14:22:27 2013 +0100

----------------------------------------------------------------------
 libcloud/storage/base.py                 |  6 +++---
 libcloud/test/storage/test_atmos.py      | 19 ++++++++-----------
 libcloud/test/storage/test_cloudfiles.py | 18 +++++++-----------
 3 files changed, 18 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5b23838/libcloud/storage/base.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/base.py b/libcloud/storage/base.py
index 3408d24..88979a4 100644
--- a/libcloud/storage/base.py
+++ b/libcloud/storage/base.py
@@ -598,9 +598,9 @@ class StorageDriver(BaseDriver):
             content_type, _ = libcloud.utils.files.guess_file_mime_type(name)
 
             if not content_type:
-                raise AttributeError(
-                    'File content-type could not be guessed and' +
-                    ' no content_type value provided')
+                # Fallback to a content-type that will cause most browsers to
+                # download it again as a binary file.
+                content_type = 'application/octet-stream'
 
         file_size = None
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5b23838/libcloud/test/storage/test_atmos.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_atmos.py b/libcloud/test/storage/test_atmos.py
index d19a5f8..561ac2f 100644
--- a/libcloud/test/storage/test_atmos.py
+++ b/libcloud/test/storage/test_atmos.py
@@ -316,17 +316,14 @@ class AtmosTests(unittest.TestCase):
         file_path = os.path.abspath(__file__)
         container = Container(name='fbc', extra={}, driver=self)
         object_name = 'ftu'
-        try:
-            self.driver.upload_object(file_path=file_path, container=container,
-                                      object_name=object_name)
-        except AttributeError:
-            pass
-        else:
-            self.fail(
-                'File content type not provided'
-                ' but an exception was not thrown')
-        finally:
-            libcloud.utils.files.guess_file_mime_type = old_func
+        obj = self.driver.upload_object(file_path=file_path,
+                                        container=container,
+                                        object_name=object_name)
+
+        # Just check that the file was uploaded OK, as the fallback
+        # Content-Type header should be set (application/octet-stream).
+        self.assertEqual(obj.name, object_name)
+        libcloud.utils.files.guess_file_mime_type = old_func
 
     def test_upload_object_error(self):
         def dummy_content_type(name):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5b23838/libcloud/test/storage/test_cloudfiles.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_cloudfiles.py b/libcloud/test/storage/test_cloudfiles.py
index 29143cc..c71b71e 100644
--- a/libcloud/test/storage/test_cloudfiles.py
+++ b/libcloud/test/storage/test_cloudfiles.py
@@ -439,17 +439,13 @@ class CloudFilesTests(unittest.TestCase):
         file_path = os.path.abspath(__file__)
         container = Container(name='foo_bar_container', extra={}, driver=self)
         object_name = 'foo_test_upload'
-        try:
-            self.driver.upload_object(file_path=file_path, container=container,
-                                      object_name=object_name)
-        except AttributeError:
-            pass
-        else:
-            self.fail(
-                'File content type not provided'
-                ' but an exception was not thrown')
-        finally:
-            libcloud.utils.files.guess_file_mime_type = old_func
+
+        obj = self.driver.upload_object(file_path=file_path, verify_hash=False,
+                                        container=container,
+                                        object_name=object_name)
+
+        self.assertEqual(obj.name, object_name)
+        libcloud.utils.files.guess_file_mime_type = old_func
 
     def test_upload_object_error(self):
         def dummy_content_type(name):


Mime
View raw message