libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1196320 - /libcloud/trunk/test/storage/test_base.py
Date Tue, 01 Nov 2011 22:09:43 GMT
Author: tomaz
Date: Tue Nov  1 22:09:43 2011
New Revision: 1196320

URL: http://svn.apache.org/viewvc?rev=1196320&view=rev
Log:
Add test for _upload_data.

Modified:
    libcloud/trunk/test/storage/test_base.py

Modified: libcloud/trunk/test/storage/test_base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/storage/test_base.py?rev=1196320&r1=1196319&r2=1196320&view=diff
==============================================================================
--- libcloud/trunk/test/storage/test_base.py (original)
+++ libcloud/trunk/test/storage/test_base.py Tue Nov  1 22:09:43 2011
@@ -28,7 +28,11 @@ class BaseStorageTests(unittest.TestCase
     def setUp(self):
         self.send_called = 0
         StorageDriver.connectionCls.conn_classes = (None, StorageMockHttp)
-        self.driver = StorageDriver('username', 'key', host='localhost')
+
+        self.driver1 = StorageDriver('username', 'key', host='localhost')
+        self.driver1.supports_chunked_encoding = True
+        self.driver2 = StorageDriver('username', 'key', host='localhost')
+        self.driver2.supports_chunked_encoding = False
 
     def test__upload_object_iterator_must_have_next_method(self):
         class Iterator(object):
@@ -54,13 +58,13 @@ class BaseStorageTests(unittest.TestCase
 
         for value in valid_iterators:
             kwargs['iterator'] = value
-            self.driver._upload_object(**kwargs)
+            self.driver1._upload_object(**kwargs)
 
         for value in invalid_iterators:
             kwargs['iterator'] = value
 
             try:
-                self.driver._upload_object(**kwargs)
+                self.driver1._upload_object(**kwargs)
             except AttributeError:
                 pass
             else:
@@ -78,7 +82,7 @@ class BaseStorageTests(unittest.TestCase
 
         # Normal
         success, data_hash, bytes_transferred = \
-                 self.driver._stream_data(response=response, iterator=iterator,
+                 self.driver1._stream_data(response=response, iterator=iterator,
                                           chunked=False, calculate_hash=True)
 
         self.assertTrue(success)
@@ -88,7 +92,7 @@ class BaseStorageTests(unittest.TestCase
 
         # Chunked
         success, data_hash, bytes_transferred = \
-                 self.driver._stream_data(response=response, iterator=iterator,
+                 self.driver1._stream_data(response=response, iterator=iterator,
                                           chunked=True, calculate_hash=True)
 
         self.assertTrue(success)
@@ -96,6 +100,23 @@ class BaseStorageTests(unittest.TestCase
         self.assertEqual(bytes_transferred, 0)
         self.assertEqual(self.send_called, 5)
 
+    def test__upload_data(self):
+        def mock_send(data):
+            self.send_called += 1
+
+        response = Mock()
+        response.connection.connection.send = mock_send
+
+        data = '123456789901234567'
+        success, data_hash, bytes_transferred = \
+                 self.driver1._upload_data(response=response, data=data,
+                                           calculate_hash=True)
+
+        self.assertTrue(success)
+        self.assertEqual(data_hash, hashlib.md5(data).hexdigest())
+        self.assertEqual(bytes_transferred, (len(data)))
+        self.assertEqual(self.send_called, 1)
+
 
 if __name__ == '__main__':
     sys.exit(unittest.main())



Mime
View raw message