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