<filename>tests/endpoints/test_login.py<gh_stars>1-10
import pytest


def test_get(client):
    response = client.get("/auth/login")
    assert response.status_code == 200


def test_can_login(client, user):
    response = client.post(
        "/auth/login", data={"email": "<EMAIL>", "password": "password"}
    )

    assert response.status_code == 302
    assert response.next.url == "http://testserver/"

    response = client.get("/")
    assert response.json() == {"user": "<EMAIL>"}


def test_user_last_login_set(client, user):
    assert user.last_login is None
    response = client.post(
        "/auth/login", data={"email": "<EMAIL>", "password": "password"}
    )
    user.refresh_from_db()
    assert user.last_login is not None


@pytest.mark.parametrize(
    "test_data",
    [
        {},
        {"email": "", "password": ""},
        {"email": " ", "password": " "},
        {"email": "<EMAIL>", "password": "<PASSWORD>"},
        {"email": "<EMAIL>", "password": "password"},
    ],
)
def test_invalid_credentials(test_data, client, user):
    response = client.post("/auth/login", data=test_data)

    assert response.status_code == 200
    assert response.url == "http://testserver/auth/login"

<filename>tests/endpoints/test_login.py<gh_stars>1-10
import pytest


def test_get(client):
    response = client.get("/auth/login")
    assert response.status_code == 200


def test_can_login(client, user):
    response = client.post(
        "/auth/login", data={"email": "<EMAIL>", "password": "password"}
    )

    assert response.status_code == 302
    assert response.next.url == "http://testserver/"

    response = client.get("/")
    assert response.json() == {"user": "<EMAIL>"}


def test_user_last_login_set(client, user):
    assert user.last_login is None
    response = client.post(
        "/auth/login", data={"email": "<EMAIL>", "password": "password"}
    )
    user.refresh_from_db()
    assert user.last_login is not None


@pytest.mark.parametrize(
    "test_data",
    [
        {},
        {"email": "", "password": ""},
        {"email": " ", "password": " "},
        {"email": "<EMAIL>", "password": "<PASSWORD>"},
        {"email": "<EMAIL>", "password": "password"},
    ],
)
def test_invalid_credentials(test_data, client, user):
    response = client.post("/auth/login", data=test_data)

    assert response.status_code == 200
    assert response.url == "http://testserver/auth/login"
