/
test_eml.py
65 lines (45 loc) · 1.83 KB
/
test_eml.py
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
63
64
65
from typing import List
from app.factories.eml import EmlFactory
def test_sample(sample_eml):
eml = EmlFactory.from_bytes(sample_eml)
assert eml.header.message_id is None
assert eml.header.subject == "Winter promotions"
assert eml.header.to == ["foo.bar@example.com"]
assert eml.header.from_ == "no-reply@example.com"
assert len(eml.bodies) == 2
def test_cc(cc_eml):
eml = EmlFactory.from_bytes(cc_eml)
assert eml.header.message_id == "<ecc38b11-aa06-44c9-b8de-283b06a1d89e@example.com>"
assert eml.header.subject == "To and Cc headers"
assert eml.header.to == ["foo.bar@example.com", "info@example.com"]
assert eml.header.cc == ["foo@example.com", "bar@example.com"]
assert len(eml.bodies) == 1
assert eml.bodies[0].content == ""
assert eml.attachments == []
def test_multipart(multipart_eml):
eml = EmlFactory.from_bytes(multipart_eml)
assert eml.attachments is not None
assert len(eml.attachments) == 1
first = eml.attachments[0]
assert first.filename == "tired_boot.FJ010019.jpeg"
assert first.hash_.md5 == "f561388f7446cedd5b8b480311744b3c"
def test_encrypted_docx(encrypted_docx_eml):
eml = EmlFactory.from_bytes(encrypted_docx_eml)
assert eml.attachments is not None
assert len(eml.attachments) == 1
first = eml.attachments[0]
assert (
first.hash_.sha256
== "28df2d6dfa10dc85c8ebb5defffcb15c196dca7b26d4fd6859b9ec75ac60cf9e"
)
def test_emails(emails: List[bytes]):
for email in emails:
try:
eml = EmlFactory.from_bytes(email)
assert eml is not None
except Exception as e:
print(e)
print(email.decode())
def test_complete_msg(complete_msg):
eml = EmlFactory.from_bytes(complete_msg)
assert eml.header.subject == "Test Multiple attachments complete email!!"