def test_no_create(self): # testing the create_tables option testsdir = os.path.dirname(__file__) # when not provided it is not created conf = os.path.join(testsdir, 'tests3.ini') appdir, config, storage, auth = initenv(conf) self._add_cleanup(cleanupenv, conf) # this should fail because the table is absent self.assertRaises(BackendError, storage.set_user, _UID, email='*****@*****.**') # create_table = false conf = os.path.join(testsdir, 'tests4.ini') appdir, config, storage, auth = initenv(conf) self._add_cleanup(cleanupenv, conf) # this should fail because the table is absent self.assertRaises(BackendError, storage.set_user, _UID, email='*****@*****.**') # create_table = true conf = os.path.join(testsdir, 'tests2.ini') appdir, config, storage, auth = initenv(conf) self._add_cleanup(cleanupenv, conf) # this should work because the table is absent storage.set_user(_UID, email='*****@*****.**')
def test_no_create(self): # testing the create_tables option testsdir = os.path.dirname(__file__) # when not provided it is not created conf = os.path.join(testsdir, 'tests3.ini') appdir, config, storage, auth = initenv(conf) # this should fail because the table is absent self.assertRaises(BackendError, storage.set_user, _UID, email='*****@*****.**') # create_table = false conf = os.path.join(testsdir, 'tests4.ini') appdir, config, storage, auth = initenv(conf) sqlfile = storage.sqluri.split('sqlite:///')[-1] try: # this should fail because the table is absent self.assertRaises(BackendError, storage.set_user, _UID, email='*****@*****.**') finally: # removing the db created if os.path.exists(sqlfile): os.remove(sqlfile) # create_table = true conf = os.path.join(testsdir, 'tests2.ini') appdir, config, storage, auth = initenv(conf) # this should work because the table is absent storage.set_user(_UID, email='*****@*****.**')
def test_nopool(self): # make sure the pool is forced to NullPool when sqlite is used. testsdir = os.path.dirname(__file__) conf = os.path.join(testsdir, 'tests2.ini') appdir, config, storage, auth = initenv(conf) self.assertEqual(storage._engine.pool.__class__.__name__, 'NullPool')
def test_shard(self): self._add_cleanup(os.path.join('/tmp', 'tests2.db')) # make shure we do shard testsdir = os.path.dirname(__file__) conf = os.path.join(testsdir, 'tests2.ini') appdir, config, storage, auth = initenv(conf) res = storage._engine.execute('select count(*) from wbo1') self.assertEqual(res.fetchall()[0][0], 0) # doing a few things on the DB storage.set_user(_UID, email='*****@*****.**') storage.set_collection(_UID, 'col1') id1 = '{ec1b7457-003a-45a9-bf1c-c34e37225ad7}' id2 = '{339f52e1-deed-497c-837a-1ab25a655e37}' storage.set_item(_UID, 'col1', id1, payload=_PLD) storage.set_item(_UID, 'col1', id2, payload=_PLD * 89) self.assertEquals(len(storage.get_items(_UID, 'col1')), 2) # now making sure we did that in the right table table = get_wbo_table_name(_UID) self.assertEqual(table, 'wbo1') res = storage._engine.execute('select count(*) from wbo1') self.assertEqual(res.fetchall()[0][0], 2)
def test_shard(self): # make shure we do shard testsdir = os.path.dirname(__file__) conf = os.path.join(testsdir, 'tests2.ini') appdir, config, storage, auth = initenv(conf) self._add_cleanup(cleanupenv, conf) res = storage._engine.execute('select count(*) from wbo1') self.assertEqual(res.fetchall()[0][0], 0) # doing a few things on the DB storage.set_user(_UID, email='*****@*****.**') storage.set_collection(_UID, 'col1') id1 = '{ec1b7457-003a-45a9-bf1c-c34e37225ad7}' id2 = '{339f52e1-deed-497c-837a-1ab25a655e37}' storage.set_item(_UID, 'col1', id1, payload=_PLD) storage.set_item(_UID, 'col1', id2, payload=_PLD * 89) self.assertEquals(len(storage.get_items(_UID, 'col1')), 2) # now making sure we did that in the right table table = get_wbo_table_name(_UID) self.assertEqual(table, 'wbo1') res = storage._engine.execute('select count(*) from wbo1') self.assertEqual(res.fetchall()[0][0], 2)
def test_nopool(self): # make sure the pool is forced to NullPool when sqlite is used. testsdir = os.path.dirname(__file__) conf = os.path.join(testsdir, 'tests2.ini') appdir, config, storage, auth = initenv(conf) self._add_cleanup(cleanupenv, conf) self.assertEqual(storage._engine.pool.__class__.__name__, 'NullPool')
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 for name in ('client', 'crypto', 'forms', 'history', 'key', 'meta', 'bookmarks', 'prefs', 'tabs', 'passwords'): self.storage.set_collection(_UID, name) self._cfiles = []
def setUp(self): # loading the app 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') self.sqlfile = self.storage.sqluri.split('sqlite:///')[-1] self.app = TestApp(make_app(self.config)) # adding a user if needed self.user_name = 'test_user_%d' % random.randint(1, 100000) self.password = '******' * 9 self.auth.create_user(self.user_name, self.password, '*****@*****.**') self.user_id = self.auth.get_user_id(self.user_name)
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 # we don't support other storages for this test self.sql_driver = self.storage.sqluri.split(":/")[0] assert self.sql_driver in ("mysql", "sqlite", "pymysql") # make sure we have the standard collections in place for name in ("client", "crypto", "forms", "history", "key", "meta", "bookmarks", "prefs", "tabs", "passwords"): self.storage.set_collection(_UID, name) self._cleanup_functions = [] # delete the decorator's cached metlog client timed_safe_execute._client = None
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 # we don't support other storages for this test self.sql_driver = self.storage.sqluri.split(':/')[0] assert self.sql_driver in ('mysql', 'sqlite', 'pymysql') # make sure we have the standard collections in place for name in ('clients', 'crypto', 'forms', 'history', 'keys', 'meta', 'bookmarks', 'prefs', 'tabs', 'passwords'): self.storage.set_collection(_UID, name) self._cleanup_functions = [] # delete the decorator's cached metlog client timed_safe_execute._client = None
def setUp(self): # loading the app self.appdir, self.config, self.storage, self.auth = initenv() # we don't support other storages for this test self.sql_driver = self.storage.sqluri.split(':/')[0] assert self.sql_driver in ('mysql', 'sqlite', 'pymysql') test_remote_url = os.environ.get("TEST_REMOTE") if test_remote_url is not None: self.distant = True test_remote_url_p = urlparse.urlparse(test_remote_url) self.app = TestApp(WSGIProxyApp(test_remote_url), extra_environ={ "HTTP_HOST": test_remote_url_p.netloc, "wsgi.url_scheme": test_remote_url_p.scheme or "http", "SERVER_NAME": test_remote_url_p.hostname, "REMOTE_ADDR": "127.0.0.1", }) else: self.distant = False self.app = TestApp(make_app(self.config)) self._setup_user()