Skip to content

Commit 2863817

Browse files
committed
add snapshot tests
1 parent 17fdc93 commit 2863817

File tree

4 files changed

+215
-2
lines changed

4 files changed

+215
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# serializer version: 1
2+
# name: test_preview_email_complex_html
3+
'''
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
<head>
7+
<meta charset="UTF-8">
8+
<title>Test Email</title>
9+
<style>
10+
body { font-family: Arial, sans-serif; }
11+
.header { background-color: #f0f0f0; padding: 20px; }
12+
.content { padding: 20px; }
13+
</style>
14+
</head>
15+
<body>
16+
<h2 style="padding-left:16px;">Subject: Complex Email Structure</h2>
17+
<div class="header">
18+
<h1>Welcome!</h1>
19+
</div>
20+
<div class="content">
21+
<p>This is a <strong>complex</strong> email with <em>formatting</em>.</p>
22+
<ul>
23+
<li>Item 1</li>
24+
<li>Item 2</li>
25+
<li>Item 3</li>
26+
</ul>
27+
<img src="data:image;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" alt="Test Image" />
28+
</div>
29+
</body>
30+
</html>
31+
'''
32+
# ---
33+
# name: test_preview_email_simple_html
34+
'''
35+
<html><body>
36+
<h2 style="padding-left:16px;">Subject: Simple Test Email</h2><p>Hello World!</p></body></html>
37+
'''
38+
# ---
39+
# name: test_preview_email_with_inline_attachments
40+
'''
41+
<html>
42+
<body>
43+
<h2 style="padding-left:16px;">Subject: Email with Inline Images</h2>
44+
<h1>Email with Images</h1>
45+
<img src="data:image;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" alt="Logo" />
46+
<p>Some text content</p>
47+
<img src="data:image;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAv/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAAAAX/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCwAAA=" alt="Banner" />
48+
</body>
49+
</html>
50+
'''
51+
# ---

emailer_lib/tests/test_structs.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,84 @@ def test_not_implemented_methods(method_name):
9595
method = getattr(email, method_name)
9696
with pytest.raises(NotImplementedError):
9797
method()
98+
99+
100+
def test_preview_email_simple_html(tmp_path, snapshot):
101+
html = "<html><body><p>Hello World!</p></body></html>"
102+
email = IntermediateEmail(
103+
html=html,
104+
subject="Simple Test Email",
105+
)
106+
107+
out_file = tmp_path / "preview.html"
108+
email.write_preview_email(str(out_file))
109+
content = out_file.read_text(encoding="utf-8")
110+
111+
assert content == snapshot
112+
113+
114+
def test_preview_email_with_inline_attachments(tmp_path, snapshot):
115+
html = """<html>
116+
<body>
117+
<h1>Email with Images</h1>
118+
<img src="cid:logo.png" alt="Logo" />
119+
<p>Some text content</p>
120+
<img src="cid:banner.jpg" alt="Banner" />
121+
</body>
122+
</html>"""
123+
email = IntermediateEmail(
124+
html=html,
125+
subject="Email with Inline Images",
126+
inline_attachments={
127+
"logo.png": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
128+
"banner.jpg": "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAv/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAAAAX/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCwAAA="
129+
},
130+
)
131+
132+
out_file = tmp_path / "preview.html"
133+
email.write_preview_email(str(out_file))
134+
content = out_file.read_text(encoding="utf-8")
135+
136+
assert content == snapshot
137+
138+
139+
def test_preview_email_complex_html(tmp_path, snapshot):
140+
html = """<!DOCTYPE html>
141+
<html lang="en">
142+
<head>
143+
<meta charset="UTF-8">
144+
<title>Test Email</title>
145+
<style>
146+
body { font-family: Arial, sans-serif; }
147+
.header { background-color: #f0f0f0; padding: 20px; }
148+
.content { padding: 20px; }
149+
</style>
150+
</head>
151+
<body>
152+
<div class="header">
153+
<h1>Welcome!</h1>
154+
</div>
155+
<div class="content">
156+
<p>This is a <strong>complex</strong> email with <em>formatting</em>.</p>
157+
<ul>
158+
<li>Item 1</li>
159+
<li>Item 2</li>
160+
<li>Item 3</li>
161+
</ul>
162+
<img src="cid:test.png" alt="Test Image" />
163+
</div>
164+
</body>
165+
</html>"""
166+
email = IntermediateEmail(
167+
html=html,
168+
subject="Complex Email Structure",
169+
inline_attachments={
170+
"test.png": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
171+
},
172+
)
173+
174+
out_file = tmp_path / "preview.html"
175+
email.write_preview_email(str(out_file))
176+
content = out_file.read_text(encoding="utf-8")
177+
178+
assert content == snapshot

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dev = [
3030
"quartodoc",
3131
"pytest-cov",
3232
"griffe",
33+
"syrupy",
3334
]
3435

3536
mailgun = [

uv.lock

Lines changed: 82 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)