Skip to content

Commit

Permalink
Update constraint violations query and tests for 1.13.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermak committed Oct 19, 2023
1 parent c53167c commit f0b79ff
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
22 changes: 18 additions & 4 deletions src/aerie_cli/aerie_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions tests/integration_tests/files/constraints/constraint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default (): Constraint => {

}
return Discrete.Resource('/flag').equal('B')
}

20 changes: 12 additions & 8 deletions tests/integration_tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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

0 comments on commit f0b79ff

Please sign in to comment.