def test_sqlite3(): from metrique.utils import remove_file from metrique.sqlalchemy import SQLAlchemyProxy _expected_db_path = os.path.join(cache_dir, 'test.sqlite') remove_file(_expected_db_path) DB = 'test' TABLE = 'bla' p = SQLAlchemyProxy(db=DB, table=TABLE) p.initialize() assert p._engine_uri == 'sqlite:///%s' % _expected_db_path db_tester(p) p.drop() try: assert p.count() == 0 except RuntimeError: pass else: assert False assert p.ls() == [] remove_file(_expected_db_path)
def test_sqlite3(): from metrique.utils import remove_file from metrique.sqlalchemy import SQLAlchemyProxy _expected_db_path = os.path.join(cache_dir, 'test.sqlite') remove_file(_expected_db_path) DB = 'test' TABLE = 'bla' p = SQLAlchemyProxy(db=DB, table=TABLE) p.initialize() assert p._engine_uri == 'sqlite:///%s' % _expected_db_path db_tester(p) p.drop() try: assert p.count() == 0 except RuntimeError: pass else: assert False assert p.ls() == [] remove_file(_expected_db_path)
def test_postgresql(): from metrique.sqlalchemy import SQLAlchemyProxy from metrique.utils import rand_chars, configure config = configure(config_file=default_config, section_key='proxy', section_only=True) _db = config['db'] = 'test' _table = config['table'] = 'bla' config['dialect'] = 'postgresql' p = SQLAlchemyProxy(**config) _u = p.config.get('username') _p = p.config.get('password') _po = p.config.get('port') _expected_engine = 'postgresql://%s:%[email protected]:%s/%s' % (_u, _p, _po, _db) p.initialize() assert p._engine_uri == _expected_engine # FIXME: DROP ALL db_tester(p) schema = { 'col_1': {'type': int}, 'col_3': {'type': datetime}, } # FIXME: remove user! before test completes # new user new_u = rand_chars(chars='asdfghjkl') new_p = rand_chars(8) p.user_register(username=new_u, password=new_p) assert p.user_exists(new_u) is True # Sharing p.share(new_u) _new_table = 'blabla' # switch to the new users db p.config['username'] = new_u p.config['password'] = new_p p.config['db'] = new_u p.config['table'] = _new_table p.initialize() assert p.ls() == [] q = 'SELECT current_user;' assert p.execute(q)[0] == {'current_user': new_u} p.autotable(name=_new_table, schema=schema, create=True) assert p.ls() == [_new_table] # switch to admin's db p.config['username'] = _u p.config['password'] = _p p.config['db'] = _u p.config['table'] = _table p.initialize() p.autotable(schema=schema) assert p.ls() == [_table] p.drop() try: assert p.count() except RuntimeError: pass else: assert False assert p.ls() == []
def test_postgresql(): from metrique.sqlalchemy import SQLAlchemyProxy from metrique.utils import rand_chars, configure config = configure(config_file=default_config, section_key='proxy', section_only=True) _db = config['db'] = 'test' _table = config['table'] = 'bla' config['dialect'] = 'postgresql' p = SQLAlchemyProxy(**config) _u = p.config.get('username') _p = p.config.get('password') _po = p.config.get('port') _expected_engine = 'postgresql://%s:%[email protected]:%s/%s' % (_u, _p, _po, _db) p.initialize() assert p._engine_uri == _expected_engine # FIXME: DROP ALL db_tester(p) schema = { 'col_1': { 'type': int }, 'col_3': { 'type': datetime }, } # FIXME: remove user! before test completes # new user new_u = rand_chars(chars='asdfghjkl') new_p = rand_chars(8) p.user_register(username=new_u, password=new_p) assert p.user_exists(new_u) is True # Sharing p.share(new_u) _new_table = 'blabla' # switch to the new users db p.config['username'] = new_u p.config['password'] = new_p p.config['db'] = new_u p.config['table'] = _new_table p.initialize() assert p.ls() == [] q = 'SELECT current_user;' assert p.execute(q)[0] == {'current_user': new_u} p.autotable(name=_new_table, schema=schema, create=True) assert p.ls() == [_new_table] # switch to admin's db p.config['username'] = _u p.config['password'] = _p p.config['db'] = _u p.config['table'] = _table p.initialize() p.autotable(schema=schema) assert p.ls() == [_table] p.drop() try: assert p.count() except RuntimeError: pass else: assert False assert p.ls() == []