Premiere version : mise en route du suivi.
[auf_roundup.git] / test / test_mailsplit.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.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 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 #
18 # $Id: test_mailsplit.py,v 1.15 2003-10-25 22:53:26 richard Exp $
19
20 import unittest, cStringIO
21
22 from roundup.mailgw import parseContent
23
24 class MailsplitTestCase(unittest.TestCase):
25 def testPreComment(self):
26 s = '''
27 blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah
28 blah blah blah blah blah blah blah blah blah blah blah!
29
30 issue_tracker@foo.com wrote:
31 > blah blah blah blahblah blahblah blahblah blah blah blah blah blah blah
32 > blah blah blah blah blah blah blah blah blah? blah blah blah blah blah
33 > blah blah blah blah blah blah blah... blah blah blah blah. blah blah
34 > blah blah blah blah? blah blah blah blah blah blah! blah blah!
35 >
36 > -------
37 > nosy: userfoo, userken
38 > _________________________________________________
39 > Roundup issue tracker
40 > issue_tracker@foo.com
41 > http://foo.com/cgi-bin/roundup.cgi/issue_tracker/
42
43 --
44 blah blah blah signature
45 userfoo@foo.com
46 '''
47 summary, content = parseContent(s, 0, 0)
48 self.assertEqual(summary, 'blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah')
49 self.assertEqual(content, 'blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah\nblah blah blah blah blah blah blah blah blah blah blah!')
50
51
52 def testPostComment(self):
53 s = '''
54 issue_tracker@foo.com wrote:
55 > blah blah blah blahblah blahblah blahblah blah blah blah blah blah
56 > blah
57 > blah blah blah blah blah blah blah blah blah? blah blah blah blah
58 > blah
59 > blah blah blah blah blah blah blah... blah blah blah blah. blah
60 > blah
61 > blah blah blah blah? blah blah blah blah blah blah! blah blah!
62 >
63 > -------
64 > nosy: userfoo, userken
65 > _________________________________________________
66 > Roundup issue tracker
67 > issue_tracker@foo.com
68 > http://foo.com/cgi-bin/roundup.cgi/issue_tracker/
69
70 blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah
71 blah blah blah blah blah blah blah blah blah blah blah!
72
73 --
74 blah blah blah signature
75 userfoo@foo.com
76 '''
77 summary, content = parseContent(s, 0, 0)
78 self.assertEqual(summary, 'blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah')
79 self.assertEqual(content, 'blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah\nblah blah blah blah blah blah blah blah blah blah blah!')
80
81
82 def testKeepCitation(self):
83 s = '''
84 blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah
85 blah blah blah blah blah blah blah blah blah blah blah!
86
87 issue_tracker@foo.com wrote:
88 > blah blah blah blahblah blahblah blahblah blah blah blah blah blah blah
89 > blah blah blah blah blah blah blah blah blah? blah blah blah blah blah
90 > blah blah blah blah blah blah blah... blah blah blah blah. blah blah
91 > blah blah blah blah? blah blah blah blah blah blah! blah blah!
92 >
93 > -------
94 > nosy: userfoo, userken
95 > _________________________________________________
96 > Roundup issue tracker
97 > issue_tracker@foo.com
98 > http://foo.com/cgi-bin/roundup.cgi/issue_tracker/
99
100 --
101 blah blah blah signature
102 userfoo@foo.com
103 '''
104 summary, content = parseContent(s, 1, 0)
105 self.assertEqual(summary, 'blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah')
106 self.assertEqual(content, '''\
107 blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah
108 blah blah blah blah blah blah blah blah blah blah blah!
109
110 issue_tracker@foo.com wrote:
111 > blah blah blah blahblah blahblah blahblah blah blah blah blah blah blah
112 > blah blah blah blah blah blah blah blah blah? blah blah blah blah blah
113 > blah blah blah blah blah blah blah... blah blah blah blah. blah blah
114 > blah blah blah blah? blah blah blah blah blah blah! blah blah!
115 >
116 > -------
117 > nosy: userfoo, userken
118 > _________________________________________________
119 > Roundup issue tracker
120 > issue_tracker@foo.com
121 > http://foo.com/cgi-bin/roundup.cgi/issue_tracker/''')
122
123
124 def testKeepBody(self):
125 s = '''
126 blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah
127 blah blah blah blah blah blah blah blah blah blah blah!
128
129 issue_tracker@foo.com wrote:
130 > blah blah blah blahblah blahblah blahblah blah blah blah blah blah blah
131 > blah blah blah blah blah blah blah blah blah? blah blah blah blah blah
132 > blah blah blah blah blah blah blah... blah blah blah blah. blah blah
133 > blah blah blah blah? blah blah blah blah blah blah! blah blah!
134 >
135 > -------
136 > nosy: userfoo, userken
137 > _________________________________________________
138 > Roundup issue tracker
139 > issue_tracker@foo.com
140 > http://foo.com/cgi-bin/roundup.cgi/issue_tracker/
141
142 --
143 blah blah blah signature
144 userfoo@foo.com
145 '''
146 summary, content = parseContent(s, 0, 1)
147 self.assertEqual(summary, 'blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah')
148 self.assertEqual(content, '''
149 blah blah blah blah... blah blah? blah blah blah blah blah. blah blah blah
150 blah blah blah blah blah blah blah blah blah blah blah!
151
152 issue_tracker@foo.com wrote:
153 > blah blah blah blahblah blahblah blahblah blah blah blah blah blah blah
154 > blah blah blah blah blah blah blah blah blah? blah blah blah blah blah
155 > blah blah blah blah blah blah blah... blah blah blah blah. blah blah
156 > blah blah blah blah? blah blah blah blah blah blah! blah blah!
157 >
158 > -------
159 > nosy: userfoo, userken
160 > _________________________________________________
161 > Roundup issue tracker
162 > issue_tracker@foo.com
163 > http://foo.com/cgi-bin/roundup.cgi/issue_tracker/
164
165 --
166 blah blah blah signature
167 userfoo@foo.com
168 ''')
169
170 def testAllQuoted(self):
171 s = '\nissue_tracker@foo.com wrote:\n> testing\n'
172 summary, content = parseContent(s, 0, 1)
173 self.assertEqual(summary, '')
174 self.assertEqual(content, s)
175
176 def testSimple(self):
177 s = '''testing'''
178 summary, content = parseContent(s, 0, 0)
179 self.assertEqual(summary, 'testing')
180 self.assertEqual(content, 'testing')
181
182 def testParagraphs(self):
183 s = '''testing\n\ntesting\n\ntesting'''
184 summary, content = parseContent(s, 0, 0)
185 self.assertEqual(summary, 'testing')
186 self.assertEqual(content, 'testing\n\ntesting\n\ntesting')
187
188 def testSimpleFollowup(self):
189 s = '''>hello\ntesting'''
190 summary, content = parseContent(s, 0, 0)
191 self.assertEqual(summary, 'testing')
192 self.assertEqual(content, 'testing')
193
194 def testSimpleFollowupParas(self):
195 s = '''>hello\ntesting\n\ntesting\n\ntesting'''
196 summary, content = parseContent(s, 0, 0)
197 self.assertEqual(summary, 'testing')
198 self.assertEqual(content, 'testing\n\ntesting\n\ntesting')
199
200 def testEmpty(self):
201 s = ''
202 summary, content = parseContent(s, 0, 0)
203 self.assertEqual(summary, '')
204 self.assertEqual(content, '')
205
206 def testIndentationSummary(self):
207 s = ' Four space indent.\n\n Four space indent.\nNo indent.'
208 summary, content = parseContent(s, 0, 0)
209 self.assertEqual(summary, ' Four space indent.')
210
211 def testIndentationContent(self):
212 s = ' Four space indent.\n\n Four space indent.\nNo indent.'
213 summary, content = parseContent(s, 0, 0)
214 self.assertEqual(content, s)
215
216 def testMultilineSummary(self):
217 s = 'This is a long sentence that would normally\nbe split. More words.'
218 summary, content = parseContent(s, 0, 0)
219 self.assertEqual(summary, 'This is a long sentence that would '
220 'normally\nbe split.')
221
222 def testKeepMultipleHyphens(self):
223 body = '''Testing, testing.
224
225 ----
226 Testing, testing.'''
227 summary, content = parseContent(body, 1, 0)
228 self.assertEqual(body, content)
229
230 def test_suite():
231 suite = unittest.TestSuite()
232 suite.addTest(unittest.makeSuite(MailsplitTestCase))
233 return suite
234
235 if __name__ == '__main__':
236 runner = unittest.TextTestRunner()
237 unittest.main(testRunner=runner)
238
239 # vim: set filetype=python ts=4 sw=4 et si