MCPcopy
hub / github.com/scrapy/scrapy / test_send_attach_utf8

Method test_send_attach_utf8

tests/test_mail.py:120–154  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

118 assert msg.get("Content-Type") == 'text/plain; charset="utf-8"'
119
120 def test_send_attach_utf8(self):
121 subject = "sübjèçt"
122 body = "bödÿ-àéïöñß"
123 attach = BytesIO()
124 attach.write(body.encode("utf-8"))
125 attach.seek(0)
126 attachs = [("attachment", "text/plain", attach)]
127
128 mailsender = MailSender(debug=True)
129 mailsender.send(
130 to=["test@scrapy.org"],
131 subject=subject,
132 body=body,
133 attachs=attachs,
134 charset="utf-8",
135 _callback=self._catch_mail_sent,
136 )
137
138 assert self.catched_msg
139 assert self.catched_msg["subject"] == subject
140 assert self.catched_msg["body"] == body
141
142 msg = self.catched_msg["msg"]
143 assert msg["subject"] == subject
144 assert msg.get_charset() == Charset("utf-8")
145 assert msg.get("Content-Type") == 'multipart/mixed; charset="utf-8"'
146
147 payload = msg.get_payload()
148 assert isinstance(payload, list)
149 assert len(payload) == 2
150
151 text, attach = payload
152 assert text.get_payload(decode=True).decode("utf-8") == body
153 assert text.get_charset() == Charset("utf-8")
154 assert attach.get_payload(decode=True).decode("utf-8") == body
155
156 def test_create_sender_factory_with_host(self):
157 mailsender = MailSender(debug=False, smtphost="smtp.testhost.com")

Callers

nothing calls this directly

Calls 4

sendMethod · 0.95
MailSenderClass · 0.90
writeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected