Skip to content

Commit 97eaca1

Browse files
Merge pull request #53 from pnnl/feature/weekly-integration-tests
Add weekly live integration test workflow
2 parents 6640862 + 51994d4 commit 97eaca1

3 files changed

Lines changed: 75 additions & 7 deletions

File tree

‎.github/workflows/integration.yml‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Integration Tests
2+
3+
# Weekly run of the live tests against the production COMcheck Web API, to
4+
# catch server-side changes that break this client. Kept separate from
5+
# test.yml, which stays offline and runs on every PR.
6+
#
7+
# Secret handling (this repo is public):
8+
# - COM_API_KEY lives in the "integration" environment, not as a repo secret.
9+
# Restrict that environment's deployment branches to `main` so only code
10+
# already merged to main can read it; PR branches and forks cannot.
11+
# - The workflow has no pull_request / pull_request_target trigger, so code
12+
# from a PR never runs with the secret.
13+
# - GitHub masks the key in logs; the client sends it only as a request header
14+
# and never logs it.
15+
# - Use a dedicated test account: --integration writes back to the first
16+
# project in the account.
17+
on:
18+
schedule:
19+
- cron: "0 14 * * 1" # Mondays 14:00 UTC
20+
workflow_dispatch:
21+
22+
permissions:
23+
contents: read
24+
25+
# Runs share one test account and project, so never overlap.
26+
concurrency:
27+
group: integration
28+
cancel-in-progress: false
29+
30+
jobs:
31+
integration:
32+
runs-on: ubuntu-latest
33+
environment: integration
34+
timeout-minutes: 30
35+
env:
36+
COM_API_KEY: ${{ secrets.COM_API_KEY }}
37+
# Fail instead of skip when the key is missing/rejected or the account
38+
# has no projects, so the run can't pass without testing anything.
39+
REQUIRE_LIVE_API: "1"
40+
steps:
41+
- uses: actions/checkout@v5
42+
43+
- name: Install uv
44+
uses: astral-sh/setup-uv@v8.2.0
45+
46+
- name: Set up Python
47+
run: uv python install 3.12
48+
49+
- name: Install dependencies
50+
run: uv sync
51+
52+
- name: Run live integration tests
53+
run: >
54+
uv run pytest -q --integration
55+
tests/test_comcheck_client.py
56+
tests/project_operation_tests

‎tests/project_operation_tests/conftest.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ def project(request, client: COMcheckClient) -> ComBuilding:
5353
if request.config.getoption("--integration"):
5454
projects = client.list_projects()
5555
if not projects or not (project_id := projects[0].get("_id")):
56-
pytest.skip("No projects found for integration tests.")
56+
reason = "No projects found for integration tests."
57+
if os.getenv("REQUIRE_LIVE_API") == "1":
58+
pytest.fail(reason)
59+
pytest.skip(reason)
5760
snapshot = client.get_project(project_id, mode="json")
5861
os.makedirs("testProjectJson", exist_ok=True)
5962
export_to_json(snapshot, "testProjectJson/initialProject.json")

‎tests/test_comcheck_client.py‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
These hit the real COMcheck Web API and need a valid ``COM_API_KEY``. They
44
skip (rather than fail) when no key is set or the key is rejected, so the
5-
offline suite stays green; provide a valid key to exercise them.
5+
offline suite stays green; provide a valid key to exercise them. Set
6+
``REQUIRE_LIVE_API=1`` (as the scheduled integration workflow does) to make
7+
those cases fail instead of skip.
68
"""
79

810
import os
@@ -19,12 +21,19 @@
1921
load_dotenv()
2022

2123

24+
def _skip_or_fail(reason: str) -> None:
25+
"""Skip the live test, or fail it when ``REQUIRE_LIVE_API`` is set."""
26+
if os.getenv("REQUIRE_LIVE_API") == "1":
27+
pytest.fail(reason)
28+
pytest.skip(reason)
29+
30+
2231
@pytest.fixture(scope="module")
2332
def client():
2433
"""Fixture to create and configure COMcheckClient."""
2534
api_key = os.getenv("COM_API_KEY")
2635
if not api_key:
27-
pytest.skip("COM_API_KEY is not set; skipping live client tests.")
36+
_skip_or_fail("COM_API_KEY is not set; skipping live client tests.")
2837

2938
client = COMcheckClient()
3039
client.set_api_key(api_key)
@@ -37,7 +46,7 @@ def test_fetch_project_list(client: COMcheckClient):
3746
project_list = client.list_projects()
3847
except COMCheckHTTPError as exc:
3948
if exc.status_code in (401, 403):
40-
pytest.skip(
49+
_skip_or_fail(
4150
f"COM_API_KEY rejected ({exc.status_code}); skipping live test."
4251
)
4352
raise
@@ -50,7 +59,7 @@ def test_fetch_single_project(client: COMcheckClient):
5059
project_list = client.list_projects()
5160
except COMCheckHTTPError as exc:
5261
if exc.status_code in (401, 403):
53-
pytest.skip(
62+
_skip_or_fail(
5463
f"COM_API_KEY rejected ({exc.status_code}); skipping live test."
5564
)
5665
raise
@@ -77,7 +86,7 @@ def test_calculate_interior_space_allowed_wattage(client: COMcheckClient):
7786
)
7887
except COMCheckHTTPError as exc:
7988
if exc.status_code in (401, 403):
80-
pytest.skip(
89+
_skip_or_fail(
8190
f"COM_API_KEY rejected ({exc.status_code}); skipping live test."
8291
)
8392
raise
@@ -105,7 +114,7 @@ def test_calculate_interior_spaces_allowed_wattage(client: COMcheckClient):
105114
)
106115
except COMCheckHTTPError as exc:
107116
if exc.status_code in (401, 403):
108-
pytest.skip(
117+
_skip_or_fail(
109118
f"COM_API_KEY rejected ({exc.status_code}); skipping live test."
110119
)
111120
raise

0 commit comments

Comments
 (0)