Started testing object_copy +minor fixes
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 24 Jul 2012 16:06:00 +0000 (19:06 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 24 Jul 2012 16:06:00 +0000 (19:06 +0300)
kamaki/cli.py
kamaki/clients/pithos.py
kamaki/clients/tests.py

index 149b987..b0f3a67 100755 (executable)
@@ -1036,8 +1036,7 @@ class store_test(_store_account_command):
         super(store_test, self).main()
         self.client.container = 'testCo'
 
-        r = self.client.object_put('lali', content_length=1, data='a',
-            content_type='application/octet-stream', permitions={'read':'u1, u2', 'write':'u2, u3'})
+        r = self.client.object_copy('lolens', destination='/testCo/lali', if_etag_not_match='lalala', format='xml')
         print(unicode(r))
 
 @command(api='storage')
index 7c15109..d12181b 100644 (file)
@@ -380,8 +380,8 @@ class PithosClient(StorageClient):
         success = kwargs.pop('success', 201)
         return self.put(path, *args, success=success, **kwargs)
 
-    def object_copy(self, object, format='json', ignore_content_type=False,
-        if_etag_match=None, if_etag_not_match=None, destination=None, destination_account=None,
+    def object_copy(self, object, destination, format='json', ignore_content_type=False,
+        if_etag_match=None, if_etag_not_match=None, destination_account=None,
         content_type=None, content_encoding=None, content_disposition=None, source_version=None,
         manifest=None, permitions={}, public=False, metadata={}, *args, **kwargs):
         """ Full Pithos+ COPY at object level
@@ -389,9 +389,9 @@ class PithosClient(StorageClient):
         @param format (string): json (default) or xml
         @param ignore_content_type (bool): Ignore the supplied Content-Type
         --- request headers ---
-         @param if_etag_match (string): if provided, return only results
+         @param if_etag_match (string): if provided, copy only results
                 with etag matching with this
-        @param if_etag_not_match (string): if provided, return only results
+        @param if_etag_not_match (string): if provided, copy only results
                 with etag not matching with this
         @param destination (string): The destination path in the form /<container>/<object>
         @param destination_account (string): The destination account to copy to
index d04665f..bd55f05 100644 (file)
@@ -532,6 +532,70 @@ class testPithos(unittest.TestCase):
         self.client.container = ''
         self.client.reset_headers()
 
+    def test_object_copy(self):
+        self.client.container='testCo0'
+        obj = 'obj'+unicode(self.now)
+
+        
+        data= '{"key1":"val1", "key2":"val2"}'
+        r = self.client.object_put(obj+'orig', content_type='application/octet-stream', data= data)
+        self.client.reset_headers()
+        r = self.client.object_copy(obj+'orig', destination = '/'+self.client.container+'/'+obj, ignore_content_type=False, content_type='application/json')
+        self.assertEqual(r.status_code, 201)
+        self.client.reset_headers()
+
+        """Check destination account"""
+        r = self.client.object_copy(obj, destination='/testCo/'+obj, content_encoding='utf8',
+            content_type='application/json', destination_account='nonExistendAddress@NeverLand.com',
+            success=(201, 403))
+        self.assertEqual(r.status_code, 403)
+        self.client.reset_headers()
+
+        """Check destination being another container and also content_type and content encoding"""
+        r = self.client.object_copy(obj, destination='/testCo/'+obj, content_encoding='utf8', content_type='application/json')
+        self.assertEqual(r.status_code, 201)
+        self.assertEqual(r.headers['content-type'], 'application/json; charset=UTF-8')
+        self.client.reset_headers()
+        r = self.client.container='testCo'
+        self.client.delete_object(obj)
+        r = self.client.container='testCo0'
+        self.client.reset_headers()
+
+        """Check ignore_content_type and content_type"""
+        r = self.client.object_get(obj)
+        etag = r.headers['etag']
+        ctype = r.headers['content-type']
+        self.assertEqual(ctype, 'application/json')
+        self.client.reset_headers()
+        r = self.client.object_copy(obj+'orig', destination = '/'+self.client.container+'/'+obj+'0',
+            ignore_content_type=True, content_type='application/json')
+        self.assertEqual(r.status_code, 201)
+        self.assertNotEqual(r.headers['content-type'], 'application/json')
+        self.client.reset_headers()
+
+        """Check if_etag_(not_)match"""
+        r = self.client.object_copy(obj, destination='/'+self.client.container+'/'+obj+'1', if_etag_match=etag)
+        self.assertEqual(r.status_code, 201)
+        self.client.reset_headers()
+        r = self.client.object_copy(obj, destination='/'+self.client.container+'/'+obj+'2', if_etag_not_match='lalala')
+        self.assertEqual(r.status_code, 201)
+        vers2 = r.headers['x-object-version']
+        self.client.reset_headers()
+
+        """Check source_version and format (?)"""
+        r = self.client.object_copy(obj+'2', destination='/'+self.client.container+'/'+obj+'3', source_version=vers2)
+        self.assertEqual(r.status_code, 201)
+
+        """Still untested: format, content_disposition, manifest, permitions, public, metadata"""
+
+        self.client.delete_object(obj)
+        self.client.delete_object(obj+'0')
+        self.client.delete_object(obj+'1')
+        self.client.delete_object(obj+'2')
+        self.client.delete_object(obj+'3')
+        self.client.delete_object(obj+'orig')
+        self.client.container = ''
+
 class testCyclades(unittest.TestCase):
     def setUp(self):
         pass
@@ -560,6 +624,7 @@ if __name__ == '__main__':
     suiteFew.addTest(testPithos('test_object_head'))
     suiteFew.addTest(testPithos('test_object_get'))
     suiteFew.addTest(testPithos('test_object_put'))
+    suiteFew.addTest(testPithos('test_object_copy'))
 
     #kamaki/cyclades.py
     #suiteFew.addTest(testCyclades('test_list_servers'))