Changeset 10:d5329a2a05b7 in mailjam for postman/tests


Ignore:
Timestamp:
May 20, 2012, 9:39:51 AM (13 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Fully added support for the configuration file. Now all the code uses
postman.conf to read the configuration parameters from it

Added a tests/postman.conf configuration file with specific configurtion
to use while testing (mostly tmp paths)

Updated the run_tests script to delete the temporary directory where
data is saved while running tests

Updated the tests modules/files so they use the tests config file

Location:
postman/tests
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • postman/tests/daemon.py

    r9 r10  
    11# -*- coding: utf-8 -*-
    22
    3 import os, multiprocessing, xmlrpclib
     3import os, multiprocessing, xmlrpclib, time
    44from SimpleXMLRPCServer import SimpleXMLRPCServer
    55from unittest import TestCase
     
    1818    """
    1919    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')
    2221        self.mailing_list = MailingList('test_list', 'test_list@example.com',
    23                                         members={}, config=config)
     22                                        members={}, configfile=self.configfile)
    2423        self.member =  Member('test@example.com')
    2524
    2625    def test___init__(self):
    27         postman = Postman()
     26        postman = Postman(configfile=self.configfile)
    2827        self.assertIsInstance(postman, Postman)
    2928        self.assertEqual(postman.mailings, {})
     
    3635
    3736    def test_save(self):
    38         postman = Postman()
     37        postman = Postman(configfile=self.configfile)
    3938        self.assertFalse(postman.save())
    4039        postman.add_mailing_list(self.mailing_list.info())
     
    4746
    4847    def test_load(self):
    49         postman = Postman()
     48        postman = Postman(configfile=self.configfile)
    5049        self.assertFalse(postman.mailings)
    5150        self.assertFalse(postman.mailings_addresses)
     
    5554
    5655        # Check that another postman instance is able to load the saved data
    57         postman_load = Postman()
     56        postman_load = Postman(configfile=self.configfile)
    5857        self.assertFalse(postman_load.mailings)
    5958        self.assertFalse(postman_load.mailings_addresses)
     
    6867
    6968    def test_clear(self):
    70         postman = Postman()
     69        postman = Postman(configfile=self.configfile)
    7170        self.assertFalse(postman.clear())
    7271        postman.add_mailing_list(self.mailing_list.info())
     
    7473
    7574    def test_add_mailing_list(self):
    76         postman = Postman()
     75        postman = Postman(configfile=self.configfile)
    7776        with self.assertRaises(TypeError):
    7877            # test improper info values
     
    10099
    101100    def test_add_mailing_member(self):
    102         postman = Postman()
     101        postman = Postman(configfile=self.configfile)
    103102        postman.add_mailing_list(self.mailing_list.info())
    104103        with self.assertRaises(ValueError):
     
    133132    """
    134133    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)
    139139        self.member =  Member('test@example.com')
    140140
    141141    def test___init__(self):
    142         daemon = PostmanDaemon()
     142        daemon = PostmanDaemon(self.configfile)
    143143        self.assertIsInstance(daemon, PostmanDaemon)
    144144        self.assertFalse(daemon.ready_to_serve)
     
    147147
    148148    def test_create_server(self):
    149         daemon = PostmanDaemon()
     149        daemon = PostmanDaemon(self.configfile)
    150150        daemon.port = 9001
    151151        self.assertTrue(daemon.create_server())
     
    154154       
    155155    def test_add_methods(self):
    156         daemon = PostmanDaemon()
     156        daemon = PostmanDaemon(self.configfile)
    157157        daemon.port = 9002
    158158        self.assertTrue(daemon.add_methods())
    159159        self.assertTrue(daemon.ready_to_serve)
    160160
    161         daemon = PostmanDaemon()
     161        daemon = PostmanDaemon(self.configfile)
    162162        daemon.port = 9003       
    163163        daemon.create_server()
     
    166166       
    167167    def test_run(self):
    168         daemon = PostmanDaemon()
     168        daemon = PostmanDaemon(self.configfile)
    169169        daemon.port = 9004
    170170        # start the daemon in another process, so we can start communicating
     
    172172        p = multiprocessing.Process(target=daemon.run)
    173173        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)
    174178       
    175179        # FIXME: Hardcoded url here, should be picked from a config file       
  • postman/tests/models.py

    r1 r10  
    11# -*- coding: utf-8 -*-
    22
     3import os
    34from unittest import TestCase
    45from postman.models import Member, MailingList
     
    1819class TestMailingList(TestCase):
    1920    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')
    2222        self.mailing_list = MailingList('test_list', 'test_list@example.com',
    23                                         members={}, config=config)
     23                                        members={}, configfile=configfile)
    2424        self.member =  Member('test@example.com')
    2525
  • postman/tests/mta.py

    r5 r10  
    66from postman.models import Member, MailingList
    77
    8 
    98class TestSendmail(TestCase):
    109    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')
    1312        self.mailing_list = MailingList('test_list', 'test_list@example.com',
    14                                         members={}, config=config)
     13                                        members={}, configfile=self.configfile)
    1514        self.member =  Member('test@example.com')
    1615        self.mta = Sendmail(self.mailing_list)
Note: See TracChangeset for help on using the changeset viewer.