From 39e812c891361f534156936deb78520e8e9b6ce4 Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 15 Feb 2012 15:01:50 -0500 Subject: [PATCH] dummy storage & storage tests --- oyster/storage/dummy.py | 20 ++++++++++++++++++++ oyster/tests/test_kernel.py | 3 --- oyster/tests/test_storage.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 oyster/storage/dummy.py create mode 100644 oyster/tests/test_storage.py diff --git a/oyster/storage/dummy.py b/oyster/storage/dummy.py new file mode 100644 index 0000000..7438cab --- /dev/null +++ b/oyster/storage/dummy.py @@ -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] diff --git a/oyster/tests/test_kernel.py b/oyster/tests/test_kernel.py index dd83c3e..dc2aff5 100644 --- a/oyster/tests/test_kernel.py +++ b/oyster/tests/test_kernel.py @@ -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 diff --git a/oyster/tests/test_storage.py b/oyster/tests/test_storage.py new file mode 100644 index 0000000..1d19c85 --- /dev/null +++ b/oyster/tests/test_storage.py @@ -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)