Changeset 15:8ae771653ffe in mailjam for postman/tests


Ignore:
Timestamp:
May 21, 2012, 7:22:27 PM (13 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Added a postman-mta.conf version to be used in the tests

Added a script bin/postman-mta that will run the MTA client from a shell

Renamed the bin/postman_server script to bin/postman-server

Disabled the tests from tests/mta.py, as they are totally outdated and they
break the tests.

Replaced the old code in mta.Sendmail with a new mta.MTAClient class, which
contains code that actually *works* against a postman server (tests to come!)

Restructured the postman-mta.conf configuration file. The sections have better
names now (server, archive) and the archive section contains parameters which
names that reflect much better what they are used for.

Added a new parameter to the postman-mta.conf file (server.uri) that allows
us to set the uri to where any MTA client will have to connect, in only one
shorter line.

Fixed some typos in postman.config

Updated the setup.py script so the bin/postman-* scripts are installed
properly in the bin/ directory.

Added a function, proper_etc_path(), to the setup.py script so the path where
configuration files have to be installed is correctly set when building a
distribution/source package (still to be tested).

Updated the MANIFEST

Location:
postman/tests
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • postman/tests/__init__.py

    r11 r15  
    1212
    1313from models import *
    14 from mta import *
     14# from mta import *
    1515from daemon import *
  • postman/tests/mta.py

    r10 r15  
    11# -*- coding: utf-8 -*-
    22
    3 import os, sys
     3import os, sys, multiprocessing, time
    44from unittest import TestCase
    5 from postman.mta import Sendmail
     5from postman.mta import MTAClient
     6from postman.daemon import PostmanDaemon
    67from postman.models import Member, MailingList
    78
    8 class TestSendmail(TestCase):
     9
     10class TestMTAClient(TestCase):
     11    """
     12    FIXME: These are dummy tests, they cover almost nothing from the
     13    real postman mta client (yet)
     14    """
    915    def setUp(self):
     16        self.mta_configfile = os.path.join(os.path.dirname(__file__),
     17                                           'postman-mta.conf')
    1018        self.configfile = os.path.join(os.path.dirname(__file__),
    1119                                       'postman.conf')
     
    1321                                        members={}, configfile=self.configfile)
    1422        self.member =  Member('test@example.com')
    15         self.mta = Sendmail(self.mailing_list)
    1623        self.raw_email_file = os.path.join(os.path.dirname(__file__),
    1724                                           'sample_raw_email.txt')
     
    1926        self.raw_email = tmp_to_read.read()
    2027        tmp_to_read.close()
    21        
     28
    2229    def test___init__(self):
     30        # in order to start mta client instances, we need to have a postman
     31        # daemon running on the background
     32        # This should be added to the setUp() method, but then it would be
     33        # more difficult to terminate the process after all the methods
     34        # were called
     35        daemon = PostmanDaemon(self.configfile)
     36        daemon.port = 9100
     37        p = multiprocessing.Process(target=daemon.run)
     38        p.start()
     39        # Add a delay here to allow the server to be fully started before
     40        # starting to send requests from the client
     41        time.sleep(1)
     42
    2343        with self.assertRaises(ValueError):
    24             mta = Sendmail('test_list@example.com')
    25             mta = Sendmail(self.member)
    26             mta = Sendmail(None)
    27         mta = Sendmail(self.mailing_list)
    28         self.assertTrue(isinstance(mta, Sendmail))
    29         self.assertEqual(mta.mailing_list, self.mailing_list)
     44            mta = MTAClient(self.mailing_list, self.mta_configfile)
     45            mta = MTAClient(self.member, self.mta_configfile)
     46            mta = MTAClient(None, self.mta_configfile)
     47        mta = MTAClient(self.mailing_list.address, self.mta_configfile)
     48        self.assertTrue(isinstance(mta, MTAClient))
     49        self.assertEqual(mta.address, self.mailing_list.address)
    3050        self.assertEqual(mta.suscriptors, self.mailing_list.members_addresses)
    3151        self.assertEqual(mta.reply_to, self.mailing_list.address)
    3252
     53        p.terminate()
     54
    3355    def test_get_raw_email(self):
     56        # in order to start mta client instances, we need to have a postman
     57        # daemon running on the background
     58        # This should be added to the setUp() method, but then it would be
     59        # more difficult to terminate the process after all the methods
     60        # were called
     61        daemon = PostmanDaemon(self.configfile)
     62        daemon.port = 9100
     63        p = multiprocessing.Process(target=daemon.run)
     64        p.start()
     65        # Add a delay here to allow the server to be fully started before
     66        # starting to send requests from the client
     67        time.sleep(1)
     68
     69        mta = MTAClient(self.mailing_list.address, self.mta_configfile)
     70
    3471        sys_stdin = sys.stdin
    3572        sys.stdin = open(self.raw_email_file, 'r')
    36         self.assertEqual(self.mta.get_raw_email(),
     73        self.assertEqual(mta.get_raw_email(),
    3774                         self.raw_email)
    3875        sys.stdin.close()
    3976        with self.assertRaises(IOError):
    40             self.mta.get_raw_email()
     77            mta.get_raw_email()
     78
     79        tmp_file= open(self.raw_email_file('r'))
     80        raw_data = tmp_file.read()
     81        tmp_file.close()
     82        self.assertEqual(mta.get_raw_email(raw_data),
     83                         self.raw_email)
     84
     85        p.terminate()
    4186
    4287    #def save_raw_email(self):
Note: See TracChangeset for help on using the changeset viewer.