48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
import pytest
|
|
from fasthtml.fastapp import fast_app
|
|
|
|
from myfasthtml.auth.utils import create_auth_beforeware
|
|
from myfasthtml.core.utils import quoted_str
|
|
from myfasthtml.test.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")
|
|
|
|
|
|
@pytest.mark.parametrize("actual,expected", [
|
|
("string", '"string"'),
|
|
("string with 'single quotes'", '''"string with 'single quotes'"'''),
|
|
('string with "double quotes"', """'string with "double quotes"'"""),
|
|
("""string with 'single' and "double" quotes""", '''"string with 'single' and \\"double\\" quotes"'''),
|
|
(None, "None"),
|
|
(123, "123"),
|
|
])
|
|
def test_i_can_quote_str(actual, expected):
|
|
assert quoted_str(actual) == expected
|