"""The dbt target and environment derived from the deployment's database URLs (`webapi.dbt_manifest`). No dbt runs here: only the mapping the entrypoint relies on to compile the manifest against the right engine. No fixtures.""" import pytest from webapi.dbt_manifest import dbt_executable, environment, target_of URLS_MSSQL = { "cacu": "mssql+pymssql://usuario:clave@servidor:1433/isss_cacu", "cama": "mssql+pymssql://usuario:clave@servidor:1433/isss_cama", "tea": "mssql+pymssql://usuario:clave@servidor:1433/isss_tea", } def test_sqlite_urls_keep_the_image_manifest(): """SQLite URLs give the `sqlite` target, which the entrypoint treats as "keep the image's manifest". Fails if `target_of` stops recognising SQLite or maps it elsewhere.""" urls = {d: f"sqlite:////data/{d}.db" for d in ("cacu", "cama", "tea")} assert target_of(urls) == "sqlite" assert environment(urls, "sqlite")["TEA_DB_PATH"] == "/data/tea.db" @pytest.mark.parametrize("scheme, target", [("mssql+pymssql", "sqlserver"), ("postgresql+psycopg2", "postgres"), ("mysql+pymysql", "mysql"), ("mariadb+pymysql", "mysql")]) def test_each_engine_maps_to_its_dbt_target(scheme, target): """Every engine the platform runs on has a dbt target. Fails if a backend name is dropped from `TARGETS`.""" urls = {d: f"{scheme}://u:p@h:1/{d}" for d in ("cacu", "cama", "tea")} assert target_of(urls) == target def test_mixed_engines_are_refused(): """One manifest serves the three domains, so their databases must share an engine. Fails if `target_of` silently picks one of several engines.""" urls = {**URLS_MSSQL, "tea": "sqlite:////data/tea.db"} with pytest.raises(ValueError, match="one engine"): target_of(urls) def test_environment_feeds_profiles_yml(): """The server, port, credentials and each domain's database name reach dbt through the variables `Transformation/profiles.yml` reads. Fails if a variable name changes on either side.""" env = environment(URLS_MSSQL, "sqlserver") assert env == {"CACU_DBT_DATABASE": "isss_cacu", "CAMA_DBT_DATABASE": "isss_cama", "TEA_DBT_DATABASE": "isss_tea", "DBT_HOST": "servidor", "DBT_PORT": "1433", "DBT_USER": "usuario", "DBT_PASSWORD": "clave"} def test_mysql_has_its_own_environment(tmp_path): """dbt-mysql pins an older dbt-core, so the image keeps it in `.venv-mysql`. Fails if the executable lookup stops distinguishing MySQL.""" assert dbt_executable(tmp_path, "mysql") == tmp_path / ".venv-mysql" / "bin" / "dbt" assert dbt_executable(tmp_path, "sqlserver") == tmp_path / ".venv" / "bin" / "dbt"