-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
989 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,18 @@ def client(): | |
yield client | ||
|
||
|
||
def test_homepage(client): | ||
def test_homepage_v1(client): | ||
expect_selfie(client.get("/").data.decode()).to_be(""" | ||
<html><body> | ||
<h1>Please login</h1> | ||
<form action="/login" method="post"> | ||
<input type="text" name="email" placeholder="email"> | ||
<input type="submit" value="login"> | ||
</form> | ||
</body></html>""") | ||
|
||
|
||
def test_homepage_v2(client): | ||
web_selfie(client.get("/")).to_be("""<html> | ||
<body> | ||
<h1> | ||
|
@@ -32,25 +43,16 @@ def test_homepage(client): | |
200 OK""") | ||
|
||
|
||
def test_T01_not_logged_in(client): | ||
response = client.get("/") | ||
expect_selfie(response.data.decode()).to_be(""" | ||
<html><body> | ||
<h1>Please login</h1> | ||
<form action="/login" method="post"> | ||
<input type="text" name="email" placeholder="email"> | ||
<input type="submit" value="login"> | ||
</form> | ||
</body></html>""") | ||
def test_login_flow(client): | ||
web_selfie(client.get("/")).to_match_disk("1. not logged in").facet("md").to_be( | ||
"Please login" | ||
) | ||
|
||
web_selfie(client.post("/login", data={"email": "[email protected]"})).to_match_disk( | ||
"2. post login form" | ||
).facet("md").to_be("""Email sent! | ||
def test_T02_login(client): | ||
response = client.post("/login", data={"email": "[email protected]"}) | ||
expect_selfie(response.data.decode()).to_be(""" | ||
<html><body> | ||
<h1>Email sent!</h1> | ||
<p>Check your email for your login link.</p> | ||
</body></html>""") | ||
Check your email for your login link.""") | ||
|
||
email = wait_for_incoming_email() | ||
expect_selfie(email).to_be( | ||
|
@@ -61,19 +63,21 @@ def test_T02_login(client): | |
} | ||
) | ||
|
||
web_selfie(client.get("/login-confirm/2Yw4aCQ")).to_be("""REDIRECT 302 Found to / | ||
╔═ [cookies] ═╗ | ||
[email protected]|29Xwa32OsHUoHm4TRitwQMWpuynz3r1aw3BcB5pPGdY=; Path=/""") | ||
|
||
def test_T03_login_confirm(client): | ||
response = client.get("/login-confirm/erjchFY=", follow_redirects=False) | ||
expect_selfie(headers_to_string(response)).to_be("""200 OK | ||
Content-Type=text/html; charset=utf-8""") | ||
|
||
|
||
def headers_to_string(response): | ||
headers = [f"{response.status}"] | ||
for name, value in response.headers.items(): | ||
if name.lower() not in ["server", "date", "content-length"]: | ||
headers.append(f"{name}={value}") | ||
return "\n".join(headers) | ||
client.set_cookie( | ||
"login", "[email protected]|29Xwa32OsHUoHm4TRitwQMWpuynz3r1aw3BcB5pPGdY=" | ||
) | ||
web_selfie(client.get("/")).to_match_disk("3. log in works with cookies").facet( | ||
"md" | ||
).to_be("Welcome back [email protected]") | ||
|
||
client.set_cookie("login", "[email protected]|ABCDEF") | ||
web_selfie(client.get("/")).to_match_disk( | ||
"4. log in fails with fake cookies" | ||
).facet("status").to_be("401 UNAUTHORIZED") | ||
|
||
|
||
if __name__ == "__main__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
╔═ test_login_flow/1. not logged in ═╗ | ||
<html> | ||
<body> | ||
<h1> | ||
Please login | ||
</h1> | ||
<form action="/login" method="post"> | ||
<input name="email" placeholder="email" type="text"/> | ||
<input type="submit" value="login"/> | ||
</form> | ||
</body> | ||
</html> | ||
|
||
╔═ test_login_flow/1. not logged in[md] ═╗ | ||
Please login | ||
╔═ test_login_flow/1. not logged in[status] ═╗ | ||
200 OK | ||
╔═ test_login_flow/2. post login form ═╗ | ||
<html> | ||
<body> | ||
<h1> | ||
Email sent! | ||
</h1> | ||
<p> | ||
Check your email for your login link. | ||
</p> | ||
</body> | ||
</html> | ||
|
||
╔═ test_login_flow/2. post login form[md] ═╗ | ||
Email sent! | ||
|
||
Check your email for your login link. | ||
╔═ test_login_flow/2. post login form[status] ═╗ | ||
200 OK | ||
╔═ test_login_flow/3. log in works with cookies ═╗ | ||
<html> | ||
<body> | ||
<h1> | ||
Welcome back [email protected] | ||
</h1> | ||
</body> | ||
</html> | ||
|
||
╔═ test_login_flow/3. log in works with cookies[md] ═╗ | ||
Welcome back [email protected] | ||
╔═ test_login_flow/3. log in works with cookies[status] ═╗ | ||
200 OK | ||
╔═ test_login_flow/4. log in fails with fake cookies ═╗ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<title> | ||
401 Unauthorized | ||
</title> | ||
<h1> | ||
Unauthorized | ||
</h1> | ||
<p> | ||
The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required. | ||
</p> | ||
</html> | ||
|
||
╔═ test_login_flow/4. log in fails with fake cookies[md] ═╗ | ||
401 Unauthorized | ||
|
||
Unauthorized | ||
|
||
The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required. | ||
╔═ test_login_flow/4. log in fails with fake cookies[status] ═╗ | ||
401 UNAUTHORIZED | ||
╔═ [end of file] ═╗ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.