Adding test for LoginPage

This commit is contained in:
2025-10-26 20:26:32 +01:00
parent f39205dba0
commit b98e52378e
14 changed files with 1003 additions and 8 deletions

0
tests/auth/__init__.py Normal file
View File

39
tests/auth/test_login.py Normal file
View File

@@ -0,0 +1,39 @@
import pytest
from fasthtml.fastapp import fast_app
from myfasthtml.auth.routes import setup_auth_routes
from myfasthtml.auth.utils import create_auth_beforeware
from myfasthtml.core.testclient import MyTestClient
@pytest.fixture()
def app():
beforeware = create_auth_beforeware()
test_app, test_rt = fast_app(before=beforeware)
setup_auth_routes(test_app, test_rt)
return test_app
@pytest.fixture()
def rt(app):
return app.route
@pytest.fixture()
def user(app):
user = MyTestClient(app)
return user
def test_i_can_see_login_page(user):
user.open("/login")
user.should_see("Sign In")
user.should_see("Register here")
def test_i_cannot_login_with_wrong_credentials(user):
user.open("/login")
user.fill_form({
"username": "wrong",
"password": ""
})
user.click("button")
user.should_see("Invalid credentials")

View File

33
tests/auth/test_utils.py Normal file
View File

@@ -0,0 +1,33 @@
import pytest
from fasthtml.fastapp import fast_app
from myfasthtml.auth.utils import create_auth_beforeware
from myfasthtml.core.testclient import MyTestClient
def test_non_protected_route():
app, rt = fast_app()
user = MyTestClient(app)
@rt('/')
def index(): return "Welcome"
@rt('/login')
def index(): return "Sign In"
user.open("/")
user.should_see("Welcome")
def test_all_routes_are_protected():
beforeware = create_auth_beforeware()
app, rt = fast_app(before=beforeware)
user = MyTestClient(app)
@rt('/')
def index(): return "Welcome"
@rt('/login')
def index(): return "Sign In"
user.open("/")
user.should_see("Sign In")