Add meal tracker app: Flask + SQLite with auth, dashboard, 31 passing tests, Docker Compose
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
"""Integration tests for HTTP routes."""
|
||||
|
||||
from datetime import date
|
||||
|
||||
|
||||
class TestDashboardRoute:
|
||||
def test_dashboard_requires_login(self, client):
|
||||
resp = client.get("/dashboard", follow_redirects=True)
|
||||
assert b"Log In" in resp.data
|
||||
|
||||
def test_dashboard_shows_today(self, auth_client):
|
||||
resp = auth_client.get("/dashboard")
|
||||
assert resp.status_code == 200
|
||||
assert b"Today" in resp.data
|
||||
|
||||
def test_dashboard_renders_users(self, auth_client):
|
||||
resp = auth_client.get("/dashboard")
|
||||
# bob and alice were registered
|
||||
assert b"alice" in resp.data
|
||||
assert b"bob" in resp.data
|
||||
assert b"Lunch" in resp.data
|
||||
assert b"Dinner" in resp.data
|
||||
|
||||
|
||||
class TestRespondRoute:
|
||||
def test_respond_sets_status(self, auth_client):
|
||||
resp = auth_client.post("/respond", data={
|
||||
"meal_type": "lunch",
|
||||
"status": "yes",
|
||||
}, follow_redirects=True)
|
||||
assert resp.status_code == 200
|
||||
# After responding, the "Home" chip should be active
|
||||
assert b"Home" in resp.data
|
||||
|
||||
def test_respond_changes_mind(self, auth_client):
|
||||
# First respond yes
|
||||
auth_client.post("/respond", data={
|
||||
"meal_type": "dinner",
|
||||
"status": "yes",
|
||||
})
|
||||
# Then change to no
|
||||
resp = auth_client.post("/respond", data={
|
||||
"meal_type": "dinner",
|
||||
"status": "no",
|
||||
}, follow_redirects=True)
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_respond_invalid_meal_type(self, auth_client):
|
||||
resp = auth_client.post("/respond", data={
|
||||
"meal_type": "breakfast",
|
||||
"status": "yes",
|
||||
}, follow_redirects=True)
|
||||
assert b"Invalid meal type" in resp.data
|
||||
|
||||
def test_respond_invalid_status(self, auth_client):
|
||||
resp = auth_client.post("/respond", data={
|
||||
"meal_type": "lunch",
|
||||
"status": "maybe",
|
||||
}, follow_redirects=True)
|
||||
assert b"Invalid status" in resp.data
|
||||
|
||||
|
||||
class TestHistoryRoute:
|
||||
def test_history_requires_login(self, client):
|
||||
resp = client.get("/history", follow_redirects=True)
|
||||
assert b"Log In" in resp.data
|
||||
|
||||
def test_history_shows_past_date(self, auth_client):
|
||||
past = date.today().replace(year=date.today().year - 1)
|
||||
resp = auth_client.get(f"/history?date={past.isoformat()}")
|
||||
assert resp.status_code == 200
|
||||
assert b"History" in resp.data
|
||||
Reference in New Issue
Block a user