Changeset 7:39e2245da71c in mailjam for postman/tests/daemon.py


Ignore:
Timestamp:
May 18, 2012, 5:54:56 PM (12 years ago)
Author:
Francisco de Borja Lopez Rio <borja@…>
Branch:
default
Phase:
public
Message:

Added some fixes to the XMLRPC server code

Added more tests for the XMLRPC server

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postman/tests/daemon.py

    r6 r7  
    11# -*- coding: utf-8 -*-
    22
    3 import os, xmlrpclib
     3import os, multiprocessing, xmlrpclib
     4from SimpleXMLRPCServer import SimpleXMLRPCServer
    45from unittest import TestCase
    5 from postman.daemon import Postman
     6
     7from postman.daemon import Postman, PostmanXMLRPC, PostmanDaemon
    68from postman.models import Member, MailingList
    79from postman.storage import JsonStorage as Storage
     
    126128    """
    127129    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
    129133    """
    130134    def setUp(self):
     
    134138                                        members={}, config=config)
    135139        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)
    137154       
    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.