Skip to content

Commit

Permalink
fix API response and test to handle Brick
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Mar 6, 2024
1 parent 40a1b78 commit 87ade9e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/unit/api/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def test_validate_model(client, building_motif):
assert library_1 is not None
library_2 = Library.load(directory="tests/unit/fixtures/templates")
assert library_2 is not None
brick = Library.load(ontology_graph="tests/unit/fixtures/Brick.ttl")
assert brick is not None

BLDG = Namespace("urn:building/")
model = Model.create(name=BLDG)
Expand All @@ -268,18 +270,19 @@ def test_validate_model(client, building_motif):
results = client.post(
f"/models/{model.id}/validate",
headers={"Content-Type": "application/json"},
json={"library_ids": [library_1.id, library_2.id]},
json={"library_ids": [library_1.id, library_2.id, brick.id]},
)

# Assert
assert results.status_code == 200

assert results.get_json().keys() == {"message", "reasons", "valid"}
assert isinstance(results.get_json()["message"], str)
assert results.get_json()["reasons"] == {
"urn:building/vav1": [
"urn:building/vav1 needs between 1 and None instances of https://brickschema.org/schema/Brick#Air_Flow_Sensor on path https://brickschema.org/schema/Brick#hasPoint"
]
response = results.get_json()
assert "urn:building/vav1" in response["reasons"], "vav1 should be in the response"
assert set(response["reasons"]["urn:building/vav1"]) == {
"urn:building/vav1 needs between 1 and None instances of https://brickschema.org/schema/Brick#Air_Flow_Sensor on path https://brickschema.org/schema/Brick#hasPoint",
"urn:building/vav1 needs between 1 and None instances of https://brickschema.org/schema/Brick#Temperature_Sensor on path https://brickschema.org/schema/Brick#hasPoint",
}
assert not results.get_json()["valid"]

Expand Down

0 comments on commit 87ade9e

Please sign in to comment.