Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 6673:567283742a5c
Add more translation tests for mailgw.py
Verify error in German for [issue999999] and [frobulated] in subject
line. The issue doesn't exist and the class doesn't exist.
Also add warning to mailgw.py for mailgw.py::handle_message that any
chnags to that method need to be replicated for all Translate tests in
test_mailgw.py since it can't be tested directly as it destroys the
mock used for the database by the test harness.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 12 May 2022 14:50:50 -0400 |
| parents | 01216187a167 |
| children | 68f7acd67298 |
comparison
equal
deleted
inserted
replaced
| 6672:01216187a167 | 6673:567283742a5c |
|---|---|
| 3780 | 3780 |
| 3781 self.db.i18n = i18n.get_translation(language, | 3781 self.db.i18n = i18n.get_translation(language, |
| 3782 self.instance.config['TRACKER_HOME']) | 3782 self.instance.config['TRACKER_HOME']) |
| 3783 | 3783 |
| 3784 _ = self.db.i18n.gettext | 3784 _ = self.db.i18n.gettext |
| 3785 old_translate_ = mailgw._ | |
| 3785 roundupdb._ = mailgw._ = _ | 3786 roundupdb._ = mailgw._ = _ |
| 3786 | 3787 |
| 3787 self.db.tx_Source = "email" | 3788 self.db.tx_Source = "email" |
| 3788 ### end copy | 3789 ### end copy |
| 3789 | 3790 |
| 3793 with self.assertRaises(MailUsageError) as ctx: | 3794 with self.assertRaises(MailUsageError) as ctx: |
| 3794 self._handle_mail(message) | 3795 self._handle_mail(message) |
| 3795 | 3796 |
| 3796 self.assertEqual(str(ctx.exception), "me me me") | 3797 self.assertEqual(str(ctx.exception), "me me me") |
| 3797 | 3798 |
| 3799 roundupdb._ = mailgw._ = old_translate_ | |
| 3798 | 3800 |
| 3799 def testNoSubjectErrorTranslationDe(self): | 3801 def testNoSubjectErrorTranslationDe(self): |
| 3800 """ Use message with no subject to trigger an error get output in | 3802 """ Use message with no subject to trigger an error get output in |
| 3801 German. """ | 3803 German. """ |
| 3802 | 3804 |
| 3823 | 3825 |
| 3824 self.db.i18n = i18n.get_translation(language, | 3826 self.db.i18n = i18n.get_translation(language, |
| 3825 self.instance.config['TRACKER_HOME']) | 3827 self.instance.config['TRACKER_HOME']) |
| 3826 | 3828 |
| 3827 _ = self.db.i18n.gettext | 3829 _ = self.db.i18n.gettext |
| 3830 old_translate_ = mailgw._ | |
| 3828 roundupdb._ = mailgw._ = _ | 3831 roundupdb._ = mailgw._ = _ |
| 3829 | 3832 |
| 3830 self.db.tx_Source = "email" | 3833 self.db.tx_Source = "email" |
| 3831 ### end copy | 3834 ### end copy |
| 3832 | 3835 |
| 3834 | 3837 |
| 3835 with self.assertRaises(MailUsageError) as ctx: | 3838 with self.assertRaises(MailUsageError) as ctx: |
| 3836 self._handle_mail(message) | 3839 self._handle_mail(message) |
| 3837 | 3840 |
| 3838 self.assertEqual(str(ctx.exception), de_translation) | 3841 self.assertEqual(str(ctx.exception), de_translation) |
| 3842 | |
| 3843 roundupdb._ = mailgw._ = old_translate_ | |
| 3844 | |
| 3845 def testNoIssueClassErrorTranslationDe(self): | |
| 3846 """ Use message with a non-existant issue designator | |
| 3847 to trigger an error get output in German. """ | |
| 3848 | |
| 3849 message = '''Content-Type: text/plain; | |
| 3850 charset="iso-8859-1" | |
| 3851 From: Chef <chef@bork.bork.bork> | |
| 3852 To: issue_tracker@your.tracker.email.domain.example | |
| 3853 Message-Id: <dummy_test_message_id_2> | |
| 3854 Subject: [issue9999999] this is a nonexistant issue | |
| 3855 | |
| 3856 Just a test reply | |
| 3857 ''' | |
| 3858 print(self.db.config.MAILGW_LANGUAGE, self.db.config.TRACKER_LANGUAGE) | |
| 3859 # verify proper value when no translation | |
| 3860 self.db.config.MAILGW_LANGUAGE = 'de' | |
| 3861 self.db.config.TRACKER_LANGUAGE = 'de' | |
| 3862 print(self.db.config.MAILGW_LANGUAGE, self.db.config.TRACKER_LANGUAGE) | |
| 3863 | |
| 3864 ### copied from mailgw.py handle_message() | |
| 3865 language = self.instance.config["MAILGW_LANGUAGE"] or self.instance.config["TRACKER_LANGUAGE"] | |
| 3866 # use . as tracker home to get .mo files from top level | |
| 3867 # locale directory. | |
| 3868 self.assertEqual('de', language) | |
| 3869 print(i18n.DOMAIN) | |
| 3870 | |
| 3871 self.db.i18n = i18n.get_translation(language, | |
| 3872 self.instance.config['TRACKER_HOME']) | |
| 3873 | |
| 3874 _ = self.db.i18n.gettext | |
| 3875 old_translate_ = mailgw._ | |
| 3876 roundupdb._ = mailgw._ = _ | |
| 3877 | |
| 3878 self.db.tx_Source = "email" | |
| 3879 ### end copy | |
| 3880 | |
| 3881 de_translation = "Der in der Betreffzeile Ihre Nachricht bezeichnete Eintrag" | |
| 3882 | |
| 3883 with self.assertRaises(MailUsageError) as ctx: | |
| 3884 self._handle_mail(message) | |
| 3885 | |
| 3886 self.assertIn(de_translation, str(ctx.exception)) | |
| 3887 | |
| 3888 de_translation = """Der Betreff muss einen Klassennamen oder Bezeichner enthalten, um | |
| 3889 anzuzeigen, worum es geht. Zum Beispiel: | |
| 3890 """ | |
| 3891 with self.assertRaises(MailUsageError) as ctx: | |
| 3892 self._handle_mail( | |
| 3893 '''Content-Type: text/plain; | |
| 3894 charset="iso-8859-1" | |
| 3895 From: Chef <chef@bork.bork.bork> | |
| 3896 To: issue_tracker@your.tracker.email.domain.example | |
| 3897 Subject: [frobulated] testing | |
| 3898 Cc: richard@test.test | |
| 3899 Reply-To: chef@bork.bork.bork | |
| 3900 Message-Id: <dummy_test_message_id> | |
| 3901 | |
| 3902 ''') | |
| 3903 | |
| 3904 self.assertIn(de_translation, str(ctx.exception)) | |
| 3905 | |
| 3906 | |
| 3907 roundupdb._ = mailgw._ = old_translate_ | |
| 3839 | 3908 |
| 3840 # | 3909 # |
| 3841 # TEST FOR INVALID DESIGNATOR HANDLING | 3910 # TEST FOR INVALID DESIGNATOR HANDLING |
| 3842 # | 3911 # |
| 3843 def testInvalidDesignator(self): | 3912 def testInvalidDesignator(self): |
