48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from alembic.runtime.migration import MigrationContext
|
|
from sqlalchemy import create_engine, inspect
|
|
|
|
from govoplan_core.db.migrations import migrate_database
|
|
from govoplan_datasources.backend.manifest import get_manifest
|
|
|
|
|
|
class DatasourceMigrationTests(unittest.TestCase):
|
|
def test_baseline_creates_datasource_tables_and_head(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="govoplan-datasources-migration-") as directory:
|
|
url = f"sqlite:///{Path(directory) / 'datasources.db'}"
|
|
migrate_database(
|
|
database_url=url,
|
|
enabled_modules=("datasources",),
|
|
manifest_factories=(get_manifest,),
|
|
)
|
|
engine = create_engine(url)
|
|
try:
|
|
with engine.connect() as connection:
|
|
self.assertIn(
|
|
"f3a8d2c7b1e0",
|
|
set(MigrationContext.configure(connection).get_current_heads()),
|
|
)
|
|
self.assertEqual(
|
|
{
|
|
"datasource_catalogue",
|
|
"datasource_materializations",
|
|
"datasource_stages",
|
|
},
|
|
{
|
|
name
|
|
for name in inspect(connection).get_table_names()
|
|
if name.startswith("datasource_")
|
|
},
|
|
)
|
|
finally:
|
|
engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|