Skip to content

Commit ad32dfb

Browse files
author
Michael Smit
committed
Added integration tests against simulation workflow
1 parent 1efdb16 commit ad32dfb

11 files changed

Lines changed: 399 additions & 1 deletion

File tree

.github/workflows/gcp-deploy.reusable.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ jobs:
9595
python-version: "3.11"
9696
- name: Set up poetry
9797
run: uv pip install poetry --system
98+
- name: Authenticate as tester SA in GCP
99+
uses: "google-github-actions/auth@v2"
100+
with:
101+
workload_identity_provider: "${{ vars._GITHUB_IDENTITY_POOL_PROVIDER_NAME }}"
102+
service_account: "tester@${{ vars.PROJECT_ID }}.iam.gserviceaccount.com"
98103
- name: Auth as tester SA in GCP for full api
99104
id: get-full-id-token
100105
uses: "google-github-actions/auth@v2"

common.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-include ../../terraform/.bootstrap_settings/project.env
2+
13
build: remove_artifacts install checkformat pyright generate test
24

35
remove_artifacts:

projects/policyengine-apis-integ/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
include ../../common.mk
2+
US_COUNTRY_PACKAGE_VERSION := $(shell ../../projects/policyengine-api-simulation/dump_package_version.sh policyengine-us)
3+
UK_COUNTRY_PACKAGE_VERSION := $(shell ../../projects/policyengine-api-simulation/dump_package_version.sh policyengine-uk)
4+
25
test: integ-test
36
echo "Skipping default test target in favor of integ-test"
47

@@ -8,4 +11,7 @@ integ-test:
811
$(if $(SIMULATION_API_ACCESS_TOKEN),SIMULATION_INTEG_TEST_ACCESS_TOKEN='$(SIMULATION_API_ACCESS_TOKEN)') \
912
$(if $(FULL_API_URL),FULL_INTEG_TEST_BASE_URL='$(FULL_API_URL)') \
1013
$(if $(SIMULATION_API_URL),SIMULATION_INTEG_TEST_BASE_URL='$(SIMULATION_API_URL)') \
14+
$(if $(TF_VAR_project_id),WORKFLOW_INTEG_TEST_PROJECT_ID='$(TF_VAR_project_id)') \
15+
$(if $(PROJECT_ID),WORKFLOW_INTEG_TEST_PROJECT_ID='$(PROJECT_ID)') \
16+
WORKFLOW_INTEG_TEST_US_MODEL_VERSION='$(US_COUNTRY_PACKAGE_VERSION)' \
1117
uv run pytest -n auto

projects/policyengine-apis-integ/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies = [
88
"policyengine_full_api_client",
99
"policyengine_simulation_api_client",
1010
"pydantic-settings (>=2.8.1,<3.0.0)",
11+
"google-cloud-workflows>=1.18.1",
1112
]
1213

1314
[project.optional-dependencies]

projects/policyengine-apis-integ/tests/simulation_workflow/__init__.py

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pydantic_settings import BaseSettings, SettingsConfigDict
2+
import pytest
3+
from .simplified_workflow_client import SimplifiedWorkflowClient
4+
5+
6+
class Settings(BaseSettings):
7+
project_id: str = "UNKNOWN_PROJECT_ID"
8+
location: str = "us-central1"
9+
workflow_id: str = "simulation-workflow"
10+
us_model_version: str = "UNKNOWN_US_MODEL_VERSION"
11+
12+
model_config = SettingsConfigDict(env_prefix="workflow_integ_test_")
13+
14+
15+
settings = Settings()
16+
17+
18+
@pytest.fixture()
19+
def us_model_version() -> str:
20+
return settings.us_model_version
21+
22+
23+
@pytest.fixture()
24+
def client() -> SimplifiedWorkflowClient:
25+
return SimplifiedWorkflowClient(
26+
settings.project_id, settings.location, settings.workflow_id
27+
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import json
2+
from typing import Any
3+
4+
from google.cloud import workflows_v1
5+
from google.cloud.workflows import executions_v1
6+
7+
from google.cloud.workflows.executions_v1.types import executions
8+
9+
10+
class SimplifiedWorkflowClient:
11+
def __init__(self, project_id: str, location: str, workflow_id: str):
12+
self.execution_client = executions_v1.ExecutionsClient()
13+
self.workflows_client = workflows_v1.WorkflowsClient()
14+
self.project_id = project_id
15+
self.location = location
16+
self.workflow_id = workflow_id
17+
18+
def execute(self, argument: Any) -> executions.Execution:
19+
parent = self.workflows_client.workflow_path(
20+
self.project_id, self.location, self.workflow_id
21+
)
22+
response = self.execution_client.create_execution(
23+
parent=parent,
24+
execution=executions.Execution(argument=json.dumps(argument)),
25+
)
26+
27+
execution_finished = False
28+
while True:
29+
execution = self.execution_client.get_execution(
30+
request={"name": response.name}
31+
)
32+
execution_finished = execution.state != executions.Execution.State.ACTIVE
33+
if execution_finished:
34+
return execution
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from .simplified_workflow_client import SimplifiedWorkflowClient
2+
from google.cloud.workflows.executions_v1.types import executions
3+
4+
5+
def test_calculate_default_model(client: SimplifiedWorkflowClient):
6+
execution = client.execute(
7+
argument={
8+
"country": "us", # don't use uk. It will try to load extra stuff from huggingface
9+
"scope": "macro",
10+
"reform": {
11+
"gov.irs.credits.ctc.refundable.fully_refundable": {
12+
"2023-01-01.2100-12-31": True
13+
}
14+
},
15+
"subsample": 200, # reduce the number of households to speed things up.
16+
"data": "gs://policyengine-us-data/cps_2023.h5", # force the service to use google storage (policyengine.py defaults to huggingface)
17+
}
18+
)
19+
assert execution.state == executions.Execution.State.SUCCEEDED
20+
21+
22+
def test_calculate_specific_model(
23+
client: SimplifiedWorkflowClient, us_model_version: str
24+
):
25+
execution = client.execute(
26+
argument={
27+
"country": "us", # don't use uk. It will try to load extra stuff from huggingface
28+
"model_version": us_model_version,
29+
"scope": "macro",
30+
"reform": {
31+
"gov.irs.credits.ctc.refundable.fully_refundable": {
32+
"2023-01-01.2100-12-31": True
33+
}
34+
},
35+
"subsample": 200, # reduce the number of households to speed things up.
36+
"data": "gs://policyengine-us-data/cps_2023.h5", # force the service to use google storage (policyengine.py defaults to huggingface)
37+
}
38+
)
39+
assert execution.state == executions.Execution.State.SUCCEEDED

0 commit comments

Comments
 (0)