dummy storage & storage tests

This commit is contained in:
James Turk 2012-02-15 15:01:50 -05:00
parent ac5bf809da
commit 39e812c891
3 changed files with 51 additions and 3 deletions

20
oyster/storage/dummy.py Normal file
View File

@ -0,0 +1,20 @@
import urllib
import boto
from oyster.conf import settings
class DummyStorage(object):
""" should NOT be used outside of testing """
storage_type = 'dummy'
def __init__(self, kernel):
self._storage = {}
def put(self, tracked_doc, data, content_type):
""" store the document in local dict """
self._storage[tracked_doc['_id']] = data
return tracked_doc['_id']
def get(self, id):
return self._storage[id]

View File

@ -93,9 +93,6 @@ class KernelTests(TestCase):
assert len(newobj['versions']) == 1
# check that document exists in storage (TODO: storage test)
assert self.kernel.storage.get(newobj['versions'][0]['storage_key'])
# check logs
assert self.kernel.db.logs.find({'action': 'update'}).count() == 1

View File

@ -0,0 +1,31 @@
from oyster.core import Kernel
from oyster.storage.s3 import S3Storage
from oyster.storage.gridfs import GridFSStorage
from oyster.storage.dummy import DummyStorage
def _simple_storage_test(StorageCls):
kernel = Kernel(mongo_db='oyster_test')
storage = StorageCls(kernel)
# ensure the class has a storage_type attribute
assert hasattr(storage, 'storage_type')
doc = {'_id': 'aabbccddeeff', 'url': 'http://localhost:8000/#test',
'metadata': {}
}
storage_id = storage.put(doc, 'hello oyster', 'text/plain')
assert storage_id
assert storage.get(storage_id) == 'hello oyster'
def test_s3():
_simple_storage_test(S3Storage)
def test_gridfs():
_simple_storage_test(GridFSStorage)
def test_dummy():
_simple_storage_test(DummyStorage)