Repository: libcloud
Updated Branches:
  refs/heads/trunk 4732d83be -> 98a07ac37


Add a test case for #1132.


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

Branch: refs/heads/trunk
Commit: 98a07ac377a58076e248673a55a9428c9e8dfe21
Parents: 4732d83
Author: Tomaz Muraus <[email protected]>
Authored: Sun Jan 7 21:28:57 2018 +0100
Committer: Tomaz Muraus <[email protected]>
Committed: Sun Jan 7 21:28:57 2018 +0100

----------------------------------------------------------------------
 libcloud/test/storage/test_s3.py | 42 ++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/98a07ac3/libcloud/test/storage/test_s3.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_s3.py b/libcloud/test/storage/test_s3.py
index d32a99c..45e9312 100644
--- a/libcloud/test/storage/test_s3.py
+++ b/libcloud/test/storage/test_s3.py
@@ -19,13 +19,15 @@ import os
 import sys
 
 from io import BytesIO
-
 from hashlib import sha1
 
+import mock
+
 from libcloud.utils.py3 import ET
 from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import urlparse
 from libcloud.utils.py3 import parse_qs
+from libcloud.utils.py3 import StringIO
 
 from libcloud.common.types import InvalidCredsError
 from libcloud.common.types import LibcloudError, MalformedResponseError
@@ -323,6 +325,14 @@ class S3MockHttp(MockHttp):
                 headers,
                 httplib.responses[httplib.OK])
 
+    def _foo_bar_container_foo_bar_object_NO_BUFFER(self, method, url, body, 
headers):
+        # test_download_object_data_is_not_buffered_in_memory
+        body = generate_random_data(1000)
+        return (httplib.OK,
+                body,
+                headers,
+                httplib.responses[httplib.OK])
+
     def _foo_bar_container_foo_test_upload_INVALID_HASH1(self, method, url,
                                                          body, headers):
         body = ''
@@ -621,6 +631,36 @@ class S3Tests(unittest.TestCase):
                                              delete_on_failure=True)
         self.assertTrue(result)
 
+    def test_download_object_data_is_not_buffered_in_memory(self):
+        # Test case which verifies that response.body attribute is not accessed
+        # and as such, whole body response is not buffered into RAM
+
+        # If content is consumed and response.content attribute accessed 
execption
+        # will be thrown and test will fail
+
+        mock_response = mock.Mock(name='mock response')
+        mock_response.headers = {}
+        mock_response.status_code = 200
+        msg = '"content" attribute was accessed but it shouldn\'t have been'
+        type(mock_response).content = mock.PropertyMock(name='mock content 
attribute',
+                                                        
side_effect=Exception(msg))
+        mock_response.iter_content.return_value = StringIO('a' * 1000)
+
+        self.driver.connection.connection.getresponse = mock.Mock()
+        self.driver.connection.connection.getresponse.return_value = 
mock_response
+
+        container = Container(name='foo_bar_container', extra={},
+                              driver=self.driver)
+        obj = Object(name='foo_bar_object_NO_BUFFER', size=1000, hash=None, 
extra={},
+                     container=container, meta_data=None,
+                     driver=self.driver_type)
+        destination_path = os.path.abspath(__file__) + '.temp'
+        result = self.driver.download_object(obj=obj,
+                                             destination_path=destination_path,
+                                             overwrite_existing=False,
+                                             delete_on_failure=True)
+        self.assertTrue(result)
+
     def test_download_object_invalid_file_size(self):
         self.mock_response_klass.type = 'INVALID_SIZE'
         container = Container(name='foo_bar_container', extra={},

Reply via email to