Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 5513:19bd4b413ed6
be more lenient when comparing string results
| author | Christof Meerwald <cmeerw@cmeerw.org> |
|---|---|
| date | Sat, 18 Aug 2018 23:04:22 +0100 |
| parents | 497ab896397d |
| children | 29346d92d80c |
comparison
equal
deleted
inserted
replaced
| 5512:c652849bfc75 | 5513:19bd4b413ed6 |
|---|---|
| 40 parseContent, IgnoreLoop, IgnoreBulk, MailUsageError, MailUsageHelp | 40 parseContent, IgnoreLoop, IgnoreBulk, MailUsageError, MailUsageHelp |
| 41 from roundup import init, instance, password, __version__ | 41 from roundup import init, instance, password, __version__ |
| 42 | 42 |
| 43 #import db_test_base | 43 #import db_test_base |
| 44 from . import memorydb | 44 from . import memorydb |
| 45 from .cmp_helper import StringFragmentCmpHelper | |
| 45 | 46 |
| 46 def expectedFailure(method): | 47 def expectedFailure(method): |
| 47 """ For marking a failing test. | 48 """ For marking a failing test. |
| 48 This will *not* run the test and return success instead. | 49 This will *not* run the test and return success instead. |
| 49 """ | 50 """ |
| 291 assert not os.path.exists(SENDMAILDEBUG) | 292 assert not os.path.exists(SENDMAILDEBUG) |
| 292 self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...') | 293 self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...') |
| 293 self.assertEqual(self.db.issue.get(nodeid, 'tx_Source'), 'email') | 294 self.assertEqual(self.db.issue.get(nodeid, 'tx_Source'), 'email') |
| 294 | 295 |
| 295 | 296 |
| 296 class MailgwTestCase(MailgwTestAbstractBase, unittest.TestCase): | 297 class MailgwTestCase(MailgwTestAbstractBase, StringFragmentCmpHelper, unittest.TestCase): |
| 297 | 298 |
| 298 def testTextHtmlMessage(self): | 299 def testTextHtmlMessage(self): |
| 299 html_message='''Content-Type: text/html; | 300 html_message='''Content-Type: text/html; |
| 300 charset="iso-8859-1" | 301 charset="iso-8859-1" |
| 301 From: Chef <chef@bork.bork.bork> | 302 From: Chef <chef@bork.bork.bork> |
| 349 have to install the win32all package separately (get it from | 350 have to install the win32all package separately (get it from |
| 350 <a class="reference external" href="http://starship.python.net/crew/mhammond/win32/">http://starship.python.net/crew/mhammond/win32/</a>).</p> | 351 <a class="reference external" href="http://starship.python.net/crew/mhammond/win32/">http://starship.python.net/crew/mhammond/win32/</a>).</p> |
| 351 </div> | 352 </div> |
| 352 </body> | 353 </body> |
| 353 ''' | 354 ''' |
| 355 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/).'] | |
| 354 | 356 |
| 355 self.db.config.MAILGW_CONVERT_HTMLTOTEXT = "dehtml" | 357 self.db.config.MAILGW_CONVERT_HTMLTOTEXT = "dehtml" |
| 356 nodeid = self._handle_mail(html_message) | 358 nodeid = self._handle_mail(html_message) |
| 357 assert not os.path.exists(SENDMAILDEBUG) | 359 assert not os.path.exists(SENDMAILDEBUG) |
| 358 msgid = self.db.issue.get(nodeid, 'messages')[0] | 360 msgid = self.db.issue.get(nodeid, 'messages')[0] |
| 359 self.assertEqual(self.db.msg.get(msgid, 'content'), '''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 package\ninstalled for Roundup installation to work. Debian and derivatives, are\nknown to require this.\n\nIf youre on windows, you will either need to be using the ActiveState python\ndistribution (at http://www.activestate.com/Products/ActivePython/), or youll\nhave to install the win32all package separately (get it from\nhttp://starship.python.net/crew/mhammond/win32/).''') | 361 self.compareStringFragments(self.db.msg.get(msgid, 'content'), |
| 362 text_fragments) | |
| 360 | 363 |
| 361 self.db.config.MAILGW_CONVERT_HTMLTOTEXT = "none" | 364 self.db.config.MAILGW_CONVERT_HTMLTOTEXT = "none" |
| 362 self.assertRaises(MailUsageError, self._handle_mail, html_message) | 365 self.assertRaises(MailUsageError, self._handle_mail, html_message) |
| 363 | 366 |
| 364 def testMessageWithFromInIt(self): | 367 def testMessageWithFromInIt(self): |
| 1276 %s | 1279 %s |
| 1277 --001485f339f8f361fb049188dbba-- | 1280 --001485f339f8f361fb049188dbba-- |
| 1278 '''%html_doc | 1281 '''%html_doc |
| 1279 | 1282 |
| 1280 def testMultipartTextifyHTML(self): | 1283 def testMultipartTextifyHTML(self): |
| 1281 mycontent='''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 package\ninstalled for Roundup installation to work. Debian and derivatives, are\nknown to require this.\n\nIf youre on windows, you will either need to be using the ActiveState python\ndistribution (at http://www.activestate.com/Products/ActivePython/), or youll\nhave to install the win32all package separately (get it from\nhttp://starship.python.net/crew/mhammond/win32/).\n\numlaut''' | 1284 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.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'] |
| 1282 | 1285 |
| 1283 # \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f | 1286 # \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f |
| 1284 # append above with leading space to end of mycontent. It is the | 1287 # append above with leading space to end of mycontent. It is the |
| 1285 # translated content when =E4=F6=FC=C4=D6=DC=DF is added to the html | 1288 # translated content when =E4=F6=FC=C4=D6=DC=DF is added to the html |
| 1286 # input. | 1289 # input. |
| 1289 self._handle_mail(self.multipart_msg_notext) | 1292 self._handle_mail(self.multipart_msg_notext) |
| 1290 messages = self.db.issue.get('1', 'messages') | 1293 messages = self.db.issue.get('1', 'messages') |
| 1291 messages.sort() | 1294 messages.sort() |
| 1292 msg = self.db.msg.getnode(messages[-1]) | 1295 msg = self.db.msg.getnode(messages[-1]) |
| 1293 # html converted to utf-8 text | 1296 # html converted to utf-8 text |
| 1294 self.assertEqual(msg.content, mycontent+b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")) | 1297 self.compareStringFragments(msg.content, |
| 1298 text_fragments + [b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")]) | |
| 1295 self.assertEqual(msg.type, None) | 1299 self.assertEqual(msg.type, None) |
| 1296 self.assertEqual(len(msg.files), 2) | 1300 self.assertEqual(len(msg.files), 2) |
| 1297 name = "unnamed" # no name for any files | 1301 name = "unnamed" # no name for any files |
| 1298 types = { 0: "text/csv", 1: "text/html" } | 1302 types = { 0: "text/csv", 1: "text/html" } |
| 1299 # replace quoted printable string at end of html document | 1303 # replace quoted printable string at end of html document |
| 1300 # with it's utf-8 encoded equivalent so comparison | 1304 # with it's utf-8 encoded equivalent so comparison |
| 1301 # works. | 1305 # works. |
| 1302 content = { 0: "75,23,16,18\n", 1: self.html_doc.replace(" =E4=F6=FC=C4=D6=DC=DF",b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f"))} | 1306 content = { 0: "75,23,16,18\n", |
| 1307 1: self.html_doc.replace(" =E4=F6=FC=C4=D6=DC=DF", | |
| 1308 b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")) } | |
| 1303 for n, id in enumerate (msg.files): | 1309 for n, id in enumerate (msg.files): |
| 1304 f = self.db.file.getnode (id) | 1310 f = self.db.file.getnode (id) |
| 1305 self.assertEqual(f.name, name) | 1311 self.assertEqual(f.name, name) |
| 1306 self.assertEqual(f.type, types[n]) | 1312 self.assertEqual(f.type, types[n]) |
| 1307 self.assertEqual(f.content, content[n]) | 1313 self.assertEqual(f.content, content[n]) |
| 1308 | 1314 |
| 1309 self.compareMessages(self._get_mail(), | 1315 self.compareMessages(self._get_mail() |
| 1316 .replace('=E2=80=99', '') | |
| 1317 .replace('=E2=80=9C', '') | |
| 1318 .replace('=E2=80=9D', '') | |
| 1319 .replace('==\n', '===\n\n').replace('=\n', ''), | |
| 1310 '''From roundup-admin@your.tracker.email.domain.example Thu Oct 10 02:42:14 2017 | 1320 '''From roundup-admin@your.tracker.email.domain.example Thu Oct 10 02:42:14 2017 |
| 1311 FROM: roundup-admin@your.tracker.email.domain.example | 1321 FROM: roundup-admin@your.tracker.email.domain.example |
| 1312 TO: chef@bork.bork.bork, richard@test.test | 1322 TO: chef@bork.bork.bork, richard@test.test |
| 1313 Content-Type: multipart/mixed; boundary="===============6077820410007357357==" | 1323 Content-Type: multipart/mixed; boundary="===============6077820410007357357==" |
| 1314 MIME-Version: 1.0 | 1324 MIME-Version: 1.0 |
| 1356 Some variants of Linux will need an additional python dev package | 1366 Some variants of Linux will need an additional python dev package |
| 1357 installed for Roundup installation to work. Debian and derivatives, are | 1367 installed for Roundup installation to work. Debian and derivatives, are |
| 1358 known to require this. | 1368 known to require this. |
| 1359 | 1369 |
| 1360 If youre on windows, you will either need to be using the ActiveState python | 1370 If youre on windows, you will either need to be using the ActiveState python |
| 1361 distribution (at http://www.activestate.com/Products/ActivePython/), or you= | 1371 distribution (at http://www.activestate.com/Products/ActivePython/), or youll |
| 1362 ll | |
| 1363 have to install the win32all package separately (get it from | 1372 have to install the win32all package separately (get it from |
| 1364 http://starship.python.net/crew/mhammond/win32/). | 1373 http://starship.python.net/crew/mhammond/win32/). |
| 1365 | 1374 |
| 1366 umlaut =C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F | 1375 umlaut =C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F |
| 1367 | 1376 |
