The auth dependency raises NotAuthenticatedError (not HTTPException), and the exception handler returns a 302 redirect. Updated the unit test to expect NotAuthenticatedError, and all route auth tests to accept 302 alongside 401/303.
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""Tests for workout logging routes."""
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
class TestLogSet:
|
|
"""Tests for POST /log."""
|
|
|
|
def test_log_set_requires_auth(self, client: TestClient) -> None:
|
|
"""POST /log should require admin login."""
|
|
response = client.post(
|
|
"/log",
|
|
data={
|
|
"exercise_id": "1",
|
|
"workout_day_id": "1",
|
|
"set_number": "1",
|
|
"reps": "8",
|
|
"weight": "30 lbs",
|
|
},
|
|
follow_redirects=False,
|
|
)
|
|
assert response.status_code in (401, 302, 303)
|
|
|
|
|
|
class TestLogEdit:
|
|
"""Tests for POST /log/<id>/edit."""
|
|
|
|
def test_edit_log_requires_auth(self, client: TestClient) -> None:
|
|
"""POST /log/1/edit should require admin login."""
|
|
response = client.post(
|
|
"/log/1/edit",
|
|
data={"reps": "10", "weight": "35 lbs"},
|
|
follow_redirects=False,
|
|
)
|
|
assert response.status_code in (401, 302, 303)
|
|
|
|
|
|
class TestLogDelete:
|
|
"""Tests for POST /log/<id>/delete."""
|
|
|
|
def test_delete_log_requires_auth(self, client: TestClient) -> None:
|
|
"""POST /log/1/delete should require admin login."""
|
|
response = client.post("/log/1/delete", follow_redirects=False)
|
|
assert response.status_code in (401, 302, 303)
|