test_test_harness.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import annotations
  2. import sys
  3. import types
  4. from pathlib import Path
  5. from tests.conftest import (
  6. REPO_ROOT,
  7. SERVICE_IMPORT_CONFIGS,
  8. build_postgres_database_url,
  9. prepare_known_service_import,
  10. )
  11. def test_prepare_known_service_import_resets_app_modules_and_orders_paths() -> None:
  12. sys.modules["app"] = types.ModuleType("app")
  13. sys.modules["app.fake"] = types.ModuleType("app.fake")
  14. prepare_known_service_import("workflow-service")
  15. assert "app" not in sys.modules
  16. assert "app.fake" not in sys.modules
  17. assert sys.path[0] == str(REPO_ROOT / "services" / "workflow-service")
  18. assert str(REPO_ROOT / "libs" / "core-dsl" / "src") in sys.path
  19. def test_service_import_configs_cover_services_with_database_tests() -> None:
  20. assert "runtime-service" in SERVICE_IMPORT_CONFIGS
  21. assert "workflow-service" in SERVICE_IMPORT_CONFIGS
  22. assert "core-db" in SERVICE_IMPORT_CONFIGS["runtime-service"].libs
  23. assert "core-dsl" in SERVICE_IMPORT_CONFIGS["workflow-service"].libs
  24. def test_build_postgres_database_url_uses_isolated_schema(tmp_path: Path) -> None:
  25. database_url = build_postgres_database_url(tmp_path, "service")
  26. assert database_url.startswith("postgresql+psycopg://")
  27. assert "options=-csearch_path%3Dtest_" in database_url
  28. assert "%2Cpublic" not in database_url
  29. def test_gitlab_ci_installs_services_used_by_tests() -> None:
  30. ci_text = (REPO_ROOT / ".gitlab-ci.yml").read_text(encoding="utf-8")
  31. assert "pip install -e libs/core-dsl" in ci_text
  32. assert "pip install -e services/workflow-service" in ci_text
  33. assert "pip install -e services/runtime-service" in ci_text