Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 4579:ba4c632143f6
issue2550535 Fix keep_quoted_text=yes setting.
In some cases even when keep_quoted_text=yes is configured we would
strip quoted sections. This hit the python bug-tracker especially for
python interpreter examples with leading '>>>' strings. The fix is
slightly different compared to the proposal as this broke
keep_quoted_text=no in certain cases. We also fix a bug where
keep_quoted_text=no would drop the last line of a non-quoted section if
there wasn't an empty line between the next quotes.
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Thu, 05 Jan 2012 20:55:47 +0100 |
| parents | c426cb251bc7 |
| children | 782737d1a2d7 |
comparison
equal
deleted
inserted
replaced
| 4578:941681fec1b0 | 4579:ba4c632143f6 |
|---|---|
| 34 from roundup import init, instance, password, rfc2822, __version__ | 34 from roundup import init, instance, password, rfc2822, __version__ |
| 35 from roundup.anypy.sets_ import set | 35 from roundup.anypy.sets_ import set |
| 36 | 36 |
| 37 #import db_test_base | 37 #import db_test_base |
| 38 import memorydb | 38 import memorydb |
| 39 | |
| 40 def expectedFailure(method): | |
| 41 """ For marking a failing test. | |
| 42 This will *not* run the test and return success instead. | |
| 43 """ | |
| 44 return lambda x: 0 | |
| 39 | 45 |
| 40 class Message(rfc822.Message): | 46 class Message(rfc822.Message): |
| 41 """String-based Message class with equivalence test.""" | 47 """String-based Message class with equivalence test.""" |
| 42 def __init__(self, s): | 48 def __init__(self, s): |
| 43 rfc822.Message.__init__(self, StringIO(s.strip())) | 49 rfc822.Message.__init__(self, StringIO(s.strip())) |
| 2278 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example> | 2284 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example> |
| 2279 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> | 2285 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> |
| 2280 _______________________________________________________________________ | 2286 _______________________________________________________________________ |
| 2281 ''') | 2287 ''') |
| 2282 | 2288 |
| 2283 def testEmailQuoting(self): | 2289 firstquotingtest = '''Content-Type: text/plain; |
| 2284 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'no' | |
| 2285 self.innerTestQuoting('''This is a followup | |
| 2286 ''') | |
| 2287 | |
| 2288 def testEmailQuotingRemove(self): | |
| 2289 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'yes' | |
| 2290 self.innerTestQuoting('''Blah blah wrote: | |
| 2291 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf | |
| 2292 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj | |
| 2293 > | |
| 2294 | |
| 2295 This is a followup | |
| 2296 ''') | |
| 2297 | |
| 2298 def innerTestQuoting(self, expect): | |
| 2299 nodeid = self.doNewIssue() | |
| 2300 | |
| 2301 messages = self.db.issue.get(nodeid, 'messages') | |
| 2302 | |
| 2303 self._handle_mail('''Content-Type: text/plain; | |
| 2304 charset="iso-8859-1" | 2290 charset="iso-8859-1" |
| 2305 From: richard <richard@test.test> | 2291 From: richard <richard@test.test> |
| 2306 To: issue_tracker@your.tracker.email.domain.example | 2292 To: issue_tracker@your.tracker.email.domain.example |
| 2307 Message-Id: <followup_dummy_id> | 2293 Message-Id: <followup_dummy_id> |
| 2308 In-Reply-To: <dummy_test_message_id> | 2294 In-Reply-To: <dummy_test_message_id> |
| 2312 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf | 2298 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf |
| 2313 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj | 2299 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj |
| 2314 > | 2300 > |
| 2315 | 2301 |
| 2316 This is a followup | 2302 This is a followup |
| 2317 ''') | 2303 ''' |
| 2304 | |
| 2305 def testEmailQuoting(self): | |
| 2306 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'no' | |
| 2307 self.innerTestQuoting(self.firstquotingtest, '''This is a followup | |
| 2308 ''', 'This is a followup') | |
| 2309 | |
| 2310 def testEmailQuotingRemove(self): | |
| 2311 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'yes' | |
| 2312 self.innerTestQuoting(self.firstquotingtest, '''Blah blah wrote: | |
| 2313 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf | |
| 2314 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj | |
| 2315 > | |
| 2316 | |
| 2317 This is a followup | |
| 2318 ''', 'This is a followup') | |
| 2319 | |
| 2320 secondquotingtest = '''Content-Type: text/plain; | |
| 2321 charset="iso-8859-1" | |
| 2322 From: richard <richard@test.test> | |
| 2323 To: issue_tracker@your.tracker.email.domain.example | |
| 2324 Message-Id: <followup_dummy_id> | |
| 2325 In-Reply-To: <dummy_test_message_id> | |
| 2326 Subject: Re: [issue1] Testing... | |
| 2327 | |
| 2328 On Tue, Feb 23, 2010 at 8:46 AM, Someone <report@bugs.python.org> wrote: | |
| 2329 > aa | |
| 2330 > aa | |
| 2331 | |
| 2332 AA: | |
| 2333 | |
| 2334 AA | |
| 2335 | |
| 2336 AA | |
| 2337 | |
| 2338 AA | |
| 2339 | |
| 2340 TEXT BEFORE QUOTE | |
| 2341 > bb | |
| 2342 > bb | |
| 2343 > | |
| 2344 | |
| 2345 BB | |
| 2346 BB | |
| 2347 BB | |
| 2348 BB | |
| 2349 | |
| 2350 > cc | |
| 2351 > | |
| 2352 > cc | |
| 2353 > | |
| 2354 > | |
| 2355 > cc | |
| 2356 > | |
| 2357 > cc | |
| 2358 > | |
| 2359 > cc | |
| 2360 > | |
| 2361 CC | |
| 2362 | |
| 2363 -- | |
| 2364 added signature | |
| 2365 ''' | |
| 2366 def testEmailQuoting2(self): | |
| 2367 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'no' | |
| 2368 self.innerTestQuoting(self.secondquotingtest, '''AA: | |
| 2369 | |
| 2370 AA | |
| 2371 | |
| 2372 AA | |
| 2373 | |
| 2374 AA | |
| 2375 | |
| 2376 TEXT BEFORE QUOTE | |
| 2377 | |
| 2378 BB | |
| 2379 BB | |
| 2380 BB | |
| 2381 BB | |
| 2382 | |
| 2383 CC | |
| 2384 ''', 'AA:') | |
| 2385 | |
| 2386 def testEmailQuotingRemove2(self): | |
| 2387 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'yes' | |
| 2388 self.innerTestQuoting(self.secondquotingtest, | |
| 2389 '\n'.join(self.secondquotingtest.split('\n')[8:-3]), 'AA:') | |
| 2390 | |
| 2391 thirdquotingtest = '''Content-Type: text/plain; | |
| 2392 charset="iso-8859-1" | |
| 2393 From: richard <richard@test.test> | |
| 2394 To: issue_tracker@your.tracker.email.domain.example | |
| 2395 Message-Id: <followup_dummy_id> | |
| 2396 In-Reply-To: <dummy_test_message_id> | |
| 2397 Subject: Re: [issue1] Testing... | |
| 2398 | |
| 2399 On Mon, Jan 02, 2012 at 06:14:27PM +0000, Someone wrote: | |
| 2400 > | |
| 2401 > aa | |
| 2402 > | |
| 2403 > aa | |
| 2404 > aa | |
| 2405 > aa | |
| 2406 AA0 | |
| 2407 AA | |
| 2408 | |
| 2409 > bb | |
| 2410 > bb | |
| 2411 > bb | |
| 2412 BB | |
| 2413 | |
| 2414 > cc | |
| 2415 > cc | |
| 2416 > cc | |
| 2417 > cc | |
| 2418 > cc | |
| 2419 > cc | |
| 2420 | |
| 2421 CC | |
| 2422 CC | |
| 2423 CC | |
| 2424 | |
| 2425 CC | |
| 2426 CC | |
| 2427 | |
| 2428 CC | |
| 2429 CC | |
| 2430 CC | |
| 2431 CC | |
| 2432 | |
| 2433 CC | |
| 2434 | |
| 2435 NAME | |
| 2436 -- | |
| 2437 sig | |
| 2438 sig | |
| 2439 sig | |
| 2440 sig | |
| 2441 ''' | |
| 2442 | |
| 2443 # This fails because the sig isn't removed (we currently remove the | |
| 2444 # sig only if the delimiter is the first line in a section) | |
| 2445 @expectedFailure | |
| 2446 def testEmailQuotingRemove3(self): | |
| 2447 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'yes' | |
| 2448 self.innerTestQuoting(self.thirdquotingtest, | |
| 2449 '\n'.join(self.thirdquotingtest.split('\n')[8:-6]), 'AA0') | |
| 2450 | |
| 2451 def innerTestQuoting(self, msgtext, expect, summary=None): | |
| 2452 nodeid = self.doNewIssue() | |
| 2453 | |
| 2454 messages = self.db.issue.get(nodeid, 'messages') | |
| 2455 | |
| 2456 self._handle_mail(msgtext) | |
| 2318 # figure the new message id | 2457 # figure the new message id |
| 2319 newmessages = self.db.issue.get(nodeid, 'messages') | 2458 newmessages = self.db.issue.get(nodeid, 'messages') |
| 2320 for msg in messages: | 2459 for msg in messages: |
| 2321 newmessages.remove(msg) | 2460 newmessages.remove(msg) |
| 2322 messageid = newmessages[0] | 2461 messageid = newmessages[0] |
| 2323 | 2462 |
| 2324 self.compareMessages(self.db.msg.get(messageid, 'content'), expect) | 2463 self.compareMessages(self.db.msg.get(messageid, 'content'), expect) |
| 2464 if summary: | |
| 2465 self.assertEqual (summary, self.db.msg.get(messageid, 'summary')) | |
| 2325 | 2466 |
| 2326 def testUserLookup(self): | 2467 def testUserLookup(self): |
| 2327 i = self.db.user.create(username='user1', address='user1@foo.com') | 2468 i = self.db.user.create(username='user1', address='user1@foo.com') |
| 2328 self.assertEqual(uidFromAddress(self.db, ('', 'user1@foo.com'), 0), i) | 2469 self.assertEqual(uidFromAddress(self.db, ('', 'user1@foo.com'), 0), i) |
| 2329 self.assertEqual(uidFromAddress(self.db, ('', 'USER1@foo.com'), 0), i) | 2470 self.assertEqual(uidFromAddress(self.db, ('', 'USER1@foo.com'), 0), i) |
