Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 475:a1a44636bace
Fix breakage caused by transaction changes.
Sorry for the huge checkin message - I was only intending to implement
[SF#496356] but I found a number of places where things had been
broken by transactions:
. modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
for _all_ roundup-generated smtp messages to be sent to.
. the transaction cache had broken the roundupdb.Class set() reactors
. newly-created author users in the mailgw weren't being committed to the db
Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
on when I found that stuff :):
. [SF#496356] Use threading in messages
. detectors were being registered multiple times
. added tests for mailgw
. much better attaching of erroneous messages in the mail gateway
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 02 Jan 2002 02:31:38 +0000 |
| parents | |
| children | f2edf460b0b9 c242455d9b46 |
comparison
equal
deleted
inserted
replaced
| 474:ef06a66a0b72 | 475:a1a44636bace |
|---|---|
| 1 # | |
| 2 # Copyright (c) 2001 Richard Jones, richard@bofh.asn.au. | |
| 3 # This module is free software, and you may redistribute it and/or modify | |
| 4 # under the same terms as Python, so long as this copyright message and | |
| 5 # disclaimer are retained in their original form. | |
| 6 # | |
| 7 # This module is distributed in the hope that it will be useful, | |
| 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 10 # | |
| 11 # $Id: test_mailgw.py,v 1.1 2002-01-02 02:31:38 richard Exp $ | |
| 12 | |
| 13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys | |
| 14 | |
| 15 from roundup.mailgw import MailGW | |
| 16 from roundup import init, instance | |
| 17 | |
| 18 class MailgwTestCase(unittest.TestCase): | |
| 19 count = 0 | |
| 20 schema = 'classic' | |
| 21 def setUp(self): | |
| 22 MailgwTestCase.count = MailgwTestCase.count + 1 | |
| 23 self.dirname = '_test_%s'%self.count | |
| 24 try: | |
| 25 shutil.rmtree(self.dirname) | |
| 26 except OSError, error: | |
| 27 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | |
| 28 # create the instance | |
| 29 init.init(self.dirname, self.schema, 'anydbm', 'sekrit') | |
| 30 # check we can load the package | |
| 31 self.instance = instance.open(self.dirname) | |
| 32 # and open the database | |
| 33 self.db = self.instance.open('sekrit') | |
| 34 self.db.user.create(username='Chef', address='chef@bork.bork.bork') | |
| 35 self.db.user.create(username='richard', address='richard@test') | |
| 36 | |
| 37 def tearDown(self): | |
| 38 if os.path.exists(os.environ['SENDMAILDEBUG']): | |
| 39 os.remove(os.environ['SENDMAILDEBUG']) | |
| 40 try: | |
| 41 shutil.rmtree(self.dirname) | |
| 42 except OSError, error: | |
| 43 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | |
| 44 | |
| 45 def testNewIssue(self): | |
| 46 message = cStringIO.StringIO('''Content-Type: text/plain; | |
| 47 charset="iso-8859-1" | |
| 48 From: Chef <chef@bork.bork.bork | |
| 49 To: issue_tracker@fill.me.in. | |
| 50 Cc: richard@test | |
| 51 Message-Id: <dummy_test_message_id> | |
| 52 Subject: [issue] Testing... | |
| 53 | |
| 54 This is a test submission of a new issue. | |
| 55 ''') | |
| 56 handler = self.instance.MailGW(self.instance, self.db) | |
| 57 handler.main(message) | |
| 58 if os.path.exists(os.environ['SENDMAILDEBUG']): | |
| 59 error = open(os.environ['SENDMAILDEBUG']).read() | |
| 60 self.assertEqual('no error', error) | |
| 61 | |
| 62 def testNewIssueAuthMsg(self): | |
| 63 message = cStringIO.StringIO('''Content-Type: text/plain; | |
| 64 charset="iso-8859-1" | |
| 65 From: Chef <chef@bork.bork.bork | |
| 66 To: issue_tracker@fill.me.in. | |
| 67 Message-Id: <dummy_test_message_id> | |
| 68 Subject: [issue] Testing... | |
| 69 | |
| 70 This is a test submission of a new issue. | |
| 71 ''') | |
| 72 handler = self.instance.MailGW(self.instance, self.db) | |
| 73 # TODO: fix the damn config - this is apalling | |
| 74 self.instance.IssueClass.MESSAGES_TO_AUTHOR = 'yes' | |
| 75 handler.main(message) | |
| 76 | |
| 77 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(), | |
| 78 '''FROM: roundup-admin@fill.me.in. | |
| 79 TO: chef@bork.bork.bork | |
| 80 Content-Type: text/plain | |
| 81 Subject: [issue1] Testing... | |
| 82 To: chef@bork.bork.bork | |
| 83 From: Chef <issue_tracker@fill.me.in.> | |
| 84 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.> | |
| 85 MIME-Version: 1.0 | |
| 86 Message-Id: <dummy_test_message_id> | |
| 87 | |
| 88 | |
| 89 New submission from Chef <chef@bork.bork.bork>: | |
| 90 | |
| 91 This is a test submission of a new issue. | |
| 92 | |
| 93 ___________________________________________________ | |
| 94 "Roundup issue tracker" <issue_tracker@fill.me.in.> | |
| 95 http://some.useful.url/issue1 | |
| 96 ___________________________________________________ | |
| 97 ''', 'Generated message not correct') | |
| 98 | |
| 99 def testFollowup(self): | |
| 100 self.testNewIssue() | |
| 101 message = cStringIO.StringIO('''Content-Type: text/plain; | |
| 102 charset="iso-8859-1" | |
| 103 From: richard <richard@test> | |
| 104 To: issue_tracker@fill.me.in. | |
| 105 Message-Id: <followup_dummy_id> | |
| 106 In-Reply-To: <dummy_test_message_id> | |
| 107 Subject: [issue1] Testing... | |
| 108 | |
| 109 This is a followup | |
| 110 ''') | |
| 111 handler = self.instance.MailGW(self.instance, self.db) | |
| 112 # TODO: fix the damn config - this is apalling | |
| 113 handler.main(message) | |
| 114 | |
| 115 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(), | |
| 116 '''FROM: roundup-admin@fill.me.in. | |
| 117 TO: chef@bork.bork.bork | |
| 118 Content-Type: text/plain | |
| 119 Subject: [issue1] Testing... | |
| 120 To: chef@bork.bork.bork | |
| 121 From: richard <issue_tracker@fill.me.in.> | |
| 122 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.> | |
| 123 MIME-Version: 1.0 | |
| 124 Message-Id: <followup_dummy_id> | |
| 125 In-Reply-To: <dummy_test_message_id> | |
| 126 | |
| 127 | |
| 128 richard <richard@test> added the comment: | |
| 129 | |
| 130 This is a followup | |
| 131 | |
| 132 ___________________________________________________ | |
| 133 "Roundup issue tracker" <issue_tracker@fill.me.in.> | |
| 134 http://some.useful.url/issue1 | |
| 135 ___________________________________________________ | |
| 136 ''', 'Generated message not correct') | |
| 137 | |
| 138 class ExtMailgwTestCase(MailgwTestCase): | |
| 139 schema = 'extended' | |
| 140 | |
| 141 def suite(): | |
| 142 l = [unittest.makeSuite(MailgwTestCase, 'test'), | |
| 143 unittest.makeSuite(ExtMailgwTestCase, 'test')] | |
| 144 return unittest.TestSuite(l) | |
| 145 | |
| 146 | |
| 147 # | |
| 148 # $Log: not supported by cvs2svn $ | |
| 149 # | |
| 150 # | |
| 151 # | |
| 152 # vim: set filetype=python ts=4 sw=4 et si |
