Skip to content

Commit f82f939

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

File tree

2 files changed

+63
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)