| 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. |
|---|
| 22 | import os |
|---|
| 23 | import unittest |
|---|
| 24 | import sys |
|---|
| 25 | |
|---|
| 26 | dirname = os.path.dirname(__file__) |
|---|
| 27 | if dirname == '': |
|---|
| 28 | dirname = '.' |
|---|
| 29 | dirname = os.path.realpath(dirname) |
|---|
| 30 | dirname = os.path.split(dirname)[0] |
|---|
| 31 | |
|---|
| 32 | if dirname not in sys.path: |
|---|
| 33 | sys.path.append(dirname) |
|---|
| 34 | |
|---|
| 35 | import settings |
|---|
| 36 | |
|---|
| 37 | settings.DATABASE = 'sqlite:///:memory:' |
|---|
| 38 | |
|---|
| 39 | from mailer import MailWorker |
|---|
| 40 | from sender import send_mail |
|---|
| 41 | |
|---|
| 42 | class 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 = """\ |
|---|
| 53 | MIME-Version: 1.0 |
|---|
| 54 | Content-Transfer-Encoding: 8bit |
|---|
| 55 | From: toto |
|---|
| 56 | To: toto@toto.com |
|---|
| 57 | Subject: vouvou |
|---|
| 58 | Content-Type: text/plain; charset="utf-8" |
|---|
| 59 | |
|---|
| 60 | coucou \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 | |
|---|
| 69 | def test_suite(): |
|---|
| 70 | tests = [unittest.makeSuite(TestMailWorker)] |
|---|
| 71 | return unittest.TestSuite(tests) |
|---|
| 72 | |
|---|
| 73 | if __name__ == '__main__': |
|---|
| 74 | unittest.main(defaultTest='test_suite') |
|---|
| 75 | |
|---|
| 76 | |
|---|