import pytest


class TestLoginPage:
    def test_login_page_loads(self, unauthed_client):
        resp = unauthed_client.get("/login")
        assert resp.status_code == 200
        assert "Sign In" in resp.text or "Login" in resp.text or "login" in resp.text

    def test_valid_login(self, unauthed_client):
        resp = unauthed_client.post("/login", data={
            "username": "testadmin",
            "password": "testpass"
        }, follow_redirects=False)
        assert resp.status_code in (302, 303, 200)

    def test_invalid_login(self, unauthed_client):
        resp = unauthed_client.post("/login", data={
            "username": "testadmin",
            "password": "wrongpassword"
        })
        assert resp.status_code in (200, 401, 403)

    def test_protected_route_redirects_when_unauthed(self, unauthed_client):
        resp = unauthed_client.get("/", follow_redirects=False)
        assert resp.status_code in (302, 303, 307)

    def test_static_files_bypass_auth(self, unauthed_client):
        resp = unauthed_client.get("/static/style.css")
        assert resp.status_code in (200, 404)
