~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 08:55:24 UTC
  • Revision ID: aurelien@bompard.org-20131008085524-s3qe3whcwj9os2sr
Some more unicode checks when importing

Show diffs side-by-side

added added

removed removed

Lines of Context:
172
172
        # moderator_password must not be unicode
173
173
        self._pckdict[b"mod_password"] = b'TESTVALUE'
174
174
        self._import()
 
175
        self.assertFalse(isinstance(self._mlist.moderator_password, unicode))
175
176
        self.assertEqual(self._mlist.moderator_password, b'TESTVALUE')
176
177
 
177
178
    def test_newsgroup_moderation(self):
435
436
        # We can't check if it changed from the default
436
437
        # -> don't import, we may do more harm than good and it's easy to
437
438
        # change if needed
438
 
        test_value = "TEST-VALUE"
 
439
        test_value = b"TEST-VALUE"
439
440
        for oldvar, newvar in self._conf_mapping.iteritems():
440
441
            self._mlist.mail_host = "example.com"
441
442
            self._pckdict[b"mail_host"] = b"test.example.com"
446
447
            self.assertEqual(old_value, new_value,
447
448
                    "Default value was not preserved for %s" % newvar)
448
449
 
 
450
    def test_unicode(self):
 
451
        for oldvar in self._conf_mapping:
 
452
            self._pckdict[str(oldvar)] = b"Ol\xe1!"
 
453
        try:
 
454
            import_config_pck(self._mlist, self._pckdict)
 
455
        except UnicodeDecodeError, e:
 
456
            self.fail(e)
 
457
        for oldvar, newvar in self._conf_mapping.iteritems():
 
458
            newattr = getattr(self._mlist, newvar)
 
459
            text = decorate(self._mlist, newattr)
 
460
            expected = u'Ol\ufffd!'.encode("utf-8")
 
461
            # we get bytestrings because the text is stored in a file
 
462
            self.assertEqual(text, expected)
 
463
 
449
464
 
450
465
 
451
466
class TestRosterImport(unittest.TestCase):