def setup_sqlite3_alias_tables(): """Setup the SQLite3 alias database.""" SQLAlchemyAliasDriver("sqlite:///alias.sq3") with sqlite3.connect(ALIAS_HOST) as conn: connection = conn.execute( """ SELECT name FROM sqlite_master WHERE type = 'table' """ ) tables = [i[0] for i in connection] for table in ALIAS_TABLES: assert table in tables, "{table} not created".format(table=table) for table, _ in ALIAS_TABLES.items(): # NOTE PRAGMA's don't work with parameters... connection = conn.execute( """ PRAGMA table_info ('{table}') """.format( table=table ) )
def test_sqlite3_alias_setup_tables(): ''' Tests that the SQLite3 alias database gets set up correctly. ''' SQLAlchemyAliasDriver('sqlite:///alias.sq3') with sqlite3.connect(ALIAS_HOST) as conn: c = conn.execute(''' SELECT name FROM sqlite_master WHERE type = 'table' ''') tables = [i[0] for i in c] for table in ALIAS_TABLES: assert table in tables, '{table} not created'.format(table=table) for table, schema in ALIAS_TABLES.items(): # NOTE PRAGMA's don't work with parameters... c = conn.execute(''' PRAGMA table_info ('{table}') '''.format(table=table)) assert schema == [i for i in c]
def test_migrate_alias_internal(monkeypatch): called = [] def mock_migrate(**kwargs): called.append(True) monkeypatch.setattr( 'indexd.alias.drivers.alchemy.CURRENT_SCHEMA_VERSION', 1) monkeypatch.setattr( 'indexd.alias.drivers.alchemy.SCHEMA_MIGRATION_FUNCTIONS', [mock_migrate]) monkeypatch.setattr('indexd.utils.check_engine_for_migrate', lambda _: True) update_version_table_for_testing('alias.sq3', 'alias_schema_version', 0) driver = SQLAlchemyAliasDriver('sqlite:///alias.sq3') assert len(called) == 1 with driver.session as s: v = s.query(AliasSchemaVersion).first() assert v.version == 1
(2, u'hash_value', u'VARCHAR', 0, None, 0)], 'alias_record_host_authority': [ (0, u'name', u'VARCHAR', 1, None, 1), (1, u'host', u'VARCHAR', 1, None, 1 if OLD_SQLITE else 2), ], 'alias_schema_version': [ (0, u'version', u'INTEGER', 1, None, 1), ], } INDEX_CONFIG = { 'driver': SQLAlchemyIndexDriver('sqlite:///index.sq3'), } ALIAS_CONFIG = { 'driver': SQLAlchemyAliasDriver('sqlite:///alias.sq3'), } @util.removes(INDEX_HOST) def test_sqlite3_index_setup_tables(): ''' Tests that the SQLite3 index database gets set up correctly. ''' SQLAlchemyIndexDriver('sqlite:///index.sq3') with sqlite3.connect(INDEX_HOST) as conn: c = conn.execute(''' SELECT name FROM sqlite_master WHERE type = 'table' ''')
usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db, ), index_config=index_config, ), } CONFIG["ALIAS"] = { "driver": SQLAlchemyAliasDriver( "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format( usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db, )), } AUTH = SQLAlchemyAuthDriver( "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format( usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db, ), arborist="http://localhost/", )
], "alias_record_hash": [ (0, "name", "VARCHAR", 1, None, 1), (1, "hash_type", "VARCHAR", 1, None, 1 if OLD_SQLITE else 2), (2, "hash_value", "VARCHAR", 0, None, 0), ], "alias_record_host_authority": [ (0, "name", "VARCHAR", 1, None, 1), (1, "host", "VARCHAR", 1, None, 1 if OLD_SQLITE else 2), ], "alias_schema_version": [(0, "version", "INTEGER", 1, None, 1)], } INDEX_CONFIG = {"driver": SQLAlchemyIndexDriver("sqlite:///index.sq3")} ALIAS_CONFIG = {"driver": SQLAlchemyAliasDriver("sqlite:///alias.sq3")} @util.removes(INDEX_HOST) def test_sqlite3_index_setup_tables(): """ Tests that the SQLite3 index database gets set up correctly. """ SQLAlchemyIndexDriver("sqlite:///index.sq3") with sqlite3.connect(INDEX_HOST) as conn: c = conn.execute(""" SELECT name FROM sqlite_master WHERE type = 'table' """) tables = [i[0] for i in c]