Skip to content

Commit 3f6902d

Browse files
Add more complete checks for fallback server
1 parent 204e35a commit 3f6902d

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[run]
2-
concurrency = multiprocessing
2+
concurrency = multiprocessing, thread
33
parallel = true
44
sigterm = true

tests/test_fallback.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from labthings_fastapi.utilities.object_reference_to_object import (
2+
object_reference_to_object,
3+
)
4+
from fastapi.testclient import TestClient
5+
from labthings_fastapi.server import server_from_config, ThingServer
6+
from labthings_fastapi.server.fallback import app
7+
8+
9+
10+
def test_fallback_empty():
11+
with TestClient(app) as client:
12+
response = client.get("/")
13+
html = response.text
14+
# test that something when wrong is shown
15+
assert "Something went wrong" in html
16+
assert "No logging info available" in html
17+
18+
19+
def test_fallback_with_config():
20+
app.labthings_config = {"hello": "goodbye"}
21+
with TestClient(app) as client:
22+
response = client.get("/")
23+
html = response.text
24+
assert "Something went wrong" in html
25+
assert "No logging info available" in html
26+
assert '"hello": "goodbye"' in html
27+
28+
def test_fallback_with_error():
29+
app.labthings_error = RuntimeError("Custom error message")
30+
with TestClient(app) as client:
31+
response = client.get("/")
32+
html = response.text
33+
assert "Something went wrong" in html
34+
assert "No logging info available" in html
35+
assert 'RuntimeError' in html
36+
assert 'Custom error message' in html
37+
38+
def test_fallback_with_server():
39+
config = {
40+
"things": {
41+
"thing1": "labthings_fastapi.example_things:MyThing",
42+
"thing2": {
43+
"class": "labthings_fastapi.example_things:MyThing",
44+
"kwargs": {},
45+
},
46+
}
47+
}
48+
app.labthings_server = server_from_config(config)
49+
with TestClient(app) as client:
50+
response = client.get("/")
51+
html = response.text
52+
assert "Something went wrong" in html
53+
assert "No logging info available" in html
54+
assert "thing1/" in html
55+
assert "thing2/" in html
56+
57+
def test_fallback_with_log():
58+
app.log_history = "Fake log conetent"
59+
with TestClient(app) as client:
60+
response = client.get("/")
61+
html = response.text
62+
assert "Something went wrong" in html
63+
assert "No logging info available" not in html
64+
assert "<p>Logging info</p>" in html
65+
assert "Fake log conetent" in html

0 commit comments

Comments
 (0)