1 | # -*- coding: utf-8 -*-
|
---|
2 |
|
---|
3 | import os, sys
|
---|
4 | from unittest import TestCase
|
---|
5 | from postman.mta import Sendmail
|
---|
6 | from postman.models import Member, MailingList
|
---|
7 |
|
---|
8 | class TestSendmail(TestCase):
|
---|
9 | def setUp(self):
|
---|
10 | self.configfile = os.path.join(os.path.dirname(__file__),
|
---|
11 | 'postman.conf')
|
---|
12 | self.mailing_list = MailingList('test_list', 'test_list@example.com',
|
---|
13 | members={}, configfile=self.configfile)
|
---|
14 | self.member = Member('test@example.com')
|
---|
15 | self.mta = Sendmail(self.mailing_list)
|
---|
16 | self.raw_email_file = os.path.join(os.path.dirname(__file__),
|
---|
17 | 'sample_raw_email.txt')
|
---|
18 | tmp_to_read = open(self.raw_email_file, 'r')
|
---|
19 | self.raw_email = tmp_to_read.read()
|
---|
20 | tmp_to_read.close()
|
---|
21 |
|
---|
22 | def test___init__(self):
|
---|
23 | with self.assertRaises(ValueError):
|
---|
24 | mta = Sendmail('test_list@example.com')
|
---|
25 | mta = Sendmail(self.member)
|
---|
26 | mta = Sendmail(None)
|
---|
27 | mta = Sendmail(self.mailing_list)
|
---|
28 | self.assertTrue(isinstance(mta, Sendmail))
|
---|
29 | self.assertEqual(mta.mailing_list, self.mailing_list)
|
---|
30 | self.assertEqual(mta.suscriptors, self.mailing_list.members_addresses)
|
---|
31 | self.assertEqual(mta.reply_to, self.mailing_list.address)
|
---|
32 |
|
---|
33 | def test_get_raw_email(self):
|
---|
34 | sys_stdin = sys.stdin
|
---|
35 | sys.stdin = open(self.raw_email_file, 'r')
|
---|
36 | self.assertEqual(self.mta.get_raw_email(),
|
---|
37 | self.raw_email)
|
---|
38 | sys.stdin.close()
|
---|
39 | with self.assertRaises(IOError):
|
---|
40 | self.mta.get_raw_email()
|
---|
41 |
|
---|
42 | #def save_raw_email(self):
|
---|
43 | # sys_stdin = sys.stdin
|
---|
44 | # sys.stdin = open(self.raw_email_file, 'r')
|
---|
45 | # self.mta.save_raw_email.filename = '/tmp/postman-test-mta-save-raw-email'
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|