def initenv(config=None, **env_args): """Reads the config file and instantiates an auth and a storage. """ # pre-registering plugins from syncstorage.storage.sql import SQLStorage SyncStorage.register(SQLStorage) try: from syncstorage.storage.memcachedsql import MemcachedSQLStorage SyncStorage.register(MemcachedSQLStorage) except ImportError: pass from services.auth.sql import SQLAuth ServicesAuth.register(SQLAuth) try: from services.auth.ldapsql import LDAPAuth ServicesAuth.register(LDAPAuth) except ImportError: pass from services.auth.dummy import DummyAuth ServicesAuth.register(DummyAuth) env_args['ini_path'] = config env_args.setdefault('ini_dir', os.path.dirname(__file__)) env_args.setdefault('load_sections', ['auth', 'storage']) testenv = services.tests.support.TestEnv(**env_args) return testenv.ini_dir, testenv.config, testenv.storage, testenv.auth
def test_register(self): class NotAStorage(object): pass self.assertRaises(TypeError, SyncStorage.register, NotAStorage) SyncStorage.register(IAmAValidStorage) fqn = 'syncstorage.tests.test_storagebase.IAmAValidStorage' self.assert_(isinstance(SyncStorage.get(fqn), IAmAValidStorage))
def test_collection_sizes(self): if not self._is_up(): # no memcached return fd, dbfile = mkstemp() os.close(fd) kw = { 'sqluri': 'sqlite:///%s' % dbfile, 'use_quota': True, 'quota_size': 5120, 'create_tables': True } try: storage = SyncStorage.get(self.fn, **kw) # setting the tabs in memcache tabs = { 'mCwylprUEiP5': { 'payload': '*' * 1024, 'id': 'mCwylprUEiP5', 'modified': Decimal('1299142695.76') } } storage.cache.set_tabs(1, tabs) size = storage.get_collection_sizes(1) self.assertEqual(size['tabs'], 1.) finally: os.remove(dbfile)
def test_collection_sizes(self): if not self._is_up(): # no memcached return fd, dbfile = mkstemp() os.close(fd) kw = {'sqluri': 'sqlite:///%s' % dbfile, 'use_quota': True, 'quota_size': 5120, 'create_tables': True} try: storage = SyncStorage.get(self.fn, **kw) # setting the tabs in memcache tabs = {'mCwylprUEiP5': {'payload': '*' * 1024, 'id': 'mCwylprUEiP5', 'modified': Decimal('1299142695.76')}} storage.cache.set_tabs(1, tabs) size = storage.get_collection_sizes(1) self.assertEqual(size['tabs'], 1.) finally: os.remove(dbfile)
def setUp(self): fd, self.dbfile = mkstemp() os.close(fd) kw = {"sqluri": "sqlite:///%s" % self.dbfile, "use_quota": True, "quota_size": 5120, "create_tables": True} self.fn = "syncstorage.storage.memcachedsql.MemcachedSQLStorage" self.storage = SyncStorage.get(self.fn, **kw) # make sure we have the standard collections in place for name in ("client", "crypto", "forms", "history"): self.storage.set_collection(_UID, name)
def test_collection_sizes(self): if not self._is_up(): # no memcached return fd, dbfile = mkstemp() os.close(fd) kw = {"sqluri": "sqlite:///%s" % dbfile, "use_quota": True, "quota_size": 5120, "create_tables": True} try: storage = SyncStorage.get(self.fn, **kw) # setting the tabs in memcache tabs = { "mCwylprUEiP5": {"payload": "*" * 1024, "id": "mCwylprUEiP5", "modified": Decimal("1299142695.76")} } storage.cache.set_tabs(1, tabs) size = storage.get_collection_sizes(1) self.assertEqual(size["tabs"], 1.0) finally: os.remove(dbfile)
def setUp(self): if not MEMCACHED: raise SkipTest # Ensure we have metlog loaded so the timers will work. config_file = os.path.join(os.path.dirname(__file__), "sync.conf") config = Config(cfgfile=config_file) load_and_configure(config, "metlog_loader") fd, self.dbfile = mkstemp() os.close(fd) self.fn = 'syncstorage.storage.memcachedsql.MemcachedSQLStorage' kwds = self.STORAGE_CONFIG.copy() kwds['sqluri'] = 'sqlite:///%s' % self.dbfile self.storage = SyncStorage.get(self.fn, **kwds) # make sure we have the standard collections in place for name in ('client', 'crypto', 'forms', 'history'): self.storage.set_collection(_UID, name)
# use your version of this file under the terms of the MPL, indicate your # decision by deleting the provisions above and replace them with the notice # and other provisions required by the GPL or the LGPL. If you do not delete # the provisions above, a recipient may use your version of this file under # the terms of any one of the MPL, the GPL or the LGPL. # # ***** END LICENSE BLOCK ***** import unittest import os import time from syncstorage.tests.support import initenv from syncstorage.storage.sqlmappers import get_wbo_table_name from syncstorage.storage import SyncStorage from syncstorage.storage.sql import SQLStorage SyncStorage.register(SQLStorage) from services.auth import ServicesAuth from services.auth.sql import SQLAuth from services.util import BackendError ServicesAuth.register(SQLAuth) _UID = 1 _PLD = '*' * 500 class TestSQLStorage(unittest.TestCase): def setUp(self): self.appdir, self.config, self.storage, self.auth = initenv() # we don't support other storages for this test
# # ***** END LICENSE BLOCK ***** import json import unittest import os import time import threading from syncstorage.tests.support import initenv, cleanupenv from syncstorage.storage.sqlmappers import get_wbo_table_name from syncstorage.storage import SyncStorage from syncstorage.storage.sql import (SQLStorage, create_engine, QueuePoolWithMaxBacklog, sql_timer_name, timed_safe_execute) from syncstorage.wsgiapp import make_app SyncStorage.register(SQLStorage) from services.auth import ServicesAuth from services.auth.sql import SQLAuth from services.util import BackendError ServicesAuth.register(SQLAuth) _UID = 1 _PLD = '*' * 500 class TestSQLStorage(unittest.TestCase): def setUp(self): self.appdir, self.config, self.storage, self.auth = initenv() config_file = os.path.join(os.path.dirname(__file__), "sync.conf") self.app = make_app({"configuration": "file:" + config_file}).app
try: from syncstorage.storage.memcachedsql import MemcachedSQLStorage MEMCACHED = True except ImportError: MEMCACHED = False from syncstorage.storage import SyncStorage from services.util import BackendError, round_time _UID = 1 _PLD = "*" * 500 # manual registration if MEMCACHED: SyncStorage.register(MemcachedSQLStorage) class TestMemcachedSQLStorage(unittest.TestCase): def setUp(self): fd, self.dbfile = mkstemp() os.close(fd) kw = {"sqluri": "sqlite:///%s" % self.dbfile, "use_quota": True, "quota_size": 5120, "create_tables": True} self.fn = "syncstorage.storage.memcachedsql.MemcachedSQLStorage" self.storage = SyncStorage.get(self.fn, **kw) # make sure we have the standard collections in place for name in ("client", "crypto", "forms", "history"):
from syncstorage.storage import SyncStorage from syncstorage.controller import _ONE_MEG # This establishes the MOZSVC_UUID environment variable. import syncstorage.tests.support # NOQA from services.util import BackendError, round_time from services.config import Config from services.pluginreg import load_and_configure _UID = 1 _PLD = '*' * 500 # manual registration if MEMCACHED: SyncStorage.register(MemcachedSQLStorage) class TestMemcachedSQLStorage(unittest.TestCase): STORAGE_CONFIG = { 'use_quota': True, 'quota_size': 5120, 'create_tables': True, } def setUp(self): if not MEMCACHED: raise SkipTest # Ensure we have metlog loaded so the timers will work.