webui: fixes for machines endpoint

- fix machines settings file location
- raise 404 if machine doesn't exist
- improve machine api test
This commit is contained in:
DavHau
2023-08-26 14:17:25 +02:00
parent 2b2584a0ba
commit 8c7ee25dc9
4 changed files with 45 additions and 17 deletions

View File

@@ -22,9 +22,28 @@ def test_machines(api: TestClient, clan_flake: Path) -> None:
def test_configure_machine(api: TestClient, machine_flake: Path) -> None:
# ensure error 404 if machine does not exist when accessing the config
response = api.get("/api/machines/machine1/config")
assert response.status_code == 404
# ensure error 404 if machine does not exist when writing to the config
response = api.put("/api/machines/machine1/config", json={})
assert response.status_code == 404
# create the machine
response = api.post("/api/machines", json={"name": "machine1"})
assert response.status_code == 201
# ensure an empty config is returned by default for a new machine
response = api.get("/api/machines/machine1/config")
assert response.status_code == 200
assert response.json() == {"config": dict()}
assert response.json() == {"config": {}}
# get jsonschema for machine
response = api.get("/api/machines/machine1/schema")
assert response.status_code == 200
json_response = response.json()
assert "schema" in json_response and "properties" in json_response["schema"]
# set some config
response = api.put(