You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2018/01/08 10:14:19 UTC

libcloud git commit: Also add no memory buffer storage test case for Google Storage driver.

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


Also add no memory buffer storage test case for Google Storage driver.


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

Branch: refs/heads/trunk
Commit: ad689715e2a6e207c61bd6d7cf894df5cccda5d2
Parents: 98a07ac
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Mon Jan 8 11:12:03 2018 +0100
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Mon Jan 8 11:12:03 2018 +0100

----------------------------------------------------------------------
 libcloud/test/storage/test_google_storage.py | 35 +++++++++++++++++++++++
 libcloud/test/storage/test_s3.py             | 11 +++----
 2 files changed, 41 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/ad689715/libcloud/test/storage/test_google_storage.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_google_storage.py b/libcloud/test/storage/test_google_storage.py
index 19eb7df..da03b2b 100644
--- a/libcloud/test/storage/test_google_storage.py
+++ b/libcloud/test/storage/test_google_storage.py
@@ -16,6 +16,7 @@
 import copy
 import json
 import mock
+import os
 import re
 import sys
 import unittest
@@ -24,10 +25,13 @@ from io import BytesIO
 
 import email.utils
 import pytest
+from mock import Mock
+from mock import PropertyMock
 
 from libcloud.common.google import GoogleAuthType
 from libcloud.common.types import InvalidCredsError
 from libcloud.storage.base import Container
+from libcloud.storage.base import Object
 from libcloud.storage.drivers import google_storage
 from libcloud.test import StorageMockHttp
 from libcloud.test.common.test_google import GoogleTestCase
@@ -35,6 +39,7 @@ from libcloud.test.file_fixtures import StorageFileFixtures
 from libcloud.test.secrets import STORAGE_GOOGLE_STORAGE_PARAMS
 from libcloud.test.storage.test_s3 import S3Tests, S3MockHttp
 from libcloud.utils.py3 import httplib
+from libcloud.utils.py3 import StringIO
 
 CONN_CLS = google_storage.GoogleStorageConnection
 JSON_CONN_CLS = google_storage.GoogleStorageJSONConnection
@@ -488,6 +493,36 @@ class GoogleStorageTests(S3Tests, GoogleTestCase):
             self.driver.upload_object_via_stream(
                 BytesIO(b' '), container, 'path')
 
+    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(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 = PropertyMock(name='mock content attribute',
+                                                   side_effect=Exception(msg))
+        mock_response.iter_content.return_value = StringIO('a' * 1000)
+
+        self.driver.connection.connection.getresponse = 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)
+
 
 if __name__ == '__main__':
     sys.exit(unittest.main())

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ad689715/libcloud/test/storage/test_s3.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_s3.py b/libcloud/test/storage/test_s3.py
index 45e9312..acb44a6 100644
--- a/libcloud/test/storage/test_s3.py
+++ b/libcloud/test/storage/test_s3.py
@@ -21,7 +21,8 @@ import sys
 from io import BytesIO
 from hashlib import sha1
 
-import mock
+from mock import Mock
+from mock import PropertyMock
 
 from libcloud.utils.py3 import ET
 from libcloud.utils.py3 import httplib
@@ -638,15 +639,15 @@ class S3Tests(unittest.TestCase):
         # 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 = 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))
+        type(mock_response).content = 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 = Mock()
         self.driver.connection.connection.getresponse.return_value = mock_response
 
         container = Container(name='foo_bar_container', extra={},