source: mailjam/postman/tests/mta.py@ 2:108a82defd3e

Last change on this file since 2:108a82defd3e was 2:108a82defd3e, checked in by Francisco de Borja Lopez Rio <borja@…>, 12 years ago

Fixed some bugs in the models and mta modules

Added tests for the mta module, including a dummy email that is used for
those tests.

Added an initial version of the Postman class (inside the daemon module). This
class will handle the main execution of the postman daemon, the manager
that will take care of mailing lists management.

Added the structure of folders needed to store json files associated with a given
postman instance.

File size: 1.9 KB
Line 
1# -*- coding: utf-8 -*-
2
3import os, sys
4from unittest import TestCase
5
6from postman.models import Member, MailingList
7from postman.mta import Sendmail
8
9
10class 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
Note: See TracBrowser for help on using the repository browser.