Commit b031b9f8 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki Committed by Giorgos Verigakis
Browse files

Add unit tests for backend and API

* Tests the OpenStack Object Storage API v1 functionality plus the extras
* Tests the functionality of a BaseBackend which implements the API

Fixes #451
Fixes #453
parent 3c093bdb
This diff is collapsed.
from dummy import BackEnd
import unittest import unittest
import os import os
import types import types
import json import json
from simple import SimpleBackend
class TestAccount(unittest.TestCase): class TestAccount(unittest.TestCase):
def setUp(self): def setUp(self):
self.basepath = './test/content' self.basepath = './test/content'
self.b = BackEnd(self.basepath) self.b = SimpleBackend(self.basepath)
self.account = 'account1' self.account = 'account1'
def tearDown(self): def tearDown(self):
...@@ -15,7 +17,8 @@ class TestAccount(unittest.TestCase): ...@@ -15,7 +17,8 @@ class TestAccount(unittest.TestCase):
for container in containers: for container in containers:
try: try:
self.b.delete_container(self.account, container) self.b.delete_container(self.account, container)
except IndexError: # container not empty except IndexError:
# container not empty
for obj in self.b.list_objects(self.account, container): for obj in self.b.list_objects(self.account, container):
self.b.delete_object(self.account, container, obj) self.b.delete_object(self.account, container, obj)
self.b.delete_container(self.account, container) self.b.delete_container(self.account, container)
...@@ -57,15 +60,15 @@ class TestAccount(unittest.TestCase): ...@@ -57,15 +60,15 @@ class TestAccount(unittest.TestCase):
"groups": "http://hostname/gss/rest/aaitest@uth.gr/groups", "groups": "http://hostname/gss/rest/aaitest@uth.gr/groups",
"creationDate": 1223372769275, "creationDate": 1223372769275,
"modificationDate": 1223372769275, "modificationDate": 1223372769275,
"lastLogin": 1223372769275 "lastLogin": 1223372769275}
}
self.b.update_account_meta(self.account, meta) self.b.update_account_meta(self.account, meta)
d = self.b.get_account_meta(self.account) d = self.b.get_account_meta(self.account)
for k,v in meta.iteritems(): for k,v in meta.iteritems():
self.assertEquals(unicode(v), d[k]) self.assertEquals(unicode(v), d[k])
def test_get_non_existing_account_meta(self): def test_get_non_existing_account_meta(self):
self.assertRaises(NameError, self.b.get_account_meta, 'account2') meta = self.b.get_account_meta('account2')
self.assertEquals(meta, {'name': 'account2', 'count': 0, 'bytes': 0})
def test_update_account_meta(self): def test_update_account_meta(self):
meta = { meta = {
...@@ -80,8 +83,7 @@ class TestAccount(unittest.TestCase): ...@@ -80,8 +83,7 @@ class TestAccount(unittest.TestCase):
"groups": "http://hostname/gss/rest/aaitest@uth.gr/groups", "groups": "http://hostname/gss/rest/aaitest@uth.gr/groups",
"creationDate": 1223372769275, "creationDate": 1223372769275,
"modificationDate": 1223372769275, "modificationDate": 1223372769275,
"lastLogin": 1223372769275 "lastLogin": 1223372769275}
}
self.b.update_account_meta(self.account, meta) self.b.update_account_meta(self.account, meta)
p = os.path.join(self.basepath, self.account) p = os.path.join(self.basepath, self.account)
self.assertTrue(os.path.exists(p)) self.assertTrue(os.path.exists(p))
...@@ -95,7 +97,7 @@ class TestAccount(unittest.TestCase): ...@@ -95,7 +97,7 @@ class TestAccount(unittest.TestCase):
class TestContainer(unittest.TestCase): class TestContainer(unittest.TestCase):
def setUp(self): def setUp(self):
self.basepath = './test/content' self.basepath = './test/content'
self.b = BackEnd(self.basepath) self.b = SimpleBackend(self.basepath)
self.account = 'account1' self.account = 'account1'
def tearDown(self): def tearDown(self):
...@@ -103,7 +105,7 @@ class TestContainer(unittest.TestCase): ...@@ -103,7 +105,7 @@ class TestContainer(unittest.TestCase):
for container in containers: for container in containers:
try: try:
self.b.delete_container(self.account, container) self.b.delete_container(self.account, container)
except Exception: # container not empty except IndexError: # container not empty
for obj in self.b.list_objects(self.account, container): for obj in self.b.list_objects(self.account, container):
self.b.delete_object(self.account, container, obj) self.b.delete_object(self.account, container, obj)
self.b.delete_container(self.account, container) self.b.delete_container(self.account, container)
...@@ -157,17 +159,17 @@ class TestContainer(unittest.TestCase): ...@@ -157,17 +159,17 @@ class TestContainer(unittest.TestCase):
self.b.update_object(self.account, 'container1', item, item) self.b.update_object(self.account, 'container1', item, item)
objects = self.b.list_objects(self.account, 'container1', prefix='photos/', delimiter='/') objects = self.b.list_objects(self.account, 'container1', prefix='photos/', delimiter='/')
self.assertEquals(['animals', 'me.jpg', 'plants'], objects) self.assertEquals(['photos/animals/', 'photos/me.jpg', 'photos/plants/'], objects)
objects = self.b.list_objects(self.account, 'container1', prefix='photos/animals/', delimiter='/') objects = self.b.list_objects(self.account, 'container1', prefix='photos/animals/', delimiter='/')
self.assertEquals(['cats', 'dogs'], objects) self.assertEquals(['photos/animals/cats/', 'photos/animals/dogs/'], objects)
self.b.create_container(self.account, 'container2') self.b.create_container(self.account, 'container2')
l = ['photos/photo1', 'photos/photo2', 'movieobject', 'videos/movieobj4'] l = ['photos/photo1', 'photos/photo2', 'movieobject', 'videos', 'videos/movieobj4']
for item in l: for item in l:
self.b.update_object(self.account, 'container2', item, item) self.b.update_object(self.account, 'container2', item, item)
objects = self.b.list_objects(self.account, 'container2', delimiter='/') objects = self.b.list_objects(self.account, 'container2', delimiter='/')
self.assertEquals(['movieobject', 'photos', 'videos'], objects) self.assertEquals(['movieobject', 'photos/', 'videos', 'videos/'], objects)
def test_create_container(self): def test_create_container(self):
cname = 'container1' cname = 'container1'
...@@ -193,7 +195,7 @@ class TestContainer(unittest.TestCase): ...@@ -193,7 +195,7 @@ class TestContainer(unittest.TestCase):
cname = 'container1' cname = 'container1'
self.b.create_container(self.account, cname) self.b.create_container(self.account, cname)
self.b.update_object(self.account, cname, 'object1', 'alkhadlkhalkdhal') self.b.update_object(self.account, cname, 'object1', 'alkhadlkhalkdhal')
self.assertRaises(Exception, self.b.delete_container, self.account, cname) self.assertRaises(IndexError, self.b.delete_container, self.account, cname)
def test_get_container_meta(self): def test_get_container_meta(self):
cname = 'container1' cname = 'container1'
...@@ -210,7 +212,7 @@ class TestContainer(unittest.TestCase): ...@@ -210,7 +212,7 @@ class TestContainer(unittest.TestCase):
class TestObject(unittest.TestCase): class TestObject(unittest.TestCase):
def setUp(self): def setUp(self):
self.basepath = './test/content' self.basepath = './test/content'
self.b = BackEnd(self.basepath) self.b = SimpleBackend(self.basepath)
self.account = 'account1' self.account = 'account1'
def tearDown(self): def tearDown(self):
...@@ -218,7 +220,7 @@ class TestObject(unittest.TestCase): ...@@ -218,7 +220,7 @@ class TestObject(unittest.TestCase):
for container in containers: for container in containers:
try: try:
self.b.delete_container(self.account, container) self.b.delete_container(self.account, container)
except Exception: # container not empty except IndexError: # container not empty
for obj in self.b.list_objects(self.account, container): for obj in self.b.list_objects(self.account, container):
self.b.delete_object(self.account, container, obj) self.b.delete_object(self.account, container, obj)
self.b.delete_container(self.account, container) self.b.delete_container(self.account, container)
...@@ -243,7 +245,6 @@ class TestObject(unittest.TestCase): ...@@ -243,7 +245,6 @@ class TestObject(unittest.TestCase):
input = {'name':'kate_beckinsale.jpg'} input = {'name':'kate_beckinsale.jpg'}
self.b.update_object(self.account, cname, input['name'], json.dumps(input)) self.b.update_object(self.account, cname, input['name'], json.dumps(input))
meta = self.b.get_object_meta(self.account, cname, input['name']) meta = self.b.get_object_meta(self.account, cname, input['name'])
self.assertTrue('hash' in meta)
def test_copy_object(self): def test_copy_object(self):
src_cname = 'container1' src_cname = 'container1'
...@@ -291,7 +292,7 @@ class TestObject(unittest.TestCase): ...@@ -291,7 +292,7 @@ class TestObject(unittest.TestCase):
self.b.create_container(self.account, dest_cname) self.b.create_container(self.account, dest_cname)
self.b.update_object_meta(self.account, src_cname, src_obj, {'tag':'sfsfssf'}) self.b.update_object_meta(self.account, src_cname, src_obj, {'tag':'sfsfssf'})
self.b.copy_object(self.account, src_cname, src_obj, dest_cname, dest_obj) self.b.copy_object(self.account, src_cname, src_obj, dest_cname, dest_obj)
self.assertTrue(dest_obj.split('/')[-1] in self.b.list_objects(self.account, self.assertTrue(dest_obj in self.b.list_objects(self.account,
dest_cname, dest_cname,
prefix='photos/personal/', prefix='photos/personal/',
delimiter='/')) delimiter='/'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment