source: mailjam/postman/tests/mta.py@ 15:8ae771653ffe

Last change on this file since 15:8ae771653ffe was 15:8ae771653ffe, checked in by Borja Lopez <borja@…>, 13 years ago

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

File size: 3.7 KB
Line 
1# -*- coding: utf-8 -*-
2
3import os, sys, multiprocessing, time
4from unittest import TestCase
5from postman.mta import MTAClient
6from postman.daemon import PostmanDaemon
7from postman.models import Member, MailingList
8
9
10class TestMTAClient(TestCase):
11 """
12 FIXME: These are dummy tests, they cover almost nothing from the
13 real postman mta client (yet)
14 """
15 def setUp(self):
16 self.mta_configfile = os.path.join(os.path.dirname(__file__),
17 'postman-mta.conf')
18 self.configfile = os.path.join(os.path.dirname(__file__),
19 'postman.conf')
20 self.mailing_list = MailingList('test_list', 'test_list@example.com',
21 members={}, configfile=self.configfile)
22 self.member = Member('test@example.com')
23 self.raw_email_file = os.path.join(os.path.dirname(__file__),
24 'sample_raw_email.txt')
25 tmp_to_read = open(self.raw_email_file, 'r')
26 self.raw_email = tmp_to_read.read()
27 tmp_to_read.close()
28
29 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
43 with self.assertRaises(ValueError):
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)
50 self.assertEqual(mta.suscriptors, self.mailing_list.members_addresses)
51 self.assertEqual(mta.reply_to, self.mailing_list.address)
52
53 p.terminate()
54
55 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
71 sys_stdin = sys.stdin
72 sys.stdin = open(self.raw_email_file, 'r')
73 self.assertEqual(mta.get_raw_email(),
74 self.raw_email)
75 sys.stdin.close()
76 with self.assertRaises(IOError):
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()
86
87 #def save_raw_email(self):
88 # sys_stdin = sys.stdin
89 # sys.stdin = open(self.raw_email_file, 'r')
90 # self.mta.save_raw_email.filename = '/tmp/postman-test-mta-save-raw-email'
91
92
93
94
95
96
97
Note: See TracBrowser for help on using the repository browser.