Changeset 7:39e2245da71c in mailjam
- Timestamp:
- May 18, 2012, 5:54:56 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- postman
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
postman/daemon.py
r6 r7 152 152 153 153 def _listMethods(self): 154 return list_public_methods(self) 154 public_methods = [] 155 public_methods += ['lists.'+i for i in dir(MailingListXMLRPC) if '_' not in i] 156 public_methods += ['members.'+i for i in dir(MemberXMLRPC) if '_' not in i] 157 return public_methods 155 158 156 159 def _methodHelp(self, method): … … 165 168 def add(self, info={}): 166 169 self.postman.add_mailing_list(info) 170 def addresses(self): 171 return self.postman.mailings_addresses 167 172 168 173 … … 185 190 self.configfile = configfile 186 191 192 # FIXME: These should be loaded from a config file 193 self.address='localhost' 194 self.port = 9000 195 187 196 self.logfile = os.path.join(os.path.dirname(__file__), 'server.log') 188 197 logging.basicConfig(filename=self.logfile, level=logging.DEBUG) … … 196 205 of SimpleXMLRPCServer in that attribute. If there is already a server 197 206 initialized there, simply return True 198 """ 199 address='localhost' 200 port = 9000 207 """ 201 208 if not self.server: 202 msg = 'Creating XMLRPC server object on {}:{}'.format(address,port) 209 msg = 'Creating XMLRPC server object on {}:{}'.format(self.address, 210 self.port) 203 211 logging.info(msg) 204 self.server = SimpleXMLRPCServer((address, port), allow_none=True, 205 logRequests=True) 212 self.server = SimpleXMLRPCServer((self.address, self.port), 213 allow_none=True, 214 logRequests=False) 206 215 self.server.register_introspection_functions() 207 216 return True … … 225 234 self.server.register_instance(root, allow_dotted_names=True) 226 235 self.ready_to_serve = True 236 return self.ready_to_serve 227 237 228 238 def run(self): … … 234 244 if not self.ready_to_serve: 235 245 self.add_methods() 236 msg = 'Starting XMLRPC server on {}:{}'.format(address,port) 246 msg = 'Starting XMLRPC server on {}:{}'.format(self.address, 247 self.port) 237 248 logging.info(msg) 238 self.server.serve_forever() 249 try: 250 self.server.serve_forever() 251 except KeyboardInterrupt: 252 msg = 'Stopping server' 253 logging.info(msg) -
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.