Adding test for LoginPage
This commit is contained in:
0
tests/auth/__init__.py
Normal file
0
tests/auth/__init__.py
Normal file
39
tests/auth/test_login.py
Normal file
39
tests/auth/test_login.py
Normal 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")
|
||||
0
tests/auth/test_register.py
Normal file
0
tests/auth/test_register.py
Normal file
33
tests/auth/test_utils.py
Normal file
33
tests/auth/test_utils.py
Normal 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")
|
||||
Reference in New Issue
Block a user