changeset 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 ff8845ca305e
files roundup/mailgw.py test/test_mailgw.py
diffstat 2 files changed, 75 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/roundup/mailgw.py	Wed May 11 21:20:34 2022 -0400
+++ b/roundup/mailgw.py	Thu May 12 14:50:50 2022 -0400
@@ -1600,6 +1600,12 @@
         ''' message - a Message instance
 
         Parse the message as per the module docstring.
+
+        WARNING: any changes in this code need to be moved to all
+        *Translate* test cases in test/test_mailgw.py. This method
+        can't be tested directly because it opens the instance
+        erasing the database mocked by the test harness.
+        
         '''
         # get database handle for handling one email
         self.db = self.instance.open('admin')
--- a/test/test_mailgw.py	Wed May 11 21:20:34 2022 -0400
+++ b/test/test_mailgw.py	Thu May 12 14:50:50 2022 -0400
@@ -3782,6 +3782,7 @@
                         self.instance.config['TRACKER_HOME'])
 
         _ = self.db.i18n.gettext
+        old_translate_ = mailgw._
         roundupdb._ = mailgw._ = _
 
         self.db.tx_Source = "email"
@@ -3795,6 +3796,7 @@
 
         self.assertEqual(str(ctx.exception), "me me me")
 
+        roundupdb._ = mailgw._ = old_translate_
 
     def testNoSubjectErrorTranslationDe(self):
         """ Use message with no subject to trigger an error get output in
@@ -3825,6 +3827,7 @@
                         self.instance.config['TRACKER_HOME'])
 
         _ = self.db.i18n.gettext
+        old_translate_ = mailgw._
         roundupdb._ = mailgw._ = _
 
         self.db.tx_Source = "email"
@@ -3837,6 +3840,72 @@
 
         self.assertEqual(str(ctx.exception), de_translation)
 
+        roundupdb._ = mailgw._ = old_translate_
+
+    def testNoIssueClassErrorTranslationDe(self):
+        """ Use message with a non-existant issue designator
+            to trigger an error get output in German. """
+
+        message = '''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: Chef <chef@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <dummy_test_message_id_2>
+Subject: [issue9999999] this is a nonexistant issue
+
+Just a test reply
+'''
+        print(self.db.config.MAILGW_LANGUAGE, self.db.config.TRACKER_LANGUAGE)
+        # verify proper value when no translation
+        self.db.config.MAILGW_LANGUAGE = 'de'
+        self.db.config.TRACKER_LANGUAGE = 'de'
+        print(self.db.config.MAILGW_LANGUAGE, self.db.config.TRACKER_LANGUAGE)
+
+        ### copied from mailgw.py handle_message()
+        language = self.instance.config["MAILGW_LANGUAGE"] or self.instance.config["TRACKER_LANGUAGE"]
+        # use . as tracker home to get .mo files from top level
+        # locale directory.
+        self.assertEqual('de', language)
+        print(i18n.DOMAIN)
+
+        self.db.i18n = i18n.get_translation(language,
+                        self.instance.config['TRACKER_HOME'])
+
+        _ = self.db.i18n.gettext
+        old_translate_ = mailgw._
+        roundupdb._ = mailgw._ = _
+
+        self.db.tx_Source = "email"
+        ### end copy
+
+        de_translation = "Der in der Betreffzeile Ihre Nachricht bezeichnete Eintrag"
+
+        with self.assertRaises(MailUsageError) as ctx:
+            self._handle_mail(message)
+
+        self.assertIn(de_translation, str(ctx.exception))
+
+        de_translation = """Der Betreff muss einen Klassennamen oder Bezeichner enthalten, um
+anzuzeigen, worum es geht. Zum Beispiel:
+"""
+        with self.assertRaises(MailUsageError) as ctx:
+            self._handle_mail(
+            '''Content-Type: text/plain;
+  charset="iso-8859-1"
+From: Chef <chef@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
+Subject: [frobulated] testing
+Cc: richard@test.test
+Reply-To: chef@bork.bork.bork
+Message-Id: <dummy_test_message_id>
+
+''')
+
+        self.assertIn(de_translation, str(ctx.exception))
+
+
+        roundupdb._ = mailgw._ = old_translate_
+
     #
     # TEST FOR INVALID DESIGNATOR HANDLING
     #

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