Skip to content

Commit d7aabb3

Browse files
Restore live project pull under --integration
The offline refactor made the project fixture always load the static JSON. Branch on --integration so integration runs again fetch a live project from the API (and snapshot it) before exercising the write operations, while the default run stays offline. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c476f3e commit d7aabb3

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

‎tests/project_operation_tests/conftest.py‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99

1010
from comcheck_api.client import COMcheckClient
11+
from comcheck_api.utilities.common import export_to_json
1112
from comcheck_api.types.core_types import *
1213
from comcheck_api.utilities.project_utilities import get_id_from_component
1314
from comcheck_api.project_operations import project_building_area_operations
@@ -42,10 +43,25 @@ def client() -> COMcheckClient:
4243

4344

4445
@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+
4965
assert project is not None
5066
return project
5167

0 commit comments

Comments
 (0)