Adding test for LoginPage
This commit is contained in:
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