示例#1
0
 def test_subject(self):
     msg = Message(self.fromaddr, self.toaddr, self.subject,
                   self.bodyplain)
     txt = msg.as_string()
     result = re.search("^Subject: (.*)$".format(self.subject), txt, re.M)
     self.assertTrue(result)
     self.assertEqual(result.group(1), self.subject)
示例#2
0
 def test_attach_image(self):
     msg = Message(self.fromaddr, self.toaddr, self.subject,
                   self.bodyplain, self.bodyhtml, ['logo.jpg'])
     txt = msg.as_string()
     result = re.search("^Content-Type: image/jpeg", txt, re.M)
     self.assertTrue(result)
     result = re.search("^Content-ID: <image\d+>", txt, re.M)
     self.assertTrue(result)
示例#3
0
 def test_multiple_to(self):
     to = ['*****@*****.**', '*****@*****.**', '*****@*****.**']
     msg = Message(self.fromaddr, to, self.subject,
                   self.bodyplain)
     txt = msg.as_string()
     result = re.search("^To: (.*)$", txt, re.M)
     self.assertTrue(result)
     self.assertEqual(result.group(1), ", ".join(to))
示例#4
0
 def test_two_attachments(self):
     msg = Message(self.fromaddr, self.toaddr, self.subject,
                   self.bodyplain, self.bodyhtml, ['logo.jpg', argv[0]])
     txt = msg.as_string()
     print(txt)
     pattern = re.compile("^Content-Disposition: attachment;")
     count = 0
     for match in pattern.finditer(txt, re.M):
         count += 1
     self.assertEqual(count, 2)
示例#5
0
 def test_attach_script(self):
     msg = Message(self.fromaddr, self.toaddr, self.subject,
                   self.bodyplain, self.bodyhtml, [argv[0]])
     txt = msg.as_string()
     result = re.search("^Content-Type: text/x-python", txt, re.M)
     self.assertTrue(result)
示例#6
0
 def test_plain_and_html(self):
     msg = Message(self.fromaddr, self.toaddr, self.subject,
                   self.bodyplain, self.bodyhtml)
     txt = msg.as_string()
     result = re.search("^Content-Type: multipart/alternative;", txt, re.M)
     self.assertTrue(result)
示例#7
0
 def test_html(self):
     msg = Message(self.fromaddr, self.toaddr, self.subject,
                   bodyhtml=self.bodyhtml)
     txt = msg.as_string()
     result = re.search("^Content-Type: text/html;", txt, re.M)
     self.assertTrue(result)
示例#8
0
 def test_plain(self):
     msg = Message(self.fromaddr, self.toaddr, self.subject,
                   self.bodyplain)
     txt = msg.as_string()
     result = re.search("^Content-Type: text/plain;", txt, re.M)
     self.assertTrue(result)
示例#9
0
 def test_no_body(self):
     with self.assertRaises(RuntimeError):
         Message(self.fromaddr, self.toaddr, self.subject)