@@ -12,8 +12,9 @@ def client():
1212 with app .test_client () as client :
1313 yield client
1414
15+
1516def test_homepage_v1 (client ):
16- expect_selfie (client .get ("/" ).data .decode ()).to_be ("""
17+ expect_selfie (client .get ("/" ).data .decode ()).to_be ("""
1718<html><body>
1819 <h1>Please login</h1>
1920 <form action="/login" method="post">
@@ -22,8 +23,9 @@ def test_homepage_v1(client):
2223 </form>
2324</body></html>""" )
2425
26+
2527def test_homepage_v2 (client ):
26- web_selfie (client .get ("/" )).to_be ("""<html>
28+ web_selfie (client .get ("/" )).to_be ("""<html>
2729 <body>
2830 <h1>
2931 Please login
@@ -39,37 +41,44 @@ def test_homepage_v2(client):
3941Please login
4042╔═ [status] ═╗
4143200 OK""" )
42-
44+
45+
4346def test_login_flow (client ):
44- web_selfie (client .get ("/" )).to_match_disk ("1. not logged in" ) \
45- .facet ("md" ).to_be ("Please login" )
47+ web_selfie (client .get ("/" )).to_match_disk ("1. not logged in" ).facet ("md" ).to_be (
48+ "Please login"
49+ )
4650
47- web_selfie (
client .
post (
"/login" ,
data = {
"email" :
"[email protected] " }))
\ 48- . to_match_disk ( "2. post login form" ) \
49- .facet ("md" ).to_be ("""Email sent!
51+ web_selfie (
client .
post (
"/login" ,
data = {
"email" :
"[email protected] " }))
. to_match_disk ( 52+ "2. post login form"
53+ ) .facet ("md" ).to_be ("""Email sent!
5054
5155Check your email for your login link.""" )
5256
53- email = wait_for_incoming_email ()
54- expect_selfie (email ).to_be (
57+ email = wait_for_incoming_email ()
58+ expect_selfie (email ).to_be (
5559 {
56605761 "subject" : "Login to example.com" ,
5862 "html_content" : 'Click <a href="http://localhost/login-confirm/2Yw4aCQ">here</a> to login.' ,
5963 }
6064 )
61-
62- web_selfie (client .get ("/login-confirm/2Yw4aCQ" )).to_be ("""REDIRECT 302 Found to /
65+
66+ web_selfie (client .get ("/login-confirm/2Yw4aCQ" )).to_be ("""REDIRECT 302 Found to /
6367╔═ [cookies] ═╗
6468[email protected] |29Xwa32OsHUoHm4TRitwQMWpuynz3r1aw3BcB5pPGdY=; Path=/""")
6569
66- client .
set_cookie (
'login' ,
'[email protected] |29Xwa32OsHUoHm4TRitwQMWpuynz3r1aw3BcB5pPGdY=' )
67- web_selfie (client .get ("/" )).to_match_disk ("3. log in works with cookies" ) \
68- .
facet (
"md" ).
to_be (
"Welcome back [email protected] " )
70+ client .set_cookie (
71+ "login" ,
"[email protected] |29Xwa32OsHUoHm4TRitwQMWpuynz3r1aw3BcB5pPGdY=" 72+ )
73+ web_selfie (client .get ("/" )).to_match_disk ("3. log in works with cookies" ).facet (
74+ "md"
75+ ).
to_be (
"Welcome back [email protected] " )
76+
77+ client .
set_cookie (
"login" ,
"[email protected] |ABCDEF" )
78+ web_selfie (client .get ("/" )).to_match_disk (
79+ "4. log in fails with fake cookies"
80+ ).facet ("status" ).to_be ("401 UNAUTHORIZED" )
6981
70- client .
set_cookie (
'login' ,
'[email protected] |ABCDEF' )
71- web_selfie (client .get ("/" )).to_match_disk ("4. log in fails with fake cookies" ) \
72- .facet ("status" ).to_be ("401 UNAUTHORIZED" )
7382
7483if __name__ == "__main__" :
7584 pytest .main ()
0 commit comments