root / mailer / tests / test_mailer.py

Revision 143:1d4505cef74f, 2.0 kB (checked in by Tarek Ziad?? <tarek@…>, 16 months ago)

fixed mail headers

Line 
1#!/usr/bin/python
2# -*- coding: UTF-8 -*-
3#
4# Copyright (c) 2007 Tarek Ziadé
5#
6# Authors:
7#   Tarek Ziadé <tarek@ziade.org>
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation; either version 2
12# of the License, or (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22import os
23import unittest
24import sys
25
26dirname = os.path.dirname(__file__)
27if dirname == '':
28    dirname = '.'
29dirname = os.path.realpath(dirname)
30dirname = os.path.split(dirname)[0]
31
32if dirname not in sys.path:
33    sys.path.append(dirname)
34
35import settings
36
37settings.DATABASE = 'sqlite:///:memory:'
38
39from mailer import MailWorker
40from sender import send_mail
41
42class TestMailWorker(unittest.TestCase):
43
44    def test_get_message(self):
45
46        worker = MailWorker()
47        mail_id = send_mail('toto', ['toto@toto.com'],
48                            'vouvou', 'coucou é')
49
50        mail = worker._get_mails()[0]
51        msg = worker._get_message(mail)
52        raw = """\
53MIME-Version: 1.0
54Content-Transfer-Encoding: 8bit
55From: toto
56To: toto@toto.com
57Subject: vouvou
58Content-Type: text/plain; charset="utf-8"
59
60coucou \xc3\xa9"""
61
62        msg = msg.as_string().split('\n')
63        msg = [line for line in msg if not line.startswith('Date')]
64        msg = '\n'.join(msg)
65
66        self.assertEquals(msg, raw)
67
68
69def test_suite():
70    tests = [unittest.makeSuite(TestMailWorker)]
71    return unittest.TestSuite(tests)
72
73if __name__ == '__main__':
74    unittest.main(defaultTest='test_suite')
75
76
Note: See TracBrowser for help on using the browser.