Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed a couple import bugs with mongo/sqla and updated integration te…

…sts.
  • Loading branch information...
commit 93a8fc2c23e5926f984488ab957e724cd0a491dd 1 parent e98075a
@mmerickel mmerickel authored
View
4 anykeystore/backends/mongodb.py
@@ -29,7 +29,9 @@ def __init__(self,
@classmethod
def backend_api(cls):
- return __import__('pymongo')
+ import pymongo
+ import pymongo.binary
+ return pymongo
def _get_conn(self):
db_conn = self.backend_api.Connection(
View
8 anykeystore/backends/sqla.py
@@ -44,7 +44,9 @@ def __init__(self, url, **kw):
@classmethod
def backend_api(cls):
- return __import__('sqlalchemy')
+ import sqlalchemy
+ import sqlalchemy.exc
+ return sqlalchemy
def _make_table(self, name, meta):
api = self.backend_api
@@ -109,9 +111,11 @@ def delete(self, key):
def purge_expired(self):
c = self._get_conn()
+ api = self.backend_api
try:
c.execute(
- delete(self.table, self.table.c.expires < datetime.utcnow()))
+ api.delete(
+ self.table, self.table.c.expires < datetime.utcnow()))
finally:
c.close()
View
2  anykeystore/store.py
@@ -34,7 +34,7 @@ def _load_entry_point(name):
def create_store(name, **kwargs):
backend_cls = _load_backend(name)
- backend_api = backend_cls.backend_api
+ backend_api = backend_cls.backend_api()
kwargs.setdefault('backend_api', backend_api)
return backend_cls(**kwargs)
View
40 anykeystore/tests/integration/tests.py
@@ -19,20 +19,15 @@ def setUpModule():
'could not find testing.ini required to run integration tests')
class BackendTests(object):
- requires = []
-
- @classmethod
- def setUpClass(cls):
- try:
- for req in cls.requires:
- __import__(req)
- except ImportError:
- raise unittest.SkipTest(
- 'unsatisfied dependency, tests require "%s"' % req)
+ expires = -1
+ wait = 0
def _makeOne(self):
from anykeystore import create_store_from_settings
- store = create_store_from_settings(config, prefix=self.key + '.')
+ try:
+ store = create_store_from_settings(config, prefix=self.key + '.')
+ except ImportError as e:
+ raise unittest.SkipTest(str(e))
return store
def test_it(self):
@@ -41,44 +36,43 @@ def test_it(self):
value = store.retrieve('foo')
self.assertEqual(value, 'bar')
- def test_it_delete(self):
+ def test_delete(self):
store = self._makeOne()
store.store('foo', 'bar')
store.delete('foo')
self.assertRaises(KeyError, store.retrieve, 'foo')
- def test_it_old(self):
+ def test_retrieve_expired(self):
store = self._makeOne()
- store.store('foo', 'bar', expires=1)
- time.sleep(2.5)
+ store.store('foo', 'bar', expires=self.expires)
+ time.sleep(self.wait)
self.assertRaises(KeyError, store.retrieve, 'foo')
- def test_it_purge(self):
+ def test_purge(self):
store = self._makeOne()
- store.store('foo', 'bar', expires=1)
- time.sleep(1.1)
+ store.store('foo', 'bar', expires=self.expires)
+ time.sleep(self.wait)
store.purge_expired()
self.assertRaises(KeyError, store.retrieve, 'foo')
class TestMemory(unittest.TestCase, BackendTests):
key = 'memory'
- requires = []
class TestSQLA(unittest.TestCase, BackendTests):
key = 'sqla'
- requires = ['sqlalchemy']
class TestMemcached(unittest.TestCase, BackendTests):
key = 'memcached'
- requires = ['memcached']
+ expires = 1
+ wait = 2
class TestMongoDB(unittest.TestCase, BackendTests):
key = 'mongodb'
- requires = ['pymongo']
class TestRedis(unittest.TestCase, BackendTests):
key = 'redis'
- requires = ['redis']
+ expires = 1
+ wait = 2
if __name__ == '__main__':
unittest.main()
Please sign in to comment.
Something went wrong with that request. Please try again.