Skip to content

Commit 1ad2a35

Browse files
committed
test: Add health endpoint and version retrieval tests
1 parent 9a76c20 commit 1ad2a35

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/test_health.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def test_health_endpoint(client):
2+
r = client.get("/health")
3+
assert r.status_code == 200
4+
assert r.json().get("status") == "ok"
5+

tests/test_version.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import importlib
2+
from pathlib import Path
3+
4+
5+
def test_get_version_uses_package_metadata(monkeypatch):
6+
# Force VERSION file to be treated as missing
7+
orig_exists = Path.exists
8+
9+
def fake_exists(self): # type: ignore[no-redef]
10+
return False if self.name == "VERSION" else orig_exists(self)
11+
12+
monkeypatch.setattr(Path, "exists", fake_exists, raising=False)
13+
14+
# Patch importlib.metadata.version to return a known value
15+
import importlib.metadata as im
16+
17+
monkeypatch.setattr(im, "version", lambda name: "9.9.9")
18+
19+
from app import _version as ver
20+
21+
assert ver.get_version() == "9.9.9"
22+
23+
24+
def test_get_version_fallback_to_default(monkeypatch):
25+
# Force VERSION file to be treated as missing
26+
orig_exists = Path.exists
27+
28+
def fake_exists(self): # type: ignore[no-redef]
29+
return False if self.name == "VERSION" else orig_exists(self)
30+
31+
monkeypatch.setattr(Path, "exists", fake_exists, raising=False)
32+
33+
# Patch importlib.metadata.version to raise, triggering default fallback
34+
import importlib.metadata as im
35+
36+
def raise_err(_):
37+
raise RuntimeError("no package metadata")
38+
39+
monkeypatch.setattr(im, "version", raise_err)
40+
41+
from app import _version as ver
42+
43+
assert ver.get_version() == "0.0.0"
44+

0 commit comments

Comments
 (0)