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 initenv(config=None): """Reads the config file and instanciates an auth and a storage. The WEAVE_TESTFILE=name environment variable can be used to point a particular tests_name.ini file. """ topdir = os.path.split(_TOPDIR)[0] if 'WEAVE_TESTFILE' in os.environ: test_filename = 'tests_%s.ini' % os.environ['WEAVE_TESTFILE'] else: test_filename = 'tests.ini' while True: ini_file = os.path.join(topdir, test_filename) if os.path.exists(ini_file): break topdir = os.path.split(topdir)[0] if topdir == '/': break if not os.path.exists(ini_file): raise IOError("cannot locate %s" % test_filename) if config is None: config = ini_file cfg = RawConfigParser() cfg.read(config) # loading loggers if cfg.has_section('loggers'): fileConfig(config) here = {'here': os.path.dirname(os.path.realpath(config))} config = dict([ (key, value % here) for key, value in cfg.items('DEFAULT') + cfg.items('app:main') ]) config = convert_config(config) auth = ServicesAuth.get_from_config(config) return topdir, config, auth
def initenv(config=None): """Reads the config file and instanciates an auth and a storage. The WEAVE_TESTFILE=name environment variable can be used to point a particular tests_name.ini file. """ topdir = os.path.split(_TOPDIR)[0] if 'WEAVE_TESTFILE' in os.environ: test_filename = 'tests_%s.ini' % os.environ['WEAVE_TESTFILE'] else: test_filename = 'tests.ini' while True: ini_file = os.path.join(topdir, test_filename) if os.path.exists(ini_file): break topdir = os.path.split(topdir)[0] if topdir == '/': break if not os.path.exists(ini_file): raise IOError("cannot locate %s" % test_filename) if config is None: config = ini_file cfg = RawConfigParser() cfg.read(config) # loading loggers if cfg.has_section('loggers'): fileConfig(config) here = {'here': os.path.dirname(os.path.realpath(config))} config = dict([(key, value % here)for key, value in cfg.items('DEFAULT') + cfg.items('app:main')]) config = convert_config(config) auth = ServicesAuth.get_from_config(config) return topdir, config, auth
# the terms of any one of the MPL, the GPL or the LGPL. # # ***** END LICENSE BLOCK ***** import os import unittest import datetime from sqlalchemy.sql import text from sqlalchemy.pool import NullPool from services.tests.support import initenv, cleanupenv from services.auth.sql import SQLAuth from services.auth import ServicesAuth from services.util import ssha, BackendError, safe_execute ServicesAuth.register(SQLAuth) class TestSQLAuth(unittest.TestCase): def setUp(self): self.appdir, self.config, self.auth = initenv() # we don't support other storages for this test driver = self.auth.sqluri.split(':/')[0] assert driver in ('mysql', 'pymysql', 'sqlite') # lets add a user tarek/tarek password = ssha('tarek') query = text('insert into users (username, password_hash, status) ' 'values (:username, :password, 1)') self._safe_execute(query, username='******', password=password) self.user_id = self._safe_execute('select id from users where'
# # ***** 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 assert self.storage.sqluri.split(':/')[0] in ('mysql', 'sqlite', 'pymysql') self.sqlfile = self.storage.sqluri.split('sqlite:///')[-1] # make sure we have the standard collections in place
def setUp(self): self.auth = ServicesAuth.get('services.auth.dummy.DummyAuth')
# in which case the provisions of the GPL or the LGPL are applicable instead # of those above. If you wish to allow use of your version of this file only # under the terms of either the GPL or the LGPL, and not to allow others to # 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 from services.auth.dummy import DummyAuth from services.auth import ServicesAuth ServicesAuth.register(DummyAuth) class TestDummyAuth(unittest.TestCase): def setUp(self): self.auth = ServicesAuth.get('services.auth.dummy.DummyAuth') def test_authenticate_user(self): tarek_id = self.auth.authenticate_user('tarek', 'tarek') self.assertNotEquals(self.auth.authenticate_user('tarek2', 'tarek'), tarek_id) self.assertEquals(self.auth.authenticate_user('tarek', 'tarek'), tarek_id)
# in which case the provisions of the GPL or the LGPL are applicable instead # of those above. If you wish to allow use of your version of this file only # under the terms of either the GPL or the LGPL, and not to allow others to # 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 from services.auth.dummy import DummyAuth from services.auth import ServicesAuth ServicesAuth.register(DummyAuth) class TestDummyAuth(unittest.TestCase): def setUp(self): self.auth = ServicesAuth.get('services.auth.dummy.DummyAuth') def test_authenticate_user(self): tarek_id = self.auth.authenticate_user('tarek', 'tarek') self.assertNotEquals(self.auth.authenticate_user('tarek2', 'tarek'), tarek_id) self.assertEquals(self.auth.authenticate_user('tarek', 'tarek'), tarek_id) def test_suite():
def setUp(self): self.auth = ServicesAuth.get('dummy')