Skip to content

Add test for citations.py #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions backend/tests/test_citations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest
from flask import Flask
from tenantfirstaid.citations import get_citation, SECTIONS


@pytest.fixture
def app():
app = Flask(__name__)
app.add_url_rule("/api/citation", view_func=get_citation, methods=["GET"])
return app


@pytest.fixture
def client(app):
return app.test_client()


def test_get_citation_success(client):
# Use a valid section from SECTIONS
section = next(iter(SECTIONS))
response = client.get(f"/api/citation?section={section}")
assert response.status_code == 200
data = response.get_json()
assert data["section"] == section
assert data["text"] == SECTIONS[section]


def test_get_citation_missing_param(client):
response = client.get("/api/citation")
assert response.status_code == 400
assert b"missing query param" in response.data


def test_get_citation_unknown_section(client):
response = client.get("/api/citation?section=notarealsection")
assert response.status_code == 404
assert b"not found" in response.data


def test_get_citation_empty_section_param(client):
response = client.get("/api/citation?section=")
assert response.status_code == 400
assert b"missing query param" in response.data