"""Tests for login/logout routes.""" from fastapi.testclient import TestClient class TestLoginPage: """Tests for GET /login.""" def test_login_page_returns_200(self, client: TestClient) -> None: """GET /login should render the login form.""" response = client.get("/login") assert response.status_code == 200 assert "Login" in response.text def test_login_page_has_form(self, client: TestClient) -> None: """GET /login should contain a login form with username and password.""" response = client.get("/login") assert 'name="username"' in response.text assert 'name="password"' in response.text class TestLoginPost: """Tests for POST /login.""" def test_login_invalid_credentials_shows_error(self, client: TestClient) -> None: """POST /login with wrong credentials should show error message.""" response = client.post( "/login", data={"username": "wrong", "password": "wrong"}, follow_redirects=False, ) # Should re-render login page with error or redirect back assert response.status_code in (200, 303) class TestLogout: """Tests for GET /logout.""" def test_logout_redirects_to_login(self, client: TestClient) -> None: """GET /logout should clear session and redirect to login.""" response = client.get("/logout", follow_redirects=False) assert response.status_code in (303, 307) assert "/login" in response.headers.get("location", "")