Skip to content

Commit a2d8cdc

Browse files
committed
Improve tests for API prefix
This adds an API prefix to `test_server_thing_descriptions` and fixes the expected URLs so the test no longer fails. Form URLs now include the API prefix (and the `base` of thing descriptions should just be the server and port). I've also added a further test that the Thing Descriptions returned individually (by e.g. `/mything/`) are identical to those returned by `/thing_descriptions/`. This PR is the second time I've seen inconsistencies there, and this test should help eliminate them.
1 parent e42e5dc commit a2d8cdc

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

tests/test_server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def test_server_thing_descriptions():
3535
"class": "labthings_fastapi.example_things:MyThing",
3636
"kwargs": {},
3737
},
38-
}
38+
},
39+
"api_prefix": "/api",
3940
}
4041

4142
thing_names = ["thing1", "thing2"]
@@ -51,7 +52,7 @@ def test_server_thing_descriptions():
5152

5253
server = lt.ThingServer.from_config(conf)
5354
with TestClient(server.app) as client:
54-
response = client.get("/thing_descriptions/")
55+
response = client.get("/api/thing_descriptions/")
5556
response.raise_for_status()
5657
thing_descriptions = response.json()
5758

@@ -63,12 +64,12 @@ def test_server_thing_descriptions():
6364

6465
for action_name in actions:
6566
action = thing_description["actions"][action_name]
66-
expected_href = thing_name + "/" + action_name
67+
expected_href = f"/api/{thing_name}/{action_name}"
6768
assert action["forms"][0]["href"] == expected_href
6869

6970
for prop_name in props:
7071
prop = thing_description["properties"][prop_name]
71-
expected_href = thing_name + "/" + prop_name
72+
expected_href = f"/api/{thing_name}/{prop_name}"
7273
assert prop["forms"][0]["href"] == expected_href
7374

7475

@@ -129,3 +130,4 @@ def test_things_endpoints():
129130
response.raise_for_status()
130131
td = response.json()
131132
assert td["title"] == "MyThing"
133+
assert tds["thing_a"] == td

0 commit comments

Comments
 (0)