Changeset 15:8ae771653ffe in mailjam for postman/tests
- Timestamp:
- May 21, 2012, 7:22:27 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- postman/tests
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
postman/tests/__init__.py
r11 r15 12 12 13 13 from models import * 14 from mta import *14 # from mta import * 15 15 from daemon import * -
postman/tests/mta.py
r10 r15 1 1 # -*- coding: utf-8 -*- 2 2 3 import os, sys 3 import os, sys, multiprocessing, time 4 4 from unittest import TestCase 5 from postman.mta import Sendmail 5 from postman.mta import MTAClient 6 from postman.daemon import PostmanDaemon 6 7 from postman.models import Member, MailingList 7 8 8 class TestSendmail(TestCase): 9 10 class TestMTAClient(TestCase): 11 """ 12 FIXME: These are dummy tests, they cover almost nothing from the 13 real postman mta client (yet) 14 """ 9 15 def setUp(self): 16 self.mta_configfile = os.path.join(os.path.dirname(__file__), 17 'postman-mta.conf') 10 18 self.configfile = os.path.join(os.path.dirname(__file__), 11 19 'postman.conf') … … 13 21 members={}, configfile=self.configfile) 14 22 self.member = Member('test@example.com') 15 self.mta = Sendmail(self.mailing_list)16 23 self.raw_email_file = os.path.join(os.path.dirname(__file__), 17 24 'sample_raw_email.txt') … … 19 26 self.raw_email = tmp_to_read.read() 20 27 tmp_to_read.close() 21 28 22 29 def test___init__(self): 30 # in order to start mta client instances, we need to have a postman 31 # daemon running on the background 32 # This should be added to the setUp() method, but then it would be 33 # more difficult to terminate the process after all the methods 34 # were called 35 daemon = PostmanDaemon(self.configfile) 36 daemon.port = 9100 37 p = multiprocessing.Process(target=daemon.run) 38 p.start() 39 # Add a delay here to allow the server to be fully started before 40 # starting to send requests from the client 41 time.sleep(1) 42 23 43 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)44 mta = MTAClient(self.mailing_list, self.mta_configfile) 45 mta = MTAClient(self.member, self.mta_configfile) 46 mta = MTAClient(None, self.mta_configfile) 47 mta = MTAClient(self.mailing_list.address, self.mta_configfile) 48 self.assertTrue(isinstance(mta, MTAClient)) 49 self.assertEqual(mta.address, self.mailing_list.address) 30 50 self.assertEqual(mta.suscriptors, self.mailing_list.members_addresses) 31 51 self.assertEqual(mta.reply_to, self.mailing_list.address) 32 52 53 p.terminate() 54 33 55 def test_get_raw_email(self): 56 # in order to start mta client instances, we need to have a postman 57 # daemon running on the background 58 # This should be added to the setUp() method, but then it would be 59 # more difficult to terminate the process after all the methods 60 # were called 61 daemon = PostmanDaemon(self.configfile) 62 daemon.port = 9100 63 p = multiprocessing.Process(target=daemon.run) 64 p.start() 65 # Add a delay here to allow the server to be fully started before 66 # starting to send requests from the client 67 time.sleep(1) 68 69 mta = MTAClient(self.mailing_list.address, self.mta_configfile) 70 34 71 sys_stdin = sys.stdin 35 72 sys.stdin = open(self.raw_email_file, 'r') 36 self.assertEqual( self.mta.get_raw_email(),73 self.assertEqual(mta.get_raw_email(), 37 74 self.raw_email) 38 75 sys.stdin.close() 39 76 with self.assertRaises(IOError): 40 self.mta.get_raw_email() 77 mta.get_raw_email() 78 79 tmp_file= open(self.raw_email_file('r')) 80 raw_data = tmp_file.read() 81 tmp_file.close() 82 self.assertEqual(mta.get_raw_email(raw_data), 83 self.raw_email) 84 85 p.terminate() 41 86 42 87 #def save_raw_email(self):
Note:
See TracChangeset
for help on using the changeset viewer.