commit 78bd53a7bf4849752e3cfd00e6f4035e7a3090e1
Author: Sofia Papagiannaki <spapagian@grnet.gr>
Date:   Thu Oct 3 12:38:41 2013 +0300

    pithos: Provide more tests

diff --git a/snf-pithos-app/pithos/api/test/accounts.py b/snf-pithos-app/pithos/api/test/accounts.py
index c2d643b..d22b1d2 100644
--- a/snf-pithos-app/pithos/api/test/accounts.py
+++ b/snf-pithos-app/pithos/api/test/accounts.py
@@ -42,6 +42,7 @@ from synnefo.lib import join_urls
 import time as _time
 import datetime
 
+import django.utils.simplejson as json
 
 class AccountHead(PithosAPITest):
     def test_get_account_meta(self):
@@ -81,6 +82,17 @@ class AccountHead(PithosAPITest):
             usage)
 
     def test_get_account_meta_until(self):
+        cnames = ['apples', 'bananas', 'kiwis']
+
+        # create containers
+        uploaded_bytes = 0
+        for cname in cnames:
+            self.create_container(cname)
+
+            # upload object
+            name, data, resp = self.upload_object(cname)
+            uploaded_bytes += len(data)
+
         self.update_account_meta({'foo': 'bar'})
 
         account_info = self.get_account_info()
@@ -90,6 +102,15 @@ class AccountHead(PithosAPITest):
         until = int(_time.mktime(t1.timetuple()))
 
         _time.sleep(2)
+
+        # add containers
+        cnames = ['oranges', 'pears']
+        for cname in cnames:
+            self.create_container(cname)
+
+            # upload object
+            self.upload_object(cname)
+
         self.update_account_meta({'quality': 'AAA'})
 
         account_info = self.get_account_info()
@@ -108,6 +129,9 @@ class AccountHead(PithosAPITest):
         t = datetime.datetime.strptime(
             account_info['X-Account-Until-Timestamp'], DATE_FORMATS[2])
         self.assertTrue(int(_time.mktime(t1.timetuple())) <= until)
+        self.assertTrue('X-Account-Container-Count' in account_info)
+        self.assertEqual(int(account_info['X-Account-Container-Count']), 3)
+        self.assertTrue('X-Account-Bytes-Used' in account_info)
 
     def test_get_account_meta_until_invalid_date(self):
         self.update_account_meta({'quality': 'AAA'})
@@ -135,6 +159,36 @@ class AccountGet(PithosAPITest):
         self.assertEquals(containers,
                           ['apples', 'bananas', 'kiwis', 'oranges', 'pears'])
 
+    def test_list_until(self):
+        account_info = self.get_account_info()
+        t = datetime.datetime.strptime(account_info['Last-Modified'],
+                                       DATE_FORMATS[2])
+        t1 = t + datetime.timedelta(seconds=1)
+        until = int(_time.mktime(t1.timetuple()))
+
+        _time.sleep(2)
+
+        self.create_container()
+        
+        url = join_urls(self.pithos_path, self.user)
+        r = self.get('%s?until=%s' % (url, until))
+        self.assertEqual(r.status_code, 200)
+        containers = r.content.split('\n')
+        if '' in containers:
+            containers.remove('')
+        self.assertEqual(containers,
+                         ['apples', 'bananas', 'kiwis', 'oranges', 'pears'])
+
+        
+        r = self.get('%s?until=%s&format=json' % (url, until))
+        self.assertEqual(r.status_code, 200)
+        try:
+            containers = json.loads(r.content)
+        except:
+            self.fail('json format expected')
+        self.assertEqual([c['name'] for c in containers],
+                         ['apples', 'bananas', 'kiwis', 'oranges', 'pears']) 
+
     def test_list_shared(self):
         # upload and publish object
         oname, data, resp = self.upload_object('apples')
diff --git a/snf-pithos-app/pithos/api/test/containers.py b/snf-pithos-app/pithos/api/test/containers.py
index 8e6a56d..2de05be 100644
--- a/snf-pithos-app/pithos/api/test/containers.py
+++ b/snf-pithos-app/pithos/api/test/containers.py
@@ -83,6 +83,65 @@ class ContainerHead(PithosAPITest):
         (self.assertTrue('foo%s' % i in r['X-Container-Object-Meta'])
             for i in range(len(objects)))
 
+    def test_get_container_meta_until(self):
+        self.create_container('apples')
+
+        # populate with objects
+        objects = {}
+        metalist = []
+        for i in range(random.randint(1, 100)):
+            # upload object
+            metakey = 'foo%s' % i
+            meta = {metakey: 'bar'}
+            name, data, resp = self.upload_object('apples', **meta)
+            objects[name] = data
+            metalist.append(metakey) 
+
+        self.update_container_meta('apples', {'foo': 'bar'})
+
+        container_info = self.get_container_info('apples')
+        t = datetime.datetime.strptime(container_info['Last-Modified'],
+                                       DATE_FORMATS[2])
+        t1 = t + datetime.timedelta(seconds=1)
+        until = int(_time.mktime(t1.timetuple()))
+
+        _time.sleep(2)
+
+        for i in range(random.randint(1, 100)):
+            # upload object
+            meta = {'foo%s' % i: 'bar'}
+            self.upload_object('apples', **meta)
+
+        self.update_container_meta('apples', {'quality': 'AAA'})
+
+        container_info = self.get_container_info('apples')
+        self.assertTrue('X-Container-Meta-Quality' in container_info)
+        self.assertTrue('X-Container-Meta-Foo' in container_info)
+        self.assertTrue('X-Container-Object-Count' in container_info)
+        self.assertTrue(int(container_info['X-Container-Object-Count']) > len(objects))
+        self.assertTrue('X-Container-Bytes-Used' in container_info)
+
+        t = datetime.datetime.strptime(container_info['Last-Modified'],
+                                       DATE_FORMATS[-1])
+        last_modified = int(_time.mktime(t.timetuple()))
+        assert until < last_modified
+
+        container_info = self.get_container_info('apples', until=until)
+        self.assertTrue('X-Container-Meta-Quality' not in container_info)
+        self.assertTrue('X-Container-Meta-Foo' in container_info)
+        self.assertTrue('X-Container-Until-Timestamp' in container_info)
+        t = datetime.datetime.strptime(
+            container_info['X-Container-Until-Timestamp'], DATE_FORMATS[2])
+        self.assertTrue(int(_time.mktime(t1.timetuple())) <= until)
+        self.assertTrue('X-Container-Object-Count' in container_info)
+        self.assertEqual(int(container_info['X-Container-Object-Count']), len(objects))
+        self.assertTrue('X-Container-Bytes-Used' in container_info)
+        self.assertEqual(int(container_info['X-Container-Bytes-Used']),
+                         sum([len(data) for data in objects.values()]))
+        self.assertTrue('X-Container-Object-Meta' in container_info)
+        self.assertEqual(container_info['X-Container-Object-Meta'],
+                         metalist) 
+
 
 class ContainerGet(PithosAPITest):
     def setUp(self):
@@ -102,6 +161,36 @@ class ContainerGet(PithosAPITest):
             name, data, resp = self.upload_object('apples', o)
             self.objects['apples'][name] = data
 
+    def test_list_until(self):
+        account_info = self.get_account_info()
+        t = datetime.datetime.strptime(account_info['Last-Modified'],
+                                       DATE_FORMATS[2])
+        t1 = t + datetime.timedelta(seconds=1)
+        until = int(_time.mktime(t1.timetuple()))
+
+        _time.sleep(2)
+
+        cname = self.cnames[0]
+        self.upload_object(cname)
+
+        url = join_urls(self.pithos_path, self.user, cname)
+        r = self.get('%s?until=%s' % (url, until))
+        self.assertTrue(r.status_code, 200)
+        objects = r.content.split('\n')
+        if '' in objects:
+            objects.remove('')
+        self.assertEqual(objects,
+                         sorted(self.objects[cname].keys()))
+
+        r = self.get('%s?until=%s&format=json' % (url, until))
+        self.assertTrue(r.status_code, 200)
+        try:
+            objects = json.loads(r.content)
+        except:
+            self.fail('json format expected')
+        self.assertEqual([o['name'] for o in objects],
+                         sorted(self.objects[cname].keys()))
+
     def test_list_shared(self):
         # share an object
         cname = self.cnames[0]
