~abompard/mailman/import21

« back to all changes in this revision

Viewing changes to src/mailman/utilities/tests/test_import.py

  • Committer: Aurélien Bompard
  • Date: 2013-10-08 13:45:36 UTC
  • Revision ID: aurelien@bompard.org-20131008134536-nv8r7t2b38mrt1rw
Make sure the imported preferred_language exists, and work around Python issue 9666

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
from mailman.app.lifecycle import create_list, remove_list
33
33
from mailman.testing.layers import ConfigLayer
34
 
from mailman.utilities.importer import import_config_pck
 
34
from mailman.utilities.importer import import_config_pck, Import21Error
35
35
from mailman.interfaces.archiver import ArchivePolicy
36
36
from mailman.interfaces.action import Action, FilterAction
37
37
from mailman.interfaces.bounce import UnrecognizedBounceDisposition
226
226
                         unicode(self._pckdict[b"info"], "ascii", "replace"),
227
227
                         "We don't fall back to replacing non-ascii chars")
228
228
 
 
229
    def test_preferred_language(self):
 
230
        self._pckdict[b"preferred_language"] = b'ja'
 
231
        english = getUtility(ILanguageManager).get('en')
 
232
        japanese = getUtility(ILanguageManager).get('ja')
 
233
        self.assertEqual(self._mlist.preferred_language, english)
 
234
        self._import()
 
235
        self.assertEqual(self._mlist.preferred_language, japanese)
 
236
 
 
237
    def test_preferred_language_unknown_previous(self):
 
238
        # when the previous language is unknown, it should not fail
 
239
        self._mlist._preferred_language = 'xx' # non-existant
 
240
        self._import()
 
241
        english = getUtility(ILanguageManager).get('en')
 
242
        self.assertEqual(self._mlist.preferred_language, english)
 
243
 
 
244
    def test_new_language(self):
 
245
        self._pckdict[b"preferred_language"] = b'xx_XX'
 
246
        try:
 
247
            self._import()
 
248
        except Import21Error, e:
 
249
            # check the message
 
250
            self.assertTrue("xx_XX" in str(e))
 
251
            self.assertTrue("[language.xx]" in str(e))
 
252
        else:
 
253
            self.fail("Import21Error was not raised")
 
254
 
229
255
 
230
256
 
231
257
class TestArchiveImport(unittest.TestCase):
549
575
            self.assertEqual(member.preferred_language.code,
550
576
                             self._pckdict["language"][addr])
551
577
 
 
578
    def test_new_language(self):
 
579
        self._pckdict[b"language"][b"anne@example.com"] = b'xx_XX'
 
580
        try:
 
581
            import_config_pck(self._mlist, self._pckdict)
 
582
        except Import21Error, e:
 
583
            # check the message
 
584
            self.assertTrue("xx_XX" in str(e))
 
585
            self.assertTrue("[language.xx]" in str(e))
 
586
        else:
 
587
            self.fail("Import21Error was not raised")
 
588
 
552
589
    def test_username(self):
553
590
        import_config_pck(self._mlist, self._pckdict)
554
591
        for name in ("anne", "bob", "cindy", "dave"):