Working on LoginPage tests
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import os
|
||||
|
||||
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.auth.utils import create_auth_beforeware, register_user
|
||||
from myfasthtml.core.testclient import MyTestClient
|
||||
|
||||
|
||||
@@ -10,7 +12,7 @@ from myfasthtml.core.testclient import MyTestClient
|
||||
def app():
|
||||
beforeware = create_auth_beforeware()
|
||||
test_app, test_rt = fast_app(before=beforeware)
|
||||
setup_auth_routes(test_app, test_rt)
|
||||
setup_auth_routes(test_app, test_rt, mount_auth_app=True, sqlite_db_path="TestUsers.db")
|
||||
return test_app
|
||||
|
||||
|
||||
@@ -24,16 +26,34 @@ def user(app):
|
||||
user = MyTestClient(app)
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def cleanup():
|
||||
if os.path.exists("TestUsers.db"):
|
||||
os.remove("TestUsers.db")
|
||||
|
||||
|
||||
def test_i_can_see_login_page(user):
|
||||
user.open("/login")
|
||||
user.should_see("Sign In")
|
||||
user.should_see("Register here")
|
||||
|
||||
user.find_form(fields=["Email", "Password"])
|
||||
|
||||
|
||||
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")
|
||||
form = user.find_form(fields=["Email", "Password"])
|
||||
form.fill(Email="user@email.com", Password="#Passw0rd")
|
||||
form.submit()
|
||||
user.should_see("Invalid email or password. Please try again.")
|
||||
|
||||
|
||||
def test_i_can_login_with_correct_credentials(user):
|
||||
# create user
|
||||
register_user("user@email.com", "user", "#Passw0rd")
|
||||
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user