source: mailjam/postman/tests/mta.py@ 14:0a6affee82cd

Last change on this file since 14:0a6affee82cd was 10:d5329a2a05b7, checked in by Borja Lopez <borja@…>, 13 years ago

Fully added support for the configuration file. Now all the code uses
postman.conf to read the configuration parameters from it

Added a tests/postman.conf configuration file with specific configurtion
to use while testing (mostly tmp paths)

Updated the run_tests script to delete the temporary directory where
data is saved while running tests

Updated the tests modules/files so they use the tests config file

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