source: mailjam/postman/tests/mta.py@ 5:573fdae8b1f6

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

Added tests for postman.daemon.Postman

Added a method to postman.daemon.Postman to "clear" all the storage associated
to a given postman instance (removing all the files from disk)

Fixed some bugs, mostly caused by typos through the sources, detected while
writing more tests

Removed the storage and archive attributes from postman.models.MailingList,
now they are methods "marked" as properties using the @property decorator.
This keeps the storage objects from being serialized into json objects by
the storage backend (de-serializing them caused some trouble and it is not
necessary at all)

Added create() and delete() methods to postman.storage.JsonStorage. the first
one ensures the path to the storage file exists (creating all subdirs if
necessary) and the second one deletes the storage file from disk

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
8
9class 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
Note: See TracBrowser for help on using the repository browser.