Changeset 7:39e2245da71c in mailjam for postman/tests
- Timestamp:
- May 18, 2012, 5:54:56 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
postman/tests/daemon.py
r6 r7 1 1 # -*- coding: utf-8 -*- 2 2 3 import os, xmlrpclib 3 import os, multiprocessing, xmlrpclib 4 from SimpleXMLRPCServer import SimpleXMLRPCServer 4 5 from unittest import TestCase 5 from postman.daemon import Postman 6 7 from postman.daemon import Postman, PostmanXMLRPC, PostmanDaemon 6 8 from postman.models import Member, MailingList 7 9 from postman.storage import JsonStorage as Storage … … 126 128 """ 127 129 postman.daemon.PostmanDaemon tests. 128 130 131 Remember to call the .clear() method of postman after each test, so 132 the temp storage files are deleted 129 133 """ 130 134 def setUp(self): … … 134 138 members={}, config=config) 135 139 self.member = Member('test@example.com') 136 # FIXME: Hardcoded url here, should be picked from a config file 140 141 def test___init__(self): 142 daemon = PostmanDaemon() 143 self.assertIsInstance(daemon, PostmanDaemon) 144 self.assertFalse(daemon.ready_to_serve) 145 # FIXME: More tests should be added here once the configuration 146 # file feature is added 147 148 def test_create_server(self): 149 daemon = PostmanDaemon() 150 daemon.port = 9001 151 self.assertTrue(daemon.create_server()) 152 self.assertIsInstance(daemon.server, SimpleXMLRPCServer) 153 self.assertFalse(daemon.ready_to_serve) 137 154 138 self.link = xmlrpclib.ServerProxy('http://localhost:9000') 155 def test_add_methods(self): 156 daemon = PostmanDaemon() 157 daemon.port = 9002 158 self.assertTrue(daemon.add_methods()) 159 self.assertTrue(daemon.ready_to_serve) 160 161 daemon = PostmanDaemon() 162 daemon.port = 9003 163 daemon.create_server() 164 self.assertTrue(daemon.add_methods()) 165 self.assertTrue(daemon.ready_to_serve) 166 167 def test_run(self): 168 daemon = PostmanDaemon() 169 daemon.port = 9004 170 # start the daemon in another process, so we can start communicating 171 # with itjobs = [] 172 p = multiprocessing.Process(target=daemon.run) 173 p.start() 174 175 # FIXME: Hardcoded url here, should be picked from a config file 176 client = xmlrpclib.ServerProxy('http://localhost:9004') 177 178 # Check that we can perform an XMLRPC call and that the list of 179 # available public methods contains the list of methods we have 180 # defined in our base XMLRPC class 181 set_class_methods = set(PostmanXMLRPC()._listMethods()) 182 set_xmlrpc_methods = set(client.system.listMethods()) 183 self.assertTrue(set_class_methods.issubset(set_xmlrpc_methods)) 184 185 # Stop the server 186 p.terminate() 187
Note:
See TracChangeset
for help on using the changeset viewer.