comparison test/test_mailgw.py @ 7064:3359dc1dabb0

Add OAuth authentication to the mailgw script Now IMAPS can be used with OAuth as required by several large cloud providers. Move command line processing of the mailgw script to ``argparse``. Note that the command line options of the mailgw have changed, see upgrading.txt for details.
author Ralf Schlatterbeck <rsc@runtux.com>
date Wed, 23 Nov 2022 10:13:48 +0100
parents bd2c3b2010c3
children 27c2d7295ba2
comparison
equal deleted inserted replaced
7063:aca710a3b687 7064:3359dc1dabb0
36 reason="Skipping beautifulsoup tests: 'bs4' not installed")) 36 reason="Skipping beautifulsoup tests: 'bs4' not installed"))
37 37
38 38
39 from roundup.anypy.email_ import message_from_bytes 39 from roundup.anypy.email_ import message_from_bytes
40 from roundup.anypy.strings import b2s, u2s, s2b 40 from roundup.anypy.strings import b2s, u2s, s2b
41 from roundup.scripts.roundup_mailgw import parse_arguments
41 42
42 if 'SENDMAILDEBUG' not in os.environ: 43 if 'SENDMAILDEBUG' not in os.environ:
43 os.environ['SENDMAILDEBUG'] = 'mail-test.log' 44 os.environ['SENDMAILDEBUG'] = 'mail-test.log'
44 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] 45 SENDMAILDEBUG = os.environ['SENDMAILDEBUG']
45 46
240 self.db.security.getPermission('Create', 'issue'), 241 self.db.security.getPermission('Create', 'issue'),
241 self.db.security.getPermission('Create', 'msg'), 242 self.db.security.getPermission('Create', 'msg'),
242 ] 243 ]
243 self.db.security.role['anonymous'].permissions = p 244 self.db.security.role['anonymous'].permissions = p
244 245
245 def _create_mailgw(self, message, args=()): 246 def _create_mailgw(self, message, args=[]):
246 class MailGW(self.instance.MailGW): 247 class MailGW(self.instance.MailGW):
247 """call _handle_message as handle_message 248 """call _handle_message as handle_message
248 the real handle_message reopens the database, and destroys 249 the real handle_message reopens the database, and destroys
249 the db that we supply as part of the test. 250 the db that we supply as part of the test.
250 """ 251 """
251 def handle_message(self, message): 252 def handle_message(self, message):
252 return self._handle_message(message) 253 return self._handle_message(message)
253 handler = MailGW(self.instance, args) 254 cmd, parsed_args = parse_arguments (args)
255 handler = MailGW(self.instance, parsed_args)
254 handler.db = self.db 256 handler.db = self.db
255 return handler 257 return handler
256 258
257 def _handle_mail(self, message, args=(), trap_exc=0): 259 def _handle_mail(self, message, args=[], trap_exc=0):
258 handler = self._create_mailgw(message, args) 260 handler = self._create_mailgw(message, args)
259 handler.trapExceptions = trap_exc 261 handler.trapExceptions = trap_exc
260 return handler.main(io.BytesIO(s2b(message))) 262 return handler.main(io.BytesIO(s2b(message)))
261 263
262 def _get_mail(self): 264 def _get_mail(self):
442 Message-Id: <dummy_test_message_id> 444 Message-Id: <dummy_test_message_id>
443 Reply-To: chef@bork.bork.bork 445 Reply-To: chef@bork.bork.bork
444 Subject: [issue] Testing... 446 Subject: [issue] Testing...
445 447
446 Hi there! 448 Hi there!
447 ''', (('-C', 'issue'), ('-S', 'status=chatting;priority=critical'))) 449 ''', ('-S', 'issue.status=chatting;priority=critical'))
448 self.assertEqual(self.db.issue.get(nodeid, 'status'), '3') 450 self.assertEqual(self.db.issue.get(nodeid, 'status'), '3')
449 self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1') 451 self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1')
450 452
451 def testOptionsMulti(self): 453 def testOptionsMulti(self):
452 nodeid = self._handle_mail('''Content-Type: text/plain; 454 nodeid = self._handle_mail('''Content-Type: text/plain;
456 Message-Id: <dummy_test_message_id> 458 Message-Id: <dummy_test_message_id>
457 Reply-To: chef@bork.bork.bork 459 Reply-To: chef@bork.bork.bork
458 Subject: [issue] Testing... 460 Subject: [issue] Testing...
459 461
460 Hi there! 462 Hi there!
461 ''', (('-C', 'issue'), ('-S', 'status=chatting'), ('-S', 'priority=critical'))) 463 ''', ('-S', 'issue.status=chatting', '-S', 'issue.priority=critical'))
462 self.assertEqual(self.db.issue.get(nodeid, 'status'), '3') 464 self.assertEqual(self.db.issue.get(nodeid, 'status'), '3')
463 self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1') 465 self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1')
464 466
465 def testOptionClass(self): 467 def testOptionClass(self):
466 nodeid = self._handle_mail('''Content-Type: text/plain; 468 nodeid = self._handle_mail('''Content-Type: text/plain;
470 Message-Id: <dummy_test_message_id> 472 Message-Id: <dummy_test_message_id>
471 Reply-To: chef@bork.bork.bork 473 Reply-To: chef@bork.bork.bork
472 Subject: [issue] Testing... [status=chatting;priority=critical] 474 Subject: [issue] Testing... [status=chatting;priority=critical]
473 475
474 Hi there! 476 Hi there!
475 ''', (('-c', 'issue'),)) 477 ''', ('-c', 'issue'))
476 self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...') 478 self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...')
477 self.assertEqual(self.db.issue.get(nodeid, 'status'), '3') 479 self.assertEqual(self.db.issue.get(nodeid, 'status'), '3')
478 self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1') 480 self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1')
479 481
480 newmsg = '''Content-Type: text/plain; 482 newmsg = '''Content-Type: text/plain;
5036 'This is the text of a signed and encrypted email.') 5038 'This is the text of a signed and encrypted email.')
5037 # check that the message has the right source code 5039 # check that the message has the right source code
5038 l = self.db.msg.get(m, 'tx_Source') 5040 l = self.db.msg.get(m, 'tx_Source')
5039 self.assertEqual(l, 'email-sig-openpgp') 5041 self.assertEqual(l, 'email-sig-openpgp')
5040 5042
5041 # vim: set filetype=python sts=4 sw=4 et si : 5043 # vim: set filetype=python sts=4 sw=4 et :

Roundup Issue Tracker: http://roundup-tracker.org/