Skip to content

Commit 30a7429

Browse files
authored
Add test for citations.py (#117)
* used AI to generate several tests to hit 100% statement coverage in citations.py * fix formatting
1 parent 7324543 commit 30a7429

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

backend/tests/test_citations.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import pytest
2+
from flask import Flask
3+
from tenantfirstaid.citations import get_citation, SECTIONS
4+
5+
6+
@pytest.fixture
7+
def app():
8+
app = Flask(__name__)
9+
app.add_url_rule("/api/citation", view_func=get_citation, methods=["GET"])
10+
return app
11+
12+
13+
@pytest.fixture
14+
def client(app):
15+
return app.test_client()
16+
17+
18+
def test_get_citation_success(client):
19+
# Use a valid section from SECTIONS
20+
section = next(iter(SECTIONS))
21+
response = client.get(f"/api/citation?section={section}")
22+
assert response.status_code == 200
23+
data = response.get_json()
24+
assert data["section"] == section
25+
assert data["text"] == SECTIONS[section]
26+
27+
28+
def test_get_citation_missing_param(client):
29+
response = client.get("/api/citation")
30+
assert response.status_code == 400
31+
assert b"missing query param" in response.data
32+
33+
34+
def test_get_citation_unknown_section(client):
35+
response = client.get("/api/citation?section=notarealsection")
36+
assert response.status_code == 404
37+
assert b"not found" in response.data
38+
39+
40+
def test_get_citation_empty_section_param(client):
41+
response = client.get("/api/citation?section=")
42+
assert response.status_code == 400
43+
assert b"missing query param" in response.data

0 commit comments

Comments
 (0)