forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_viewhtmlmail.py
More file actions
executable file
·63 lines (42 loc) · 1.48 KB
/
test_viewhtmlmail.py
File metadata and controls
executable file
·63 lines (42 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
# Tests for viewhtmlmail.py
import unittest
import os
import shutil
import hashlib
import time
import viewhtmlmail
def md5sum(filename):
md5 = hashlib.md5()
with open(filename, "rb") as f:
while chunk := f.read(4096):
md5.update(chunk)
return md5.hexdigest()
class TestSampleMessage(unittest.TestCase):
# setUp() will be called for every test_*() function in the class.
def setUp(self):
pass
def tearDown(self):
pass
def test_sample_message(self):
"""Test a sample message to make sure that images, charsets etc.
come through correctly.
"""
tmpdir = os.path.abspath("test/files/tmp")
print("tmpdir is", tmpdir)
try:
os.mkdir(tmpdir)
except FileExistsError:
pass
viewhtmlmail.view_html_message("test/files/htmlmail.eml", tmpdir)
print("Check to make sure the message window looks right")
htmlfile = os.path.join(tmpdir, "viewhtml.html")
self.assertTrue(os.path.exists(htmlfile))
self.assertEqual(md5sum(htmlfile), "b15a4e42651073042ec01940a1eaed75")
imgfile = os.path.join(tmpdir, "tuxnetwork.jpg")
self.assertTrue(os.path.exists(imgfile))
self.assertEqual(md5sum(imgfile), "a69eb0be3c99646e3e0f410861a70a60")
# Remove the temp dir. But first, wait briefly for the
# mail window to pop up.
time.sleep(1)
shutil.rmtree(tmpdir)