|
8 | 8 | import pytest |
9 | 9 |
|
10 | 10 | from comcheck_api.client import COMcheckClient |
| 11 | +from comcheck_api.utilities.common import export_to_json |
11 | 12 | from comcheck_api.types.core_types import * |
12 | 13 | from comcheck_api.utilities.project_utilities import get_id_from_component |
13 | 14 | from comcheck_api.project_operations import project_building_area_operations |
@@ -42,10 +43,25 @@ def client() -> COMcheckClient: |
42 | 43 |
|
43 | 44 |
|
44 | 45 | @pytest.fixture(scope="session") |
45 | | -def project(client: COMcheckClient) -> ComBuilding: |
46 | | - """Load the project model from the committed sample JSON (offline).""" |
47 | | - data = json.loads(SAMPLE_PROJECT_PATH.read_text()) |
48 | | - project = client._parse_data(data, "python") |
| 46 | +def project(request, client: COMcheckClient) -> ComBuilding: |
| 47 | + """Project model under test. |
| 48 | +
|
| 49 | + With ``--integration`` this pulls a live project from the API (and snapshots |
| 50 | + it to ``testProjectJson/initialProject.json``) so the operations write back |
| 51 | + to a real project. Otherwise it loads the committed sample JSON offline. |
| 52 | + """ |
| 53 | + if request.config.getoption("--integration"): |
| 54 | + projects = client.list_projects() |
| 55 | + if not projects or not (project_id := projects[0].get("_id")): |
| 56 | + pytest.skip("No projects found for integration tests.") |
| 57 | + snapshot = client.get_project(project_id, mode="json") |
| 58 | + os.makedirs("testProjectJson", exist_ok=True) |
| 59 | + export_to_json(snapshot, "testProjectJson/initialProject.json") |
| 60 | + project = client.get_project(project_id) |
| 61 | + else: |
| 62 | + data = json.loads(SAMPLE_PROJECT_PATH.read_text()) |
| 63 | + project = client._parse_data(data, "python") |
| 64 | + |
49 | 65 | assert project is not None |
50 | 66 | return project |
51 | 67 |
|
|
0 commit comments