from unittest import skipUnless try: from redis import StrictRedis except ImportError: StrictRedis = None from pulsar import ImproperlyConfigured from pulsar.apps.test import check_server from pulsar.apps.data.redis.client import RedisClient from lux.utils import test REDIS_OK = check_server('redis') class TestWrappers(test.TestCase): def test_dummy_cache(self): app = self.application() cache = app.cache_server from lux.core.cache import Cache self.assertIsInstance(cache, Cache) self.assertEqual(cache.ping(), True) self.assertEqual(cache.hmget('bla'), None) cache.hmset('foo', {'name': 'pippo'}) self.assertEqual(cache.hmget('foo'), None) cache.set('h', 56) self.assertEqual(cache.get('h'), None)
'''Tests the taskqueue redis backend.''' import unittest from pulsar.apps.test import check_server from . import test_pulsards OK = check_server('redis') @unittest.skipUnless(OK, 'Requires a running redis server') class TestRedisTaskQueueOnThread(test_pulsards.TestTaskQueueOnThread): # schedule_periodic = False @classmethod def task_backend(cls): return 'redis://%s' % cls.cfg.redis_server @unittest.skipUnless(OK, 'Requires a running redis server') class TestRedisTaskQueueOnProcess(test_pulsards.TestTaskQueueOnProcess): @classmethod def task_backend(cls): return 'redis://%s' % cls.cfg.redis_server
import unittest from pulsar import Future, new_event_loop from pulsar.apps.data import create_store from pulsar.apps.test import check_server OK = check_server('postgresql') @unittest.skipUnless(OK, 'Requires postgresql binding') class PostgreSqlTest(object): @classmethod def setUpClass(cls): cls.created = [] cls.store = create_store(cls.cfg.postgresql_server, database=cls.name('test')) assert cls.store.database == cls.name('test') return cls.createdb() @classmethod def tearDownClass(cls): for db in cls.created: yield cls.store.delete_database(db) @classmethod def createdb(cls, name=None): if name: name = cls.name(name) name = yield cls.store.create_database(name)
from unittest import skipUnless from pulsar.apps.test import check_server from lux.utils import test REDIS_OK = check_server('redis') @skipUnless(REDIS_OK, 'Requires a running Redis server') class TestPostgreSql(test.AppTestCase): config_file = 'tests.sessions' config_params = { 'DATASTORE': 'postgresql+green://lux:[email protected]:5432/luxtests' } @classmethod def setUpClass(cls): cls.config_params['CACHE_SERVER'] = ('redis://%s' % cls.cfg.redis_server) return super().setUpClass() def test_backend(self): backend = self.app.auth_backend self.assertTrue(backend) self.assertEqual(len(backend.backends), 3) @test.green def test_get_user_none(self): backend = self.app.auth_backend request = self.app.wsgi_request()
import unittest from pulsar import coroutine_return, multi_async, new_event_loop, task from pulsar.utils.security import random_string from pulsar.apps.data import create_store from pulsar.apps.test import check_server from pulsar.apps.data.stores import CouchDbError, CouchDbNoDbError from pulsar.apps.test import run_on_actor OK = check_server('couchdb') @unittest.skipUnless(OK, 'Requires a running CouchDB server') class CouchDbTest(object): @classmethod def create_store(cls, pool_size=2, **kw): addr = '%s/%s' % (cls.cfg.couchdb_server, cls.name(cls.__name__)) return create_store(addr, pool_size=pool_size, **kw) class TestStoreWithDb(object): store = None databases = [] @classmethod def name(cls, name): '''A modified database name ''' return ('test_%s_%s' % (cls.cfg.exc_id, name)).lower()
from pulsar import new_event_loop, HAS_C_EXTENSIONS from pulsar.apps.test import check_server from .pulsards import unittest, RedisCommands, Scripting, create_store OK = check_server("redis") @unittest.skipUnless(OK, "Requires a running Redis server") class RedisDbTest(object): @classmethod def create_store(cls, pool_size=2, namespace=None, **kw): addr = cls.cfg.redis_server if not addr.startswith("redis://"): addr = "redis://%s" % cls.cfg.redis_server namespace = namespace or cls.name(cls.__name__) return create_store(addr, pool_size=pool_size, namespace=namespace, **kw) @unittest.skipUnless(OK, "Requires a running redis server") class TestRedisStore(RedisCommands, Scripting, unittest.TestCase): store = None @classmethod def setUpClass(cls): addr = "redis://%s" % cls.cfg.redis_server cls.store = cls.create_store(addr) cls.sync_store = create_store(addr, loop=new_event_loop()) cls.client = cls.store.client()
import unittest from pulsar import coroutine_return, multi_async, new_event_loop, task from pulsar.utils.security import random_string from pulsar.apps.data import create_store from pulsar.apps.test import check_server from pulsar.apps.data.stores import CouchDbError, CouchDbNoDbError from pulsar.apps.test import run_on_actor OK = check_server("couchdb") @unittest.skipUnless(OK, "Requires a running CouchDB server") class CouchDbTest(object): @classmethod def create_store(cls, pool_size=2, **kw): addr = "%s/%s" % (cls.cfg.couchdb_server, cls.name(cls.__name__)) return create_store(addr, pool_size=pool_size, **kw) class TestStoreWithDb(object): store = None databases = [] @classmethod def name(cls, name): """A modified database name """ return ("test_%s_%s" % (cls.cfg.exc_id, name)).lower()
import unittest from pulsar import Future, new_event_loop from pulsar.apps.data import create_store from pulsar.apps.test import check_server OK = check_server('postgresql') if not OK: try: import pulsar.apps.greenio.pg except ImportError as e: MSG = str(e) else: MSG = 'Requires a running postgresql database' else: MSG = '' @unittest.skipUnless(OK, MSG) class PostgreSqlTest(object): @classmethod def setUpClass(cls): cls.created = [] cls.store = create_store(cls.cfg.postgresql_server, database=cls.name('test')) assert cls.store.database == cls.name('test') return cls.createdb() @classmethod def tearDownClass(cls):
import unittest from pulsar import coroutine_return, multi_async, new_event_loop from pulsar.utils.security import random_string from pulsar.apps.data import create_store from pulsar.apps.test import check_server from pulsar.apps.data.stores import CouchDbError, CouchDbNoDbError OK = check_server('couchdb') @unittest.skipUnless(OK, 'Requires a running CouchDB server') class CouchDbTest(object): @classmethod def create_store(cls, pool_size=2, **kw): addr = '%s/%s' % (cls.cfg.couchdb_server, cls.name(cls.__name__)) return create_store(addr, pool_size=pool_size, **kw) class TestStoreWithDb(object): store = None databases = [] @classmethod def name(cls, name): '''A modified database name ''' return ('test_%s_%s' % (cls.cfg.exc_id, name)).lower()