"""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 in the same household assert b"alice" in resp.data assert b"bob" in resp.data assert b"Lunch" in resp.data assert b"Dinner" in resp.data def test_dashboard_hides_other_households(self, auth_client): """Bob should NOT see users from other households.""" # Register another user in a different household auth_client.get("/logout") auth_client.post("/register", data={ "username": "stranger", "password": "stranger1", "confirm": "stranger1", "household_action": "create", "new_household_name": "Stranger House", }) # Log back in as bob (Test Household) auth_client.get("/logout") auth_client.post("/login", data={ "username": "bob", "password": "bobpass", }) resp = auth_client.get("/dashboard") assert resp.status_code == 200 assert b"stranger" not in resp.data assert b"Stranger House" not 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 assert b"Home" in resp.data def test_respond_changes_mind(self, auth_client): auth_client.post("/respond", data={ "meal_type": "dinner", "status": "yes", }) 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