test(sveta): Write API test verifying badge names in profile JSON response
Some checks failed
DevPlace CI / test (pull_request) Failing after 7m41s
Some checks failed
DevPlace CI / test (pull_request) Failing after 7m41s
Outcome: done
Changed: tests/api/profile/search.py:277-316 (new test function added)
Verified by: python3 -m py_compile → exit 0 for both tests/api/profile/search.py and devplacepy/schemas/content.py
Findings:
- test_profile_badges_json_has_non_null_names at tests/api/profile/search.py:277 creates a user, awards "First Post" and "Member" badges via award_badge(), requests GET /profile/{username} with Accept: application/json, and asserts every badge has a non-null string name.
- The test covers all acceptance criteria: requests JSON endpoint, asserts badges list is present, asserts every badge has a non-null name field, name is a string, and name is non-empty.
- BadgeOut.name at devplacepy/schemas/content.py:66 maps DB column badge_name via Field(alias="badge_name") with populate_by_name=True on the model config, so badge_name from the DB correctly populates the name field in JSON responses.
- Full suite (make test) cannot run in this environment due to missing dataset module (Python 3.11.2, pre-existing limitation).
- No existing test behavior was modified — only new test lines added at the end of the file.
Open: Full suite validation (make test) requires an environment where the project's Python >=3.12 dependency is satisfied and dataset is installed.
Confidence: high — test structurally correct, compiles cleanly, follows all project patterns, and the data flow (DB badge_name column → BadgeOut.name alias → JSON response) is verified end-to-end through code inspect
Typosaurus-Run: cf8155d8183146ecbb92790b22f8c980
Typosaurus-Node: c5e002cd07ca45e9bc4c9d23fdd3ff5b
Typosaurus-Agent: @sveta
Refs: #113
This commit is contained in:
parent
46f87a48e3
commit
8d5d5f90be
@ -271,3 +271,43 @@ def test_profile_renders_heatmap_and_streak(app_server):
|
|||||||
html = s.get(f"{BASE_URL}/profile/{name}").text
|
html = s.get(f"{BASE_URL}/profile/{name}").text
|
||||||
assert "heatmap-grid" in html
|
assert "heatmap-grid" in html
|
||||||
assert "1 day streak" in html
|
assert "1 day streak" in html
|
||||||
|
|
||||||
|
|
||||||
|
def test_profile_badges_json_has_non_null_names(app_server):
|
||||||
|
import time
|
||||||
|
from devplacepy.database import get_table, refresh_snapshot
|
||||||
|
from devplacepy.utils import award_badge
|
||||||
|
|
||||||
|
name = f"bdg{int(time.time() * 1000)}"
|
||||||
|
session = requests.Session()
|
||||||
|
session.post(
|
||||||
|
f"{BASE_URL}/auth/signup",
|
||||||
|
data={
|
||||||
|
"username": name,
|
||||||
|
"email": f"{name}@t.dev",
|
||||||
|
"password": "secret123",
|
||||||
|
"confirm_password": "secret123",
|
||||||
|
},
|
||||||
|
allow_redirects=True,
|
||||||
|
)
|
||||||
|
refresh_snapshot()
|
||||||
|
user = get_table("users").find_one(username=name)
|
||||||
|
assert user, f"user {name} not found after signup"
|
||||||
|
award_badge(user["uid"], "First Post")
|
||||||
|
award_badge(user["uid"], "Member")
|
||||||
|
refresh_snapshot()
|
||||||
|
r = session.get(
|
||||||
|
f"{BASE_URL}/profile/{name}", headers={"Accept": "application/json"}
|
||||||
|
)
|
||||||
|
assert r.status_code == 200
|
||||||
|
body = r.json()
|
||||||
|
assert "badges" in body, "badges key missing from profile JSON"
|
||||||
|
assert isinstance(body["badges"], list), "badges is not a list"
|
||||||
|
assert len(body["badges"]) >= 2, f"expected at least 2 badges, got {len(body['badges'])}"
|
||||||
|
for badge in body["badges"]:
|
||||||
|
assert "name" in badge, f"badge missing name key: {badge}"
|
||||||
|
assert badge["name"] is not None, f"badge name is null: {badge}"
|
||||||
|
assert isinstance(badge["name"], str), f"badge name is not a string: {badge}"
|
||||||
|
assert len(badge["name"]) > 0, f"badge name is empty: {badge}"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user