Skip to content

Commit a2b82d2

Browse files
committed
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.
1 parent 79e7c6e commit a2b82d2

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

roundup/mailgw.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,12 @@ def handle_message(self, message):
16001600
''' message - a Message instance
16011601
16021602
Parse the message as per the module docstring.
1603+
1604+
WARNING: any changes in this code need to be moved to all
1605+
*Translate* test cases in test/test_mailgw.py. This method
1606+
can't be tested directly because it opens the instance
1607+
erasing the database mocked by the test harness.
1608+
16031609
'''
16041610
# get database handle for handling one email
16051611
self.db = self.instance.open('admin')

test/test_mailgw.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3782,6 +3782,7 @@ def testNoSubjectErrorTranslation(self):
37823782
self.instance.config['TRACKER_HOME'])
37833783

37843784
_ = self.db.i18n.gettext
3785+
old_translate_ = mailgw._
37853786
roundupdb._ = mailgw._ = _
37863787

37873788
self.db.tx_Source = "email"
@@ -3795,6 +3796,7 @@ def testNoSubjectErrorTranslation(self):
37953796

37963797
self.assertEqual(str(ctx.exception), "me me me")
37973798

3799+
roundupdb._ = mailgw._ = old_translate_
37983800

37993801
def testNoSubjectErrorTranslationDe(self):
38003802
""" Use message with no subject to trigger an error get output in
@@ -3825,6 +3827,7 @@ def testNoSubjectErrorTranslationDe(self):
38253827
self.instance.config['TRACKER_HOME'])
38263828

38273829
_ = self.db.i18n.gettext
3830+
old_translate_ = mailgw._
38283831
roundupdb._ = mailgw._ = _
38293832

38303833
self.db.tx_Source = "email"
@@ -3837,6 +3840,72 @@ def testNoSubjectErrorTranslationDe(self):
38373840

38383841
self.assertEqual(str(ctx.exception), de_translation)
38393842

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 <[email protected]>
3852+
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 <[email protected]>
3896+
3897+
Subject: [frobulated] testing
3898+
3899+
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_
3908+
38403909
#
38413910
# TEST FOR INVALID DESIGNATOR HANDLING
38423911
#

0 commit comments

Comments
 (0)