From f0b79ff7a4e15a81167a63ef6327527b291d2bdd Mon Sep 17 00:00:00 2001 From: Carter Mak Date: Thu, 19 Oct 2023 14:29:26 -0700 Subject: [PATCH] Update constraint violations query and tests for 1.13.0+ --- src/aerie_cli/aerie_client.py | 22 +++++++++++++++---- .../files/constraints/constraint.ts | 5 +++-- tests/integration_tests/test_constraints.py | 20 ++++++++++------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/aerie_cli/aerie_client.py b/src/aerie_cli/aerie_client.py index 5c742115..a0c35bb4 100644 --- a/src/aerie_cli/aerie_client.py +++ b/src/aerie_cli/aerie_client.py @@ -1630,15 +1630,29 @@ def get_constraint_by_id(self, id): def get_constraint_violations(self, plan_id): get_violations_query = """ - query ($plan_id: Int!){ - constraintViolations(planId: $plan_id) { - violations + query ($plan_id: Int!) { + constraintResults: constraintViolations(planId: $plan_id) { + constraintId + constraintName + type + resourceIds + violations { + activityInstanceIds + windows { + start + end + } + } + gaps { + start + end + } } } """ resp = self.aerie_host.post_to_graphql(get_violations_query, plan_id=plan_id) - return resp["violations"] + return resp def get_resource_types(self, model_id: int) -> List[ResourceType]: """Get resource types (value schema) diff --git a/tests/integration_tests/files/constraints/constraint.ts b/tests/integration_tests/files/constraints/constraint.ts index d6d85775..160ae3dc 100644 --- a/tests/integration_tests/files/constraints/constraint.ts +++ b/tests/integration_tests/files/constraints/constraint.ts @@ -1,3 +1,4 @@ export default (): Constraint => { - -} \ No newline at end of file + return Discrete.Resource('/flag').equal('B') + } + \ No newline at end of file diff --git a/tests/integration_tests/test_constraints.py b/tests/integration_tests/test_constraints.py index f1c8430d..1b04ce1d 100644 --- a/tests/integration_tests/test_constraints.py +++ b/tests/integration_tests/test_constraints.py @@ -48,6 +48,7 @@ def set_up_environment(request): plan_to_create.name += arrow.utcnow().format("YYYY-MM-DDTHH-mm-ss") global plan_id plan_id = client.create_activity_plan(model_id, plan_to_create) + client.simulate_plan(plan_id) def test_constraint_upload(): result = runner.invoke(app, ["constraints", "upload"], @@ -76,20 +77,23 @@ def test_constraint_update(): f"{result.stderr}" assert "Updated constraint" in result.stdout -def test_constraint_delete(): - result = runner.invoke(app, ["constraints", "delete"], - input=str(constraint_id) + "\n", +def test_constraint_violations(): + result = runner.invoke(app, ["constraints", "violations"], + input=str(plan_id) + "\n", catch_exceptions=False,) assert result.exit_code == 0,\ f"{result.stdout}"\ f"{result.stderr}" - assert f"Successfully deleted constraint {str(constraint_id)}" in result.stdout -def test_constraint_violations(): - result = runner.invoke(app, ["constraints", "violations"], - input=str(plan_id) + "\n", + # Check that a constraint violation is returned with the open bracket and curly brace + # (The integration test constraint should report a violation) + assert "Constraint violations: [{" in result.stdout + +def test_constraint_delete(): + result = runner.invoke(app, ["constraints", "delete"], + input=str(constraint_id) + "\n", catch_exceptions=False,) assert result.exit_code == 0,\ f"{result.stdout}"\ f"{result.stderr}" - assert "Constraint violations: " in result.stdout + assert f"Successfully deleted constraint {str(constraint_id)}" in result.stdout