Changeset 16:cd4170142d87 in mailjam for mailjam/tests
- Timestamp:
- May 22, 2012, 9:31:15 AM (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- mailjam/tests
- Files:
-
- 7 moved
Legend:
- Unmodified
- Added
- Removed
-
mailjam/tests/__init__.py
r15 r16 2 2 3 3 """ 4 The postmanproject - tests module4 The mailjam project - tests module 5 5 6 6 This file is released under the BSD license, see LICENSE for -
mailjam/tests/daemon.py
r11 r16 2 2 3 3 """ 4 The postmanproject - daemon.py4 The mailjam project - daemon.py 5 5 6 6 This file is released under the BSD license, see LICENSE for … … 15 15 from unittest import TestCase 16 16 17 from postman.daemon import Postman, PostmanXMLRPC, PostmanDaemon18 from postman.models import Member, MailingList19 from postman.storage import JsonStorage as Storage20 21 22 class Test Postman(TestCase):23 """ 24 postman.daemon.Postmantests.25 26 Remember to call the .clear() method of postmanafter each test, so17 from mailjam.daemon import Mailjam, MailjamXMLRPC, MailjamDaemon 18 from mailjam.models import Member, MailingList 19 from mailjam.storage import JsonStorage as Storage 20 21 22 class TestMailjam(TestCase): 23 """ 24 mailjam.daemon.Mailjam tests. 25 26 Remember to call the .clear() method of mailjam after each test, so 27 27 the temp storage files are deleted 28 28 """ 29 29 def setUp(self): 30 self.configfile = os.path.join(os.path.dirname(__file__), ' postman.conf')30 self.configfile = os.path.join(os.path.dirname(__file__), 'mailjam.conf') 31 31 self.mailing_list = MailingList('test_list', 'test_list@example.com', 32 32 members={}, configfile=self.configfile) … … 34 34 35 35 def test___init__(self): 36 postman = Postman(configfile=self.configfile)37 self.assertIsInstance( postman, Postman)38 self.assertEqual( postman.mailings, {})39 self.assertEqual( postman.mailings_addresses, [])40 self.assertIsInstance( postman.dbs, dict)41 self.assertTrue('mailings' in postman.dbs.keys())42 self.assertTrue('members' in postman.dbs.keys())43 self.assertIsInstance( postman.dbs['mailings'], Storage)44 self.assertIsInstance( postman.dbs['members'], Storage)36 mailjam = Mailjam(configfile=self.configfile) 37 self.assertIsInstance(mailjam, Mailjam) 38 self.assertEqual(mailjam.mailings, {}) 39 self.assertEqual(mailjam.mailings_addresses, []) 40 self.assertIsInstance(mailjam.dbs, dict) 41 self.assertTrue('mailings' in mailjam.dbs.keys()) 42 self.assertTrue('members' in mailjam.dbs.keys()) 43 self.assertIsInstance(mailjam.dbs['mailings'], Storage) 44 self.assertIsInstance(mailjam.dbs['members'], Storage) 45 45 46 46 def test_save(self): 47 postman = Postman(configfile=self.configfile)48 self.assertFalse( postman.save())49 postman.add_mailing_list(self.mailing_list.info())50 self.assertTrue( postman.save())47 mailjam = Mailjam(configfile=self.configfile) 48 self.assertFalse(mailjam.save()) 49 mailjam.add_mailing_list(self.mailing_list.info()) 50 self.assertTrue(mailjam.save()) 51 51 # FIXME: We have to test here that the generated json file 52 52 # contains the data it should contain 53 53 54 54 # Clear the files created by the tests 55 postman.clear()55 mailjam.clear() 56 56 57 57 def test_load(self): 58 postman = Postman(configfile=self.configfile)59 self.assertFalse( postman.mailings)60 self.assertFalse( postman.mailings_addresses)61 self.assertFalse( postman.load())62 postman.add_mailing_list(self.mailing_list.info())63 self.assertTrue( postman.load())64 65 # Check that another postmaninstance is able to load the saved data66 postman_load = Postman(configfile=self.configfile)67 self.assertFalse( postman_load.mailings)68 self.assertFalse( postman_load.mailings_addresses)69 postman_load.load()70 self.assertTrue( postman_load.mailings)71 self.assertIsInstance( postman_load.mailings, dict)72 self.assertTrue( postman_load.mailings_addresses)73 self.assertIsInstance( postman_load.mailings_addresses, list)74 75 # Clear the files created by the tests 76 postman.clear()58 mailjam = Mailjam(configfile=self.configfile) 59 self.assertFalse(mailjam.mailings) 60 self.assertFalse(mailjam.mailings_addresses) 61 self.assertFalse(mailjam.load()) 62 mailjam.add_mailing_list(self.mailing_list.info()) 63 self.assertTrue(mailjam.load()) 64 65 # Check that another mailjam instance is able to load the saved data 66 mailjam_load = Mailjam(configfile=self.configfile) 67 self.assertFalse(mailjam_load.mailings) 68 self.assertFalse(mailjam_load.mailings_addresses) 69 mailjam_load.load() 70 self.assertTrue(mailjam_load.mailings) 71 self.assertIsInstance(mailjam_load.mailings, dict) 72 self.assertTrue(mailjam_load.mailings_addresses) 73 self.assertIsInstance(mailjam_load.mailings_addresses, list) 74 75 # Clear the files created by the tests 76 mailjam.clear() 77 77 78 78 def test_clear(self): 79 postman = Postman(configfile=self.configfile)80 self.assertFalse( postman.clear())81 postman.add_mailing_list(self.mailing_list.info())82 self.assertTrue( postman.clear())79 mailjam = Mailjam(configfile=self.configfile) 80 self.assertFalse(mailjam.clear()) 81 mailjam.add_mailing_list(self.mailing_list.info()) 82 self.assertTrue(mailjam.clear()) 83 83 84 84 def test_add_mailing_list(self): 85 postman = Postman(configfile=self.configfile)85 mailjam = Mailjam(configfile=self.configfile) 86 86 with self.assertRaises(TypeError): 87 87 # test improper info values 88 postman.add_mailing_list(['a list', 'is an', 'invalid parameter'])89 postman.add_mailing_list(self.mailing_list)88 mailjam.add_mailing_list(['a list', 'is an', 'invalid parameter']) 89 mailjam.add_mailing_list(self.mailing_list) 90 90 with self.assertRaises(ValueError): 91 91 #test incomplete/missing info values 92 postman.add_mailing_list()93 postman.add_mailing_list({'name': 'missing info'})94 postman.add_mailing_list({'address': 'missing info'})95 postman.add_mailing_list({'name': 'missing info',92 mailjam.add_mailing_list() 93 mailjam.add_mailing_list({'name': 'missing info'}) 94 mailjam.add_mailing_list({'address': 'missing info'}) 95 mailjam.add_mailing_list({'name': 'missing info', 96 96 'address': 'missing info'}) 97 97 # test mailing lists can be added 98 self.assertTrue( postman.add_mailing_list(self.mailing_list.info()))99 self.assertTrue( postman.mailings)100 self.assertIsInstance( postman.mailings, dict)101 self.assertTrue( postman.mailings_addresses)102 self.assertIsInstance( postman.mailings_addresses, list)98 self.assertTrue(mailjam.add_mailing_list(self.mailing_list.info())) 99 self.assertTrue(mailjam.mailings) 100 self.assertIsInstance(mailjam.mailings, dict) 101 self.assertTrue(mailjam.mailings_addresses) 102 self.assertIsInstance(mailjam.mailings_addresses, list) 103 103 with self.assertRaises(IndexError): 104 104 # test what happens when the mailing has been already added 105 postman.add_mailing_list(self.mailing_list.info())106 107 # Clear the files created by the tests 108 postman.clear()105 mailjam.add_mailing_list(self.mailing_list.info()) 106 107 # Clear the files created by the tests 108 mailjam.clear() 109 109 110 110 def test_add_mailing_member(self): 111 postman = Postman(configfile=self.configfile)112 postman.add_mailing_list(self.mailing_list.info())111 mailjam = Mailjam(configfile=self.configfile) 112 mailjam.add_mailing_list(self.mailing_list.info()) 113 113 with self.assertRaises(ValueError): 114 114 # test what happens if we call the method without proper 115 115 # parameters 116 postman.add_mailing_member()117 postman.add_mailing_member(None, None)118 postman.add_mailing_member(None, 'test_list@example.net')119 postman.add_mailing_member('test@example.net', None)120 postman.add_mailing_member('test@example', 'test_list@example.net')116 mailjam.add_mailing_member() 117 mailjam.add_mailing_member(None, None) 118 mailjam.add_mailing_member(None, 'test_list@example.net') 119 mailjam.add_mailing_member('test@example.net', None) 120 mailjam.add_mailing_member('test@example', 'test_list@example.net') 121 121 with self.assertRaises(IndexError): 122 122 # test if we try to add a member to a non-existing mailing list 123 postman.add_mailing_member('test@example.net',123 mailjam.add_mailing_member('test@example.net', 124 124 'test_list_b@example.net') 125 125 # Test adding a member 126 self.assertTrue( postman.add_mailing_member('test@example.net',126 self.assertTrue(mailjam.add_mailing_member('test@example.net', 127 127 self.mailing_list.address)) 128 128 # Test trying to re-add that user 129 self.assertFalse( postman.add_mailing_member('test@example.net',129 self.assertFalse(mailjam.add_mailing_member('test@example.net', 130 130 self.mailing_list.address)) 131 131 132 132 # Clear the files created by the tests 133 postman.clear()134 135 136 class Test PostmanDaemon(TestCase):137 """ 138 postman.daemon.PostmanDaemon tests.139 140 Remember to call the .clear() method of postmanafter each test, so133 mailjam.clear() 134 135 136 class TestMailjamDaemon(TestCase): 137 """ 138 mailjam.daemon.MailjamDaemon tests. 139 140 Remember to call the .clear() method of mailjam after each test, so 141 141 the temp storage files are deleted 142 142 """ 143 143 def setUp(self): 144 144 self.configfile = os.path.join(os.path.dirname(__file__), 145 ' postman.conf')145 'mailjam.conf') 146 146 self.mailing_list = MailingList('test_xmlrpc', 147 147 'test_xmlrpc@example.com', members={}, … … 150 150 151 151 def test___init__(self): 152 daemon = PostmanDaemon(self.configfile)153 self.assertIsInstance(daemon, PostmanDaemon)152 daemon = MailjamDaemon(self.configfile) 153 self.assertIsInstance(daemon, MailjamDaemon) 154 154 self.assertFalse(daemon.ready_to_serve) 155 155 # FIXME: More tests should be added here once the configuration … … 157 157 158 158 def test_create_server(self): 159 daemon = PostmanDaemon(self.configfile)159 daemon = MailjamDaemon(self.configfile) 160 160 daemon.port = 9001 161 161 self.assertTrue(daemon.create_server()) … … 164 164 165 165 def test_add_methods(self): 166 daemon = PostmanDaemon(self.configfile)166 daemon = MailjamDaemon(self.configfile) 167 167 daemon.port = 9002 168 168 self.assertTrue(daemon.add_methods()) 169 169 self.assertTrue(daemon.ready_to_serve) 170 170 171 daemon = PostmanDaemon(self.configfile)171 daemon = MailjamDaemon(self.configfile) 172 172 daemon.port = 9003 173 173 daemon.create_server() … … 176 176 177 177 def test_run(self): 178 daemon = PostmanDaemon(self.configfile)178 daemon = MailjamDaemon(self.configfile) 179 179 daemon.port = 9004 180 180 # start the daemon in another process, so we can start communicating … … 193 193 # available public methods contains the list of methods we have 194 194 # defined in our base XMLRPC class 195 set_class_methods = set( PostmanXMLRPC()._listMethods())195 set_class_methods = set(MailjamXMLRPC()._listMethods()) 196 196 set_xmlrpc_methods = set(client.system.listMethods()) 197 197 self.assertTrue(set_class_methods.issubset(set_xmlrpc_methods)) -
mailjam/tests/mailjam-mta.conf
r15 r16 1 1 # 2 # postman-mta.conf - PostmanMTA client configuration file2 # mailjam-mta.conf - Mailjam MTA client configuration file 3 3 # 4 4 … … 11 11 [archive] 12 12 persistent = true 13 path = /tmp/ postman-tests/mta/archive13 path = /tmp/mailjam-tests/mta/archive -
mailjam/tests/mailjam.conf
r13 r16 1 1 # 2 # postman.conf - Postmanconfiguration file2 # mailjam.conf - Mailjam configuration file 3 3 # 4 4 # IMPORTANT: This config file should be used only … … 9 9 port = 9876 10 10 ssl = false 11 ssl_key = /usr/local/etc/ postman/ssl/postman.key12 ssl_crt = /usr/local/etc/ postman/ssl/postman.crt13 logfile = /tmp/ postman-tests/xmlrpc_server.log11 ssl_key = /usr/local/etc/mailjam/ssl/mailjam.key 12 ssl_crt = /usr/local/etc/mailjam/ssl/mailjam.crt 13 logfile = /tmp/mailjam-tests/xmlrpc_server.log 14 14 15 15 [storage] 16 16 backend = json 17 path = /tmp/ postman-tests/storage17 path = /tmp/mailjam-tests/storage 18 18 lists_db = %(path)s/mailings.%(backend)s 19 19 members_db = %(path)s/members.%(backend)s … … 22 22 enabled = true 23 23 backend = json 24 path = /tmp/ postman-tests/archives24 path = /tmp/mailjam-tests/archives 25 25 26 26 [mailing_lists] -
mailjam/tests/models.py
r10 r16 3 3 import os 4 4 from unittest import TestCase 5 from postman.models import Member, MailingList5 from mailjam.models import Member, MailingList 6 6 7 7 … … 19 19 class TestMailingList(TestCase): 20 20 def setUp(self): 21 configfile = os.path.join(os.path.dirname(__file__), ' postman.conf')21 configfile = os.path.join(os.path.dirname(__file__), 'mailjam.conf') 22 22 self.mailing_list = MailingList('test_list', 'test_list@example.com', 23 23 members={}, configfile=configfile) -
mailjam/tests/mta.py
r15 r16 3 3 import os, sys, multiprocessing, time 4 4 from unittest import TestCase 5 from postman.mta import MTAClient6 from postman.daemon import PostmanDaemon7 from postman.models import Member, MailingList5 from mailjam.mta import MTAClient 6 from mailjam.daemon import MailjamDaemon 7 from mailjam.models import Member, MailingList 8 8 9 9 … … 11 11 """ 12 12 FIXME: These are dummy tests, they cover almost nothing from the 13 real postmanmta client (yet)13 real mailjam mta client (yet) 14 14 """ 15 15 def setUp(self): 16 16 self.mta_configfile = os.path.join(os.path.dirname(__file__), 17 ' postman-mta.conf')17 'mailjam-mta.conf') 18 18 self.configfile = os.path.join(os.path.dirname(__file__), 19 ' postman.conf')19 'mailjam.conf') 20 20 self.mailing_list = MailingList('test_list', 'test_list@example.com', 21 21 members={}, configfile=self.configfile) … … 28 28 29 29 def test___init__(self): 30 # in order to start mta client instances, we need to have a postman30 # in order to start mta client instances, we need to have a mailjam 31 31 # daemon running on the background 32 32 # This should be added to the setUp() method, but then it would be 33 33 # more difficult to terminate the process after all the methods 34 34 # were called 35 daemon = PostmanDaemon(self.configfile)35 daemon = MailjamDaemon(self.configfile) 36 36 daemon.port = 9100 37 37 p = multiprocessing.Process(target=daemon.run) … … 54 54 55 55 def test_get_raw_email(self): 56 # in order to start mta client instances, we need to have a postman56 # in order to start mta client instances, we need to have a mailjam 57 57 # daemon running on the background 58 58 # This should be added to the setUp() method, but then it would be 59 59 # more difficult to terminate the process after all the methods 60 60 # were called 61 daemon = PostmanDaemon(self.configfile)61 daemon = MailjamDaemon(self.configfile) 62 62 daemon.port = 9100 63 63 p = multiprocessing.Process(target=daemon.run) … … 88 88 # sys_stdin = sys.stdin 89 89 # sys.stdin = open(self.raw_email_file, 'r') 90 # self.mta.save_raw_email.filename = '/tmp/ postman-test-mta-save-raw-email'90 # self.mta.save_raw_email.filename = '/tmp/mailjam-test-mta-save-raw-email' 91 91 92 92
Note:
See TracChangeset
for help on using the changeset viewer.