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 os
import types
import json
from simple import SimpleBackend
class TestAccount(unittest.TestCase):
def setUp(self):
self.basepath = './test/content'
self.b = BackEnd(self.basepath)
self.b = SimpleBackend(self.basepath)
self.account = 'account1'
def tearDown(self):
......@@ -15,7 +17,8 @@ class TestAccount(unittest.TestCase):
for container in containers:
try:
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):
self.b.delete_object(self.account, container, obj)
self.b.delete_container(self.account, container)
......@@ -57,15 +60,15 @@ class TestAccount(unittest.TestCase):
"groups": "http://hostname/gss/rest/aaitest@uth.gr/groups",
"creationDate": 1223372769275,
"modificationDate": 1223372769275,
"lastLogin": 1223372769275
}
"lastLogin": 1223372769275}
self.b.update_account_meta(self.account, meta)
d = self.b.get_account_meta(self.account)
for k,v in meta.iteritems():
self.assertEquals(unicode(v), d[k])
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):
meta = {
......@@ -80,8 +83,7 @@ class TestAccount(unittest.TestCase):
"groups": "http://hostname/gss/rest/aaitest@uth.gr/groups",
"creationDate": 1223372769275,
"modificationDate": 1223372769275,
"lastLogin": 1223372769275
}
"lastLogin": 1223372769275}
self.b.update_account_meta(self.account, meta)
p = os.path.join(self.basepath, self.account)
self.assertTrue(os.path.exists(p))
......@@ -95,7 +97,7 @@ class TestAccount(unittest.TestCase):
class TestContainer(unittest.TestCase):
def setUp(self):
self.basepath = './test/content'
self.b = BackEnd(self.basepath)
self.b = SimpleBackend(self.basepath)
self.account = 'account1'
def tearDown(self):
......@@ -103,7 +105,7 @@ class TestContainer(unittest.TestCase):
for container in containers:
try:
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):
self.b.delete_object(self.account, container, obj)
self.b.delete_container(self.account, container)
......@@ -157,17 +159,17 @@ class TestContainer(unittest.TestCase):
self.b.update_object(self.account, 'container1', item, item)
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='/')
self.assertEquals(['cats', 'dogs'], objects)
self.assertEquals(['photos/animals/cats/', 'photos/animals/dogs/'], objects)
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:
self.b.update_object(self.account, 'container2', item, item)
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):
cname = 'container1'
......@@ -193,7 +195,7 @@ class TestContainer(unittest.TestCase):
cname = 'container1'
self.b.create_container(self.account, cname)
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):
cname = 'container1'
......@@ -210,7 +212,7 @@ class TestContainer(unittest.TestCase):
class TestObject(unittest.TestCase):
def setUp(self):
self.basepath = './test/content'
self.b = BackEnd(self.basepath)
self.b = SimpleBackend(self.basepath)
self.account = 'account1'
def tearDown(self):
......@@ -218,7 +220,7 @@ class TestObject(unittest.TestCase):
for container in containers:
try:
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):
self.b.delete_object(self.account, container, obj)
self.b.delete_container(self.account, container)
......@@ -243,7 +245,6 @@ class TestObject(unittest.TestCase):
input = {'name':'kate_beckinsale.jpg'}
self.b.update_object(self.account, cname, input['name'], json.dumps(input))
meta = self.b.get_object_meta(self.account, cname, input['name'])
self.assertTrue('hash' in meta)
def test_copy_object(self):
src_cname = 'container1'
......@@ -291,7 +292,7 @@ class TestObject(unittest.TestCase):
self.b.create_container(self.account, dest_cname)
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.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,
prefix='photos/personal/',
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