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 $
13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys
15 from roundup.mailgw import MailGW
16 from roundup import init, instance
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')
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
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...
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)
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...
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)
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>
89 New submission from Chef <chef@bork.bork.bork>:
91 This is a test submission of a new issue.
93 ___________________________________________________
94 "Roundup issue tracker" <issue_tracker@fill.me.in.>
95 http://some.useful.url/issue1
96 ___________________________________________________
97 ''', 'Generated message not correct')
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...
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)
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>
128 richard <richard@test> added the comment:
130 This is a followup
132 ___________________________________________________
133 "Roundup issue tracker" <issue_tracker@fill.me.in.>
134 http://some.useful.url/issue1
135 ___________________________________________________
136 ''', 'Generated message not correct')
138 class ExtMailgwTestCase(MailgwTestCase):
139 schema = 'extended'
141 def suite():
142 l = [unittest.makeSuite(MailgwTestCase, 'test'),
143 unittest.makeSuite(ExtMailgwTestCase, 'test')]
144 return unittest.TestSuite(l)
147 #
148 # $Log: not supported by cvs2svn $
149 #
150 #
151 #
152 # vim: set filetype=python ts=4 sw=4 et si