api/schema: don't crash on eval error

This commit is contained in:
DavHau
2023-11-10 14:27:03 +07:00
parent c194adc181
commit 97ea9312ac
2 changed files with 17 additions and 1 deletions

View File

@@ -22,6 +22,21 @@ def test_machines(api: TestClient, test_flake: FlakeForTest) -> None:
assert response.json() == {"machines": [{"name": "test", "status": "unknown"}]}
@pytest.mark.with_core
def test_schema_errors(api: TestClient, test_flake_with_core: FlakeForTest) -> None:
# make sure that eval errors do not raise an internal server error
response = api.put(
f"/api/{test_flake_with_core.name}/schema",
json={"imports": ["some-inavlid-import"]},
)
assert response.status_code == 422
# expect error to contain "error: string 'some-inavlid-import' doesn't represent an absolute path"
assert (
"error: string 'some-inavlid-import' doesn't represent an absolute path"
in response.json()["detail"][0]["msg"]
)
@pytest.mark.with_core
def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest) -> None:
# ensure error 404 if machine does not exist when accessing the config