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