I can login test is now working

This commit is contained in:
2025-10-27 21:47:07 +01:00
parent 09d012d065
commit 3f3e3a6ae5
2 changed files with 21 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ import os
import pytest
from fasthtml.fastapp import fast_app
import myfasthtml.auth.utils
from myfasthtml.auth.routes import setup_auth_routes
from myfasthtml.auth.utils import create_auth_beforeware, register_user
from myfasthtml.core.testclient import MyTestClient
@@ -24,7 +25,12 @@ def rt(app):
@pytest.fixture()
def user(app):
user = MyTestClient(app)
return user
previous = myfasthtml.auth.utils.http_client
myfasthtml.auth.utils.http_client = user.client
yield user
myfasthtml.auth.utils.http_client = previous
@pytest.fixture(autouse=True)
@@ -48,12 +54,15 @@ def test_i_cannot_login_with_wrong_credentials(user):
user.should_see("Invalid email or password. Please try again.")
def test_i_can_login_with_correct_credentials(user):
def test_i_can_login_with_correct_credentials(user, rt):
# create user
register_user("user@email.com", "user", "#Passw0rd")
@rt('/')
def index(): return "You are now logged in !"
user.open("/login")
form = user.find_form(fields=["Email", "Password"])
form.fill(Email="user@email.com", Password="#Passw0rd")
form.submit()
user.should_see("You are now logged in")
user.should_see("You are now logged in !")