libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [2/6] git commit: Make 'DEFAULT_CONTENT_TYPE' a constant and add a test case for it.
Date Mon, 09 Dec 2013 14:25:03 GMT
Make 'DEFAULT_CONTENT_TYPE' a constant and add a test case for it.


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

Branch: refs/heads/trunk
Commit: 888b3d598ee0d67cea6ec899d1aa1ec330dd36c4
Parents: c5b2383
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Mon Dec 9 14:42:12 2013 +0100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Mon Dec 9 14:42:12 2013 +0100

----------------------------------------------------------------------
 libcloud/storage/base.py           | 15 +++++++++++----
 libcloud/test/storage/test_base.py | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/888b3d59/libcloud/storage/base.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/base.py b/libcloud/storage/base.py
index 88979a4..5b441a6 100644
--- a/libcloud/storage/base.py
+++ b/libcloud/storage/base.py
@@ -33,14 +33,21 @@ from libcloud.common.types import LibcloudError
 from libcloud.common.base import ConnectionUserAndKey, BaseDriver
 from libcloud.storage.types import ObjectDoesNotExistError
 
-CHUNK_SIZE = 8096
-
 __all__ = [
     'Object',
     'Container',
-    'StorageDriver'
+    'StorageDriver',
+
+    'CHUNK_SIZE',
+    'DEFAULT_CONTENT_TYPE'
 ]
 
+CHUNK_SIZE = 8096
+
+# Default Content-Type which is sent when upload an object if one is not
+# supplied and can't be detected
+DEFAULT_CONTENT_TYPE = 'application/octet-stream'
+
 
 class Object(object):
     """
@@ -600,7 +607,7 @@ class StorageDriver(BaseDriver):
             if not content_type:
                 # Fallback to a content-type that will cause most browsers to
                 # download it again as a binary file.
-                content_type = 'application/octet-stream'
+                content_type = DEFAULT_CONTENT_TYPE
 
         file_size = None
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/888b3d59/libcloud/test/storage/test_base.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_base.py b/libcloud/test/storage/test_base.py
index 05dfea7..9e4bd2d 100644
--- a/libcloud/test/storage/test_base.py
+++ b/libcloud/test/storage/test_base.py
@@ -27,6 +27,7 @@ if PY3:
     from io import FileIO as file
 
 from libcloud.storage.base import StorageDriver
+from libcloud.storage.base import DEFAULT_CONTENT_TYPE
 
 from libcloud.test import StorageMockHttp  # pylint: disable-msg=E0611
 
@@ -151,5 +152,23 @@ class BaseStorageTests(unittest.TestCase):
         else:
             self.fail('Invalid hash type but exception was not thrown')
 
+    def test_upload_default_content_type_is_specified_when_not_supplied(self):
+        iterator = StringIO()
+
+        upload_func = Mock()
+        upload_func.return_value = True, '', 0
+
+        self.driver1.connection = Mock()
+
+        self.driver1._upload_object(object_name='test',
+                                    content_type=None,
+                                    upload_func=upload_func,
+                                    upload_func_kwargs={},
+                                    request_path='/',
+                                    iterator=iterator)
+
+        headers = self.driver1.connection.request.call_args[-1]['headers']
+        self.assertEqual(headers['Content-Type'], DEFAULT_CONTENT_TYPE)
+
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message