|
| 1 | +import importlib |
| 2 | +import os |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +from fastapi.testclient import TestClient |
| 6 | + |
| 7 | + |
| 8 | +TEST_DB = Path("./test_ic_workflow.db") |
| 9 | +os.environ["DATABASE_URL"] = "sqlite+aiosqlite:///./test_ic_workflow.db" |
| 10 | +os.environ["OPENAI_API_KEY"] = "" |
| 11 | + |
| 12 | +from src.core.config import get_settings |
| 13 | + |
| 14 | +get_settings.cache_clear() |
| 15 | + |
| 16 | +import src.database.session as session_module |
| 17 | +import src.main as main_module |
| 18 | + |
| 19 | +importlib.reload(session_module) |
| 20 | +importlib.reload(main_module) |
| 21 | + |
| 22 | +app = main_module.app |
| 23 | + |
| 24 | + |
| 25 | +def setup_module() -> None: |
| 26 | + if TEST_DB.exists(): |
| 27 | + TEST_DB.unlink() |
| 28 | + |
| 29 | + |
| 30 | +def teardown_module() -> None: |
| 31 | + if TEST_DB.exists(): |
| 32 | + TEST_DB.unlink() |
| 33 | + |
| 34 | + |
| 35 | +def test_health_endpoint() -> None: |
| 36 | + with TestClient(app) as client: |
| 37 | + response = client.get("/api/v1/health") |
| 38 | + assert response.status_code == 200 |
| 39 | + payload = response.json() |
| 40 | + assert payload["status"] == "ok" |
| 41 | + |
| 42 | + |
| 43 | +def test_create_and_list_deals() -> None: |
| 44 | + with TestClient(app) as client: |
| 45 | + create_response = client.post( |
| 46 | + "/api/v1/deals", |
| 47 | + json={ |
| 48 | + "deal_name": "Integration Deal", |
| 49 | + "target_name": "Integration Target", |
| 50 | + "deal_type": "equity", |
| 51 | + "industry": "Fintech", |
| 52 | + "geography": "US", |
| 53 | + "deal_size": 2500000, |
| 54 | + "valuation": 20000000, |
| 55 | + "currency": "USD", |
| 56 | + }, |
| 57 | + headers={"X-User": "integration@test.local"}, |
| 58 | + ) |
| 59 | + assert create_response.status_code == 201 |
| 60 | + deal = create_response.json() |
| 61 | + assert deal["deal_name"] == "Integration Deal" |
| 62 | + |
| 63 | + list_response = client.get("/api/v1/deals") |
| 64 | + assert list_response.status_code == 200 |
| 65 | + deals = list_response.json() |
| 66 | + assert any(item["id"] == deal["id"] for item in deals) |
0 commit comments