comparison test/test_mailgw.py @ 6672:01216187a167

Testing translations in mailgw.py, update translations, i18n improved i18n.py: translation objects get a _file which is the file that catalog was loaded from. Useful for debugging. mailgw.py: fix code to include roundup.i18n and invoke propert method. GNUMakefile: added roundup.pot target. Also building roundup.pot sets the release version and product code in roundup.pot. Release version from roundup.__init__.py. merged roundup.pot changes into all *.po files. Not sure if the version info in the headers of the .po files is supposed to be updated to match roundup.pot or not. test_mailgw.py: test cases for en and de translations tested. Not sure why I neede to set roundupdb._ and mailgw._, but followed setUp method code and it worked.
author John Rouillard <rouilj@ieee.org>
date Wed, 11 May 2022 21:20:34 -0400
parents 0ef688717613
children 567283742a5c
comparison
equal deleted inserted replaced
6671:8e834d29e0e1 6672:01216187a167
3752 Reply-To: chef@bork.bork.bork 3752 Reply-To: chef@bork.bork.bork
3753 Message-Id: <dummy_test_message_id> 3753 Message-Id: <dummy_test_message_id>
3754 3754
3755 ''') 3755 ''')
3756 3756
3757
3758 def testNoSubjectErrorTranslation(self):
3759 """ Use message with no subject to trigger an error """
3760 message = '''Content-Type: text/plain;
3761 charset="iso-8859-1"
3762 From: Chef <chef@bork.bork.bork>
3763 To: issue_tracker@your.tracker.email.domain.example
3764 Message-Id: <dummy_test_message_id_2>
3765
3766 Just a test reply
3767 '''
3768 print(self.db.config.MAILGW_LANGUAGE, self.db.config.TRACKER_LANGUAGE)
3769 # verify proper value when no translation
3770 self.db.config.MAILGW_LANGUAGE = 'en'
3771 self.db.config.TRACKER_LANGUAGE = 'en'
3772 print(self.db.config.MAILGW_LANGUAGE, self.db.config.TRACKER_LANGUAGE)
3773
3774 ### copied from mailgw.py handle_message()
3775 language = self.instance.config["MAILGW_LANGUAGE"] or self.instance.config["TRACKER_LANGUAGE"]
3776 # use . as tracker home to get .mo files from top level
3777 # locale directory.
3778 self.assertEqual('en', language)
3779 print(i18n.DOMAIN)
3780
3781 self.db.i18n = i18n.get_translation(language,
3782 self.instance.config['TRACKER_HOME'])
3783
3784 _ = self.db.i18n.gettext
3785 roundupdb._ = mailgw._ = _
3786
3787 self.db.tx_Source = "email"
3788 ### end copy
3789
3790 # insert translation string
3791 self.db.i18n._catalog['\nEmails to Roundup trackers must include a Subject: line!\n'] = 'me me me'
3792
3793 with self.assertRaises(MailUsageError) as ctx:
3794 self._handle_mail(message)
3795
3796 self.assertEqual(str(ctx.exception), "me me me")
3797
3798
3799 def testNoSubjectErrorTranslationDe(self):
3800 """ Use message with no subject to trigger an error get output in
3801 German. """
3802
3803 message = '''Content-Type: text/plain;
3804 charset="iso-8859-1"
3805 From: Chef <chef@bork.bork.bork>
3806 To: issue_tracker@your.tracker.email.domain.example
3807 Message-Id: <dummy_test_message_id_2>
3808
3809 Just a test reply
3810 '''
3811 print(self.db.config.MAILGW_LANGUAGE, self.db.config.TRACKER_LANGUAGE)
3812 # verify proper value when no translation
3813 self.db.config.MAILGW_LANGUAGE = 'de'
3814 self.db.config.TRACKER_LANGUAGE = 'de'
3815 print(self.db.config.MAILGW_LANGUAGE, self.db.config.TRACKER_LANGUAGE)
3816
3817 ### copied from mailgw.py handle_message()
3818 language = self.instance.config["MAILGW_LANGUAGE"] or self.instance.config["TRACKER_LANGUAGE"]
3819 # use . as tracker home to get .mo files from top level
3820 # locale directory.
3821 self.assertEqual('de', language)
3822 print(i18n.DOMAIN)
3823
3824 self.db.i18n = i18n.get_translation(language,
3825 self.instance.config['TRACKER_HOME'])
3826
3827 _ = self.db.i18n.gettext
3828 roundupdb._ = mailgw._ = _
3829
3830 self.db.tx_Source = "email"
3831 ### end copy
3832
3833 de_translation = "\nMails an Roundup müssen eine Subject-Zeile haben (Betreff)!\n"
3834
3835 with self.assertRaises(MailUsageError) as ctx:
3836 self._handle_mail(message)
3837
3838 self.assertEqual(str(ctx.exception), de_translation)
3839
3757 # 3840 #
3758 # TEST FOR INVALID DESIGNATOR HANDLING 3841 # TEST FOR INVALID DESIGNATOR HANDLING
3759 # 3842 #
3760 def testInvalidDesignator(self): 3843 def testInvalidDesignator(self):
3761 self.assertRaises(MailUsageError, self._handle_mail, 3844 self.assertRaises(MailUsageError, self._handle_mail,

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