Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 6670:0ef688717613
Add testing for beautifulsoup4 as html -> text converter.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 11 May 2022 00:52:02 -0400 |
| parents | 2453d7b58a92 |
| children | 01216187a167 |
comparison
equal
deleted
inserted
replaced
| 6669:ef0975b4291b | 6670:0ef688717613 |
|---|---|
| 24 # FIX: workaround for a bug in pytest.mark.skip(): | 24 # FIX: workaround for a bug in pytest.mark.skip(): |
| 25 # https://github.com/pytest-dev/pytest/issues/568 | 25 # https://github.com/pytest-dev/pytest/issues/568 |
| 26 from .pytest_patcher import mark_class | 26 from .pytest_patcher import mark_class |
| 27 skip_pgp = mark_class(pytest.mark.skip( | 27 skip_pgp = mark_class(pytest.mark.skip( |
| 28 reason="Skipping PGP tests: 'gpg' not installed")) | 28 reason="Skipping PGP tests: 'gpg' not installed")) |
| 29 | |
| 30 try: | |
| 31 import bs4 | |
| 32 skip_beautifulsoup = lambda func, *args, **kwargs: func | |
| 33 except ImportError: | |
| 34 from .pytest_patcher import mark_class | |
| 35 skip_beautifulsoup = mark_class(pytest.mark.skip( | |
| 36 reason="Skipping beautifulsoup tests: 'bs4' not installed")) | |
| 29 | 37 |
| 30 | 38 |
| 31 from roundup.anypy.email_ import message_from_bytes | 39 from roundup.anypy.email_ import message_from_bytes |
| 32 from roundup.anypy.strings import b2s, u2s, s2b | 40 from roundup.anypy.strings import b2s, u2s, s2b |
| 33 | 41 |
| 234 ] | 242 ] |
| 235 self.db.security.role['anonymous'].permissions = p | 243 self.db.security.role['anonymous'].permissions = p |
| 236 | 244 |
| 237 def _create_mailgw(self, message, args=()): | 245 def _create_mailgw(self, message, args=()): |
| 238 class MailGW(self.instance.MailGW): | 246 class MailGW(self.instance.MailGW): |
| 247 """call _handle_message as handle_message | |
| 248 the real handle_message reopens the database, and destroys | |
| 249 the db that we supply as part of the test. | |
| 250 """ | |
| 239 def handle_message(self, message): | 251 def handle_message(self, message): |
| 240 return self._handle_message(message) | 252 return self._handle_message(message) |
| 241 handler = MailGW(self.instance, args) | 253 handler = MailGW(self.instance, args) |
| 242 handler.db = self.db | 254 handler.db = self.db |
| 243 return handler | 255 return handler |
| 295 self.assertEqual(self.db.issue.get(nodeid, 'tx_Source'), 'email') | 307 self.assertEqual(self.db.issue.get(nodeid, 'tx_Source'), 'email') |
| 296 | 308 |
| 297 | 309 |
| 298 class MailgwTestCase(MailgwTestAbstractBase, StringFragmentCmpHelper, unittest.TestCase): | 310 class MailgwTestCase(MailgwTestAbstractBase, StringFragmentCmpHelper, unittest.TestCase): |
| 299 | 311 |
| 300 def testTextHtmlMessage(self): | 312 @skip_beautifulsoup |
| 313 def testTextHtmlMessageBeautifulSoup(self): | |
| 314 self.testTextHtmlMessage(converter='beautifulsoup') | |
| 315 | |
| 316 def testTextHtmlMessage(self, converter='dehtml'): | |
| 301 html_message='''Content-Type: text/html; | 317 html_message='''Content-Type: text/html; |
| 302 charset="iso-8859-1" | 318 charset="iso-8859-1" |
| 303 From: Chef <chef@bork.bork.bork> | 319 From: Chef <chef@bork.bork.bork> |
| 304 To: issue_tracker@your.tracker.email.domain.example | 320 To: issue_tracker@your.tracker.email.domain.example |
| 305 Cc: richard@test.test | 321 Cc: richard@test.test |
| 351 have to install the win32all package separately (get it from | 367 have to install the win32all package separately (get it from |
| 352 <a class="reference external" href="http://starship.python.net/crew/mhammond/win32/">http://starship.python.net/crew/mhammond/win32/</a>).</p> | 368 <a class="reference external" href="http://starship.python.net/crew/mhammond/win32/">http://starship.python.net/crew/mhammond/win32/</a>).</p> |
| 353 </div> | 369 </div> |
| 354 </body> | 370 </body> |
| 355 ''' | 371 ''' |
| 356 text_fragments = ['Roundup\n Home\nDownload\nDocs\nRoundup Features\nInstalling Roundup\nUpgrading to newer versions of Roundup\nRoundup FAQ\nUser Guide\nCustomising Roundup\nAdministration Guide\nPrerequisites\n\nRoundup requires Python 2.6 or newer (but not Python 3) with a functioning\nanydbm module. Download the latest version from http://www.python.org/.\nIt is highly recommended that users install the latest patch version\nof python as these contain many fixes to serious bugs.\n\nSome variants of Linux will need an additional ', ('python dev', u2s(u'\u201cpython dev\u201d')), ' package\ninstalled for Roundup installation to work. Debian and derivatives, are\nknown to require this.\n\nIf you', (u2s(u'\u2019'), ''), 're on windows, you will either need to be using the ActiveState python\ndistribution (at http://www.activestate.com/Products/ActivePython/), or you', (u2s(u'\u2019'), ''), 'll\nhave to install the win32all package separately (get it from\nhttp://starship.python.net/crew/mhammond/win32/).'] | 372 text_fragments = {} |
| 357 | 373 text_fragments['dehtml'] = ['Roundup\n Home\nDownload\nDocs\nRoundup Features\nInstalling Roundup\nUpgrading to newer versions of Roundup\nRoundup FAQ\nUser Guide\nCustomising Roundup\nAdministration Guide\nPrerequisites\n\nRoundup requires Python 2.6 or newer (but not Python 3) with a functioning\nanydbm module. Download the latest version from http://www.python.org/.\nIt is highly recommended that users install the latest patch version\nof python as these contain many fixes to serious bugs.\n\nSome variants of Linux will need an additional ', ('python dev', u2s(u'\u201cpython dev\u201d')), ' package\ninstalled for Roundup installation to work. Debian and derivatives, are\nknown to require this.\n\nIf you', (u2s(u'\u2019'), ''), 're on windows, you will either need to be using the ActiveState python\ndistribution (at http://www.activestate.com/Products/ActivePython/), or you', (u2s(u'\u2019'), ''), 'll\nhave to install the win32all package separately (get it from\nhttp://starship.python.net/crew/mhammond/win32/).'] |
| 358 self.db.config.MAILGW_CONVERT_HTMLTOTEXT = "dehtml" | 374 text_fragments['beautifulsoup'] = ['Roundup\nHome\nDownload\nDocs\nRoundup Features\nInstalling Roundup\nUpgrading to newer versions of Roundup\nRoundup FAQ\nUser Guide\nCustomising Roundup\nAdministration Guide\nPrerequisites\nRoundup requires Python 2.6 or newer (but not Python 3) with a functioning\nanydbm module. Download the latest version from\nhttp://www.python.org/\n.\nIt is highly recommended that users install the latest patch version\nof python as these contain many fixes to serious bugs.\nSome variants of Linux will need an additional ', ('python dev', u2s(u'\u201cpython dev\u201d')), ' package\ninstalled for Roundup installation to work. Debian and derivatives, are\nknown to require this.\nIf you', (u2s(u'\u2019'), "'"), 're on windows, you will either need to be using the ActiveState python\ndistribution (at\nhttp://www.activestate.com/Products/ActivePython/\n), or you’ll\nhave to install the win32all package separately (get it from\nhttp://starship.python.net/crew/mhammond/win32/\n).'] |
| 375 | |
| 376 self.db.config.MAILGW_CONVERT_HTMLTOTEXT = converter | |
| 359 nodeid = self._handle_mail(html_message) | 377 nodeid = self._handle_mail(html_message) |
| 360 assert not os.path.exists(SENDMAILDEBUG) | 378 assert not os.path.exists(SENDMAILDEBUG) |
| 361 msgid = self.db.issue.get(nodeid, 'messages')[0] | 379 msgid = self.db.issue.get(nodeid, 'messages')[0] |
| 362 self.compareStringFragments(self.db.msg.get(msgid, 'content'), | 380 self.compareStringFragments(self.db.msg.get(msgid, 'content'), |
| 363 text_fragments) | 381 text_fragments[converter]) |
| 364 | 382 |
| 365 self.db.config.MAILGW_CONVERT_HTMLTOTEXT = "none" | 383 if converter == 'dehtml': |
| 366 self.assertRaises(MailUsageError, self._handle_mail, html_message) | 384 self.db.config.MAILGW_CONVERT_HTMLTOTEXT = "none" |
| 385 self.assertRaises(MailUsageError, self._handle_mail, html_message) | |
| 367 | 386 |
| 368 def testMessageWithFromInIt(self): | 387 def testMessageWithFromInIt(self): |
| 369 nodeid = self._handle_mail('''Content-Type: text/plain; | 388 nodeid = self._handle_mail('''Content-Type: text/plain; |
| 370 charset="iso-8859-1" | 389 charset="iso-8859-1" |
| 371 From: Chef <chef@bork.bork.bork> | 390 From: Chef <chef@bork.bork.bork> |
| 1379 | 1398 |
| 1380 %s | 1399 %s |
| 1381 --001485f339f8f361fb049188dbba-- | 1400 --001485f339f8f361fb049188dbba-- |
| 1382 '''%html_doc | 1401 '''%html_doc |
| 1383 | 1402 |
| 1384 def disabletestMultipartTextifyHTMLBeautifulSoup(self): | 1403 @skip_beautifulsoup |
| 1385 self.maxDiff = None | 1404 def testMultipartTextifyHTMLBeautifulSoup(self): |
| 1386 self.MultipartTextifyHTML(converter="beautifulsoup") | 1405 self.testMultipartTextifyHTML(converter="beautifulsoup") |
| 1387 | 1406 |
| 1388 def testMultipartTextifyHTMLDehtml(self): | 1407 def testMultipartTextifyHTML(self, converter='dehtml'): |
| 1389 self.MultipartTextifyHTML(converter="dehtml") | |
| 1390 | |
| 1391 def MultipartTextifyHTML(self, converter='dehtml'): | |
| 1392 text_fragments = {} | 1408 text_fragments = {} |
| 1393 text_fragments['dehtml'] = ['Roundup\n Home\nDownload\nDocs\nRoundup Features\nInstalling Roundup\nUpgrading to newer versions of Roundup\nRoundup FAQ\nUser Guide\nCustomising Roundup\nAdministration Guide\nPrerequisites\n\nRoundup requires Python 2.5 or newer (but not Python 3) with a functioning\nanydbm module. Download the latest version from http://www.python.org/.\nIt is highly recommended that users install the latest patch version\nof python as these contain many fixes to serious bugs.\n\nSome variants of Linux will need an additional ', ('python dev', u2s(u'\u201cpython dev\u201d')), ' package\ninstalled for Roundup installation to work. Debian and derivatives, are\nknown to require this.\n\nIf you', (u2s(u'\u2019'), ''), 're on windows, you will either need to be using the ActiveState python\ndistribution (at http://www.activestate.com/Products/ActivePython/), or you', (u2s(u'\u2019'), ''), 'll\nhave to install the win32all package separately (get it from\nhttp://starship.python.net/crew/mhammond/win32/).\n\numlaut'] + [b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")] | 1409 text_fragments['dehtml'] = ['Roundup\n Home\nDownload\nDocs\nRoundup Features\nInstalling Roundup\nUpgrading to newer versions of Roundup\nRoundup FAQ\nUser Guide\nCustomising Roundup\nAdministration Guide\nPrerequisites\n\nRoundup requires Python 2.5 or newer (but not Python 3) with a functioning\nanydbm module. Download the latest version from http://www.python.org/.\nIt is highly recommended that users install the latest patch version\nof python as these contain many fixes to serious bugs.\n\nSome variants of Linux will need an additional ', ('python dev', u2s(u'\u201cpython dev\u201d')), ' package\ninstalled for Roundup installation to work. Debian and derivatives, are\nknown to require this.\n\nIf you', (u2s(u'\u2019'), ''), 're on windows, you will either need to be using the ActiveState python\ndistribution (at http://www.activestate.com/Products/ActivePython/), or you', (u2s(u'\u2019'), ''), 'll\nhave to install the win32all package separately (get it from\nhttp://starship.python.net/crew/mhammond/win32/).\n\numlaut'] + [b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")] |
| 1410 text_fragments['beautifulsoup'] = ['Roundup\nHome\nDownload\nDocs\nRoundup Features\nInstalling Roundup\nUpgrading to newer versions of Roundup\nRoundup FAQ\nUser Guide\nCustomising Roundup\nAdministration Guide\nPrerequisites\nRoundup requires Python 2.5 or newer (but not Python 3) with a functioning\nanydbm module. Download the latest version from\nhttp://www.python.org/\n.\nIt is highly recommended that users install the latest patch version\nof python as these contain many fixes to serious bugs.\nSome variants of Linux will need an additional ', ('python dev', u2s(u'\u201cpython dev\u201d')), ' package\ninstalled for Roundup installation to work. Debian and derivatives, are\nknown to require this.\nIf you', (u2s(u'\u2019'), "'"), 're on windows, you will either need to be using the ActiveState python\ndistribution (at\nhttp://www.activestate.com/Products/ActivePython/\n), or you’ll\nhave to install the win32all package separately (get it from\nhttp://starship.python.net/crew/mhammond/win32/\n).\numlaut'] + [b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")] | |
| 1411 | |
| 1394 | 1412 |
| 1395 # \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f | 1413 # \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f |
| 1396 # append above with leading space to end of mycontent. It is the | 1414 # append above with leading space to end of mycontent. It is the |
| 1397 # translated content when =E4=F6=FC=C4=D6=DC=DF is added to the html | 1415 # translated content when =E4=F6=FC=C4=D6=DC=DF is added to the html |
| 1398 # input. | 1416 # input. |
| 1402 messages = self.db.issue.get('1', 'messages') | 1420 messages = self.db.issue.get('1', 'messages') |
| 1403 messages.sort() | 1421 messages.sort() |
| 1404 msg = self.db.msg.getnode(messages[-1]) | 1422 msg = self.db.msg.getnode(messages[-1]) |
| 1405 | 1423 |
| 1406 print(msg.content) | 1424 print(msg.content) |
| 1407 print(text_fragments[converter][0]) | |
| 1408 # html converted to utf-8 text | 1425 # html converted to utf-8 text |
| 1409 self.compareStringFragments(msg.content, | 1426 self.compareStringFragments(msg.content, |
| 1410 text_fragments[converter]) | 1427 text_fragments[converter]) |
| 1411 self.assertEqual(msg.type, None) | 1428 self.assertEqual(msg.type, None) |
| 1412 self.assertEqual(len(msg.files), 2) | 1429 self.assertEqual(len(msg.files), 2) |
| 1416 # with it's utf-8 encoded equivalent so comparison | 1433 # with it's utf-8 encoded equivalent so comparison |
| 1417 # works. | 1434 # works. |
| 1418 content = { 0: "75,23,16,18\n", | 1435 content = { 0: "75,23,16,18\n", |
| 1419 1: self.html_doc.replace(" =E4=F6=FC=C4=D6=DC=DF", | 1436 1: self.html_doc.replace(" =E4=F6=FC=C4=D6=DC=DF", |
| 1420 b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")) } | 1437 b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")) } |
| 1438 email_body = {} | |
| 1439 email_body['dehtml'] = '''Roundup | |
| 1440 Home | |
| 1441 Download | |
| 1442 Docs | |
| 1443 Roundup Features | |
| 1444 Installing Roundup | |
| 1445 Upgrading to newer versions of Roundup | |
| 1446 Roundup FAQ | |
| 1447 User Guide | |
| 1448 Customising Roundup | |
| 1449 Administration Guide | |
| 1450 Prerequisites | |
| 1451 | |
| 1452 Roundup requires Python 2.5 or newer (but not Python 3) with a functioning | |
| 1453 anydbm module. Download the latest version from http://www.python.org/. | |
| 1454 It is highly recommended that users install the latest patch version | |
| 1455 of python as these contain many fixes to serious bugs. | |
| 1456 | |
| 1457 Some variants of Linux will need an additional python dev package | |
| 1458 installed for Roundup installation to work. Debian and derivatives, are | |
| 1459 known to require this. | |
| 1460 | |
| 1461 If youre on windows, you will either need to be using the ActiveState python | |
| 1462 distribution (at http://www.activestate.com/Products/ActivePython/), or youll | |
| 1463 have to install the win32all package separately (get it from | |
| 1464 http://starship.python.net/crew/mhammond/win32/). | |
| 1465 ''' | |
| 1466 email_body['beautifulsoup']='''Roundup | |
| 1467 Home | |
| 1468 Download | |
| 1469 Docs | |
| 1470 Roundup Features | |
| 1471 Installing Roundup | |
| 1472 Upgrading to newer versions of Roundup | |
| 1473 Roundup FAQ | |
| 1474 User Guide | |
| 1475 Customising Roundup | |
| 1476 Administration Guide | |
| 1477 Prerequisites | |
| 1478 Roundup requires Python 2.5 or newer (but not Python 3) with a functioning | |
| 1479 anydbm module. Download the latest version from | |
| 1480 http://www.python.org/ | |
| 1481 . | |
| 1482 It is highly recommended that users install the latest patch version | |
| 1483 of python as these contain many fixes to serious bugs. | |
| 1484 Some variants of Linux will need an additional python dev package | |
| 1485 installed for Roundup installation to work. Debian and derivatives, are | |
| 1486 known to require this. | |
| 1487 If youre on windows, you will either need to be using the ActiveState python | |
| 1488 distribution (at | |
| 1489 http://www.activestate.com/Products/ActivePython/ | |
| 1490 ), or youll | |
| 1491 have to install the win32all package separately (get it from | |
| 1492 http://starship.python.net/crew/mhammond/win32/ | |
| 1493 ).''' | |
| 1494 | |
| 1421 for n, id in enumerate (msg.files): | 1495 for n, id in enumerate (msg.files): |
| 1422 f = self.db.file.getnode (id) | 1496 f = self.db.file.getnode (id) |
| 1423 self.assertEqual(f.name, name) | 1497 self.assertEqual(f.name, name) |
| 1424 self.assertEqual(f.type, types[n]) | 1498 self.assertEqual(f.type, types[n]) |
| 1425 self.assertEqual(f.content, content[n]) | 1499 self.assertEqual(f.content, content[n]) |
| 1456 Content-Transfer-Encoding: quoted-printable | 1530 Content-Transfer-Encoding: quoted-printable |
| 1457 | 1531 |
| 1458 | 1532 |
| 1459 Contrary, Mary <mary@test.test> added the comment: | 1533 Contrary, Mary <mary@test.test> added the comment: |
| 1460 | 1534 |
| 1461 Roundup | 1535 ''' + email_body[converter] + |
| 1462 Home | 1536 ''' |
| 1463 Download | |
| 1464 Docs | |
| 1465 Roundup Features | |
| 1466 Installing Roundup | |
| 1467 Upgrading to newer versions of Roundup | |
| 1468 Roundup FAQ | |
| 1469 User Guide | |
| 1470 Customising Roundup | |
| 1471 Administration Guide | |
| 1472 Prerequisites | |
| 1473 | |
| 1474 Roundup requires Python 2.5 or newer (but not Python 3) with a functioning | |
| 1475 anydbm module. Download the latest version from http://www.python.org/. | |
| 1476 It is highly recommended that users install the latest patch version | |
| 1477 of python as these contain many fixes to serious bugs. | |
| 1478 | |
| 1479 Some variants of Linux will need an additional python dev package | |
| 1480 installed for Roundup installation to work. Debian and derivatives, are | |
| 1481 known to require this. | |
| 1482 | |
| 1483 If youre on windows, you will either need to be using the ActiveState python | |
| 1484 distribution (at http://www.activestate.com/Products/ActivePython/), or youll | |
| 1485 have to install the win32all package separately (get it from | |
| 1486 http://starship.python.net/crew/mhammond/win32/). | |
| 1487 | |
| 1488 umlaut =C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F | 1537 umlaut =C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F |
| 1489 | 1538 |
| 1490 ---------- | 1539 ---------- |
| 1491 status: unread -> chatting | 1540 status: unread -> chatting |
| 1492 | 1541 |
