Changeset 10:d5329a2a05b7 in mailjam
- Timestamp:
- May 20, 2012, 9:39:51 AM (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
bin/run_tests
r1 r10 3 3 # Run the tests for the postman package 4 4 5 import os, s ys, unittest5 import os, shutil, sys, unittest 6 6 7 7 try: … … 13 13 except ImportError: 14 14 raise SystemExit('Could not find postman on your filesystem') 15 16 unittest.main() 15 16 try: 17 unittest.main() 18 finally: 19 # FIXME: hardcoded path to the tmp directory, we should read this path 20 # from postman/tests/postman.conf 21 shutil.rmtree('/tmp/postman-tests') -
postman/daemon.py
r9 r10 91 91 'address' not in info.keys() or \ 92 92 'members' not in info.keys() or \ 93 'config ' not in info.keys():93 'configfile' not in info.keys(): 94 94 raise ValueError(info, ' does not seem to be a valid configuration') 95 95 … … 99 99 100 100 mailing = MailingList(info['name'], info['address'], 101 info['members'], info['config '])101 info['members'], info['configfile']) 102 102 self.mailings[mailing.address] = mailing 103 103 self.mailings_addresses.append(mailing.address) -
postman/models.py
r5 r10 33 33 """ 34 34 35 def __init__(self, name, address, members={}, config={}): 35 def __init__(self, name, address, members={}, configfile=None): 36 self.configfile = configfile 37 self.storage_config = config.get_config_parameters('storage', 38 configfile) 39 self.archive_config = config.get_config_parameters('archive', 40 configfile) 41 self.mailing_config = config.get_config_parameters('mailing_lists', 42 configfile) 36 43 self.name = name 37 44 self.address = address 38 45 self.members = members 39 self.config = config40 self._validate_config() # validate the config parameters41 46 42 47 def __repr__(self): … … 45 50 def __str__(self): 46 51 return self.address 47 48 def _validate_config(self):49 if not 'storage' in self.config.keys():50 self.config['storage'] = os.path.join(config.storage_path,51 'mailings/')52 if not 'archive' in self.config.keys():53 self.config['archive'] = config.archive_path54 if not 'private' in self.config.keys():55 self.config['private'] = config.private_mailing56 52 57 53 def _validate_member_object(self, member=None): … … 71 67 @property 72 68 def storage(self): 73 return Storage(os.path.join(self. config['storage'], self.address))69 return Storage(os.path.join(self.storage_config['path'], self.address)) 74 70 75 71 @property 76 72 def archive(self): 77 return Storage(os.path.join(self. config['archive'], self.address))73 return Storage(os.path.join(self.archive_config['path'], self.address)) 78 74 79 75 def members_addresses(self): … … 109 105 # automagically generates the dict from the instance attributes 110 106 return {'name': self.name, 'address': self.address, 111 'members': self.members, 'config ': self.config}107 'members': self.members, 'configfile': self.configfile} 112 108 113 109 def load(self): -
postman/mta.py
r2 r10 8 8 class Sendmail(): 9 9 10 def __init__(self, mailing_list=None ):10 def __init__(self, mailing_list=None, configfile=None): 11 11 if not isinstance(mailing_list, MailingList): 12 12 raise ValueError(mailing_list, ' is not a valid mailing list') … … 16 16 self.raw_email = None 17 17 self.queue = [] 18 self.archive = self.mailing_list.config.get('archive',19 config.archive_path)18 self.archive_config = config.get_config_parameters('archive', 19 configfile) 20 20 21 21 def get_raw_email(self): … … 31 31 # check, would be nice here 32 32 self.get_raw_email 33 filename = os.path.join(self.archive ,33 filename = os.path.join(self.archive_config['path'], 34 34 datetime.today().strftime('%Y%d%m%H%M%S%f')) 35 35 tmpfile = file(filename, 'w') -
postman/tests/daemon.py
r9 r10 1 1 # -*- coding: utf-8 -*- 2 2 3 import os, multiprocessing, xmlrpclib 3 import os, multiprocessing, xmlrpclib, time 4 4 from SimpleXMLRPCServer import SimpleXMLRPCServer 5 5 from unittest import TestCase … … 18 18 """ 19 19 def setUp(self): 20 config = {'private': False, 'archive': '/tmp/postman-tests/archive', 21 'storage': '/tmp/postman-tests/storage'} 20 self.configfile = os.path.join(os.path.dirname(__file__), 'postman.conf') 22 21 self.mailing_list = MailingList('test_list', 'test_list@example.com', 23 members={}, config =config)22 members={}, configfile=self.configfile) 24 23 self.member = Member('test@example.com') 25 24 26 25 def test___init__(self): 27 postman = Postman( )26 postman = Postman(configfile=self.configfile) 28 27 self.assertIsInstance(postman, Postman) 29 28 self.assertEqual(postman.mailings, {}) … … 36 35 37 36 def test_save(self): 38 postman = Postman( )37 postman = Postman(configfile=self.configfile) 39 38 self.assertFalse(postman.save()) 40 39 postman.add_mailing_list(self.mailing_list.info()) … … 47 46 48 47 def test_load(self): 49 postman = Postman( )48 postman = Postman(configfile=self.configfile) 50 49 self.assertFalse(postman.mailings) 51 50 self.assertFalse(postman.mailings_addresses) … … 55 54 56 55 # Check that another postman instance is able to load the saved data 57 postman_load = Postman( )56 postman_load = Postman(configfile=self.configfile) 58 57 self.assertFalse(postman_load.mailings) 59 58 self.assertFalse(postman_load.mailings_addresses) … … 68 67 69 68 def test_clear(self): 70 postman = Postman( )69 postman = Postman(configfile=self.configfile) 71 70 self.assertFalse(postman.clear()) 72 71 postman.add_mailing_list(self.mailing_list.info()) … … 74 73 75 74 def test_add_mailing_list(self): 76 postman = Postman( )75 postman = Postman(configfile=self.configfile) 77 76 with self.assertRaises(TypeError): 78 77 # test improper info values … … 100 99 101 100 def test_add_mailing_member(self): 102 postman = Postman( )101 postman = Postman(configfile=self.configfile) 103 102 postman.add_mailing_list(self.mailing_list.info()) 104 103 with self.assertRaises(ValueError): … … 133 132 """ 134 133 def setUp(self): 135 config = {'private': False, 'archive': '/tmp/postman-tests/archive', 136 'storage': '/tmp/postman-tests/storage'} 137 self.mailing_list = MailingList('test_xmlrpc', 'test_xmlrpc@example.com', 138 members={}, config=config) 134 self.configfile = os.path.join(os.path.dirname(__file__), 135 'postman.conf') 136 self.mailing_list = MailingList('test_xmlrpc', 137 'test_xmlrpc@example.com', members={}, 138 configfile=self.configfile) 139 139 self.member = Member('test@example.com') 140 140 141 141 def test___init__(self): 142 daemon = PostmanDaemon( )142 daemon = PostmanDaemon(self.configfile) 143 143 self.assertIsInstance(daemon, PostmanDaemon) 144 144 self.assertFalse(daemon.ready_to_serve) … … 147 147 148 148 def test_create_server(self): 149 daemon = PostmanDaemon( )149 daemon = PostmanDaemon(self.configfile) 150 150 daemon.port = 9001 151 151 self.assertTrue(daemon.create_server()) … … 154 154 155 155 def test_add_methods(self): 156 daemon = PostmanDaemon( )156 daemon = PostmanDaemon(self.configfile) 157 157 daemon.port = 9002 158 158 self.assertTrue(daemon.add_methods()) 159 159 self.assertTrue(daemon.ready_to_serve) 160 160 161 daemon = PostmanDaemon( )161 daemon = PostmanDaemon(self.configfile) 162 162 daemon.port = 9003 163 163 daemon.create_server() … … 166 166 167 167 def test_run(self): 168 daemon = PostmanDaemon( )168 daemon = PostmanDaemon(self.configfile) 169 169 daemon.port = 9004 170 170 # start the daemon in another process, so we can start communicating … … 172 172 p = multiprocessing.Process(target=daemon.run) 173 173 p.start() 174 175 # Add a delay here to allow the server to be fully started before 176 # starting to send requests from the client 177 time.sleep(2) 174 178 175 179 # FIXME: Hardcoded url here, should be picked from a config file -
postman/tests/models.py
r1 r10 1 1 # -*- coding: utf-8 -*- 2 2 3 import os 3 4 from unittest import TestCase 4 5 from postman.models import Member, MailingList … … 18 19 class TestMailingList(TestCase): 19 20 def setUp(self): 20 config = {'private': False, 'archive': '/tmp/postman-tests/archive', 21 'storage': '/tmp/postman-tests/storage'} 21 configfile = os.path.join(os.path.dirname(__file__), 'postman.conf') 22 22 self.mailing_list = MailingList('test_list', 'test_list@example.com', 23 members={}, config =config)23 members={}, configfile=configfile) 24 24 self.member = Member('test@example.com') 25 25 -
postman/tests/mta.py
r5 r10 6 6 from postman.models import Member, MailingList 7 7 8 9 8 class TestSendmail(TestCase): 10 9 def setUp(self): 11 config = {'private': False, 'archive': '/tmp/postman-tests/archive',12 'storage': '/tmp/postman-tests/storage'}10 self.configfile = os.path.join(os.path.dirname(__file__), 11 'postman.conf') 13 12 self.mailing_list = MailingList('test_list', 'test_list@example.com', 14 members={}, config =config)13 members={}, configfile=self.configfile) 15 14 self.member = Member('test@example.com') 16 15 self.mta = Sendmail(self.mailing_list)
Note:
See TracChangeset
for help on using the changeset viewer.