| 1 | from __future__ import annotations |
| 2 | |
| 3 | import subprocess |
| 4 | from pathlib import Path |
| 5 | |
| 6 | import yaml |
| 7 | |
| 8 | from app.settings import Settings |
| 9 | |
| 10 | |
| 11 | REPOSITORY_ROOT = Path(__file__).resolve().parents[3] |
| 12 | CHART = REPOSITORY_ROOT / "infrastructure" / "helm" / "ai-investment-platform" |
| 13 | |
| 14 | |
| 15 | def test_dev_helm_renders_research_engine_with_kubernetes_portfolio_service_address() -> None: |
| 16 | rendered = subprocess.run( |
| 17 | [ |
| 18 | "helm", |
| 19 | "template", |
| 20 | "configuration-test", |
| 21 | str(CHART), |
| 22 | "--values", |
| 23 | str(CHART / "values-dev.yaml"), |
| 24 | ], |
| 25 | check=True, |
| 26 | capture_output=True, |
| 27 | text=True, |
| 28 | ).stdout |
| 29 | |
| 30 | research_deployment = next( |
| 31 | document |
| 32 | for document in yaml.safe_load_all(rendered) |
| 33 | if document |
| 34 | and document.get("kind") == "Deployment" |
| 35 | and document.get("metadata", {}).get("name") == "research-engine" |
| 36 | ) |
| 37 | environment = { |
| 38 | item["name"]: item.get("value") |
| 39 | for item in research_deployment["spec"]["template"]["spec"]["containers"][0]["env"] |
| 40 | } |
| 41 | assert environment["AIP_PORTFOLIO_SERVICE_BASE_URL"] == "http://portfolio-service" |
| 42 | |
| 43 | |
| 44 | def test_local_development_can_override_portfolio_service_to_localhost(monkeypatch) -> None: |
| 45 | monkeypatch.setenv("AIP_PORTFOLIO_SERVICE_BASE_URL", "http://localhost:8080") |
| 46 | |
| 47 | assert Settings(_env_file=None).portfolio_service_base_url == "http://localhost:8080" |