Skip to content

Commit 0383de2

Browse files
committed
Pretty-print the example.
1 parent 26d99d4 commit 0383de2

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

python/example-pytest-selfie/tests/app_account_test.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from selfie_lib import expect_selfie
33

44
from app import app, wait_for_incoming_email
5-
from tests.selfie_settings import web_selfie
5+
6+
from .selfie_settings import web_selfie
67

78

89
@pytest.fixture
@@ -13,14 +14,18 @@ def client():
1314

1415

1516
def test_homepage(client):
16-
web_selfie(client.get("/")).to_be("""
17-
<html><body>
18-
<h1>Please login</h1>
17+
web_selfie(client.get("/")).to_be("""<html>
18+
<body>
19+
<h1>
20+
Please login
21+
</h1>
1922
<form action="/login" method="post">
20-
<input type="text" name="email" placeholder="email">
21-
<input type="submit" value="login">
23+
<input name="email" placeholder="email" type="text"/>
24+
<input type="submit" value="login"/>
2225
</form>
23-
</body></html>
26+
</body>
27+
</html>
28+
2429
╔═ [status] ═╗
2530
200 OK""")
2631

python/example-pytest-selfie/tests/selfie_settings.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from bs4 import BeautifulSoup
12
from selfie_lib import Camera, Snapshot, StringSelfie, expect_selfie
23
from werkzeug.test import TestResponse
34

@@ -20,8 +21,21 @@ def _web_camera(response: TestResponse) -> Snapshot:
2021
return Snapshot.of(response.data.decode()).plus_facet("status", response.status)
2122

2223

23-
WEB_CAMERA = Camera.of(_web_camera)
24+
def _pretty_print_html(html: str) -> str:
25+
return BeautifulSoup(html, "html.parser").prettify()
26+
27+
28+
def _pretty_print_lens(snapshot: Snapshot) -> Snapshot:
29+
if "<html" in snapshot.subject.value_string():
30+
return snapshot.plus_or_replace(
31+
"", _pretty_print_html(snapshot.subject.value_string())
32+
)
33+
else:
34+
return snapshot
35+
36+
37+
WEB_CAMERA = Camera.of(_web_camera).with_lens(_pretty_print_lens)
2438

2539

2640
def web_selfie(response: TestResponse) -> StringSelfie:
27-
return expect_selfie(response, _web_camera)
41+
return expect_selfie(response, WEB_CAMERA)

0 commit comments

Comments
 (0)