~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-22 13:28:11 UTC
  • mfrom: (7215.2.10 3.0)
  • Revision ID: aurelien@bompard.org-20131022132811-d1utj61rqjm178k9
Merge from the main branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
__metaclass__ = type
23
23
__all__ = [
 
24
    'TestArchiveImport',
24
25
    'TestBasicImport',
25
26
    ]
26
27
 
33
34
 
34
35
from mailman.config import config
35
36
from mailman.app.lifecycle import create_list, remove_list
 
37
from mailman.interfaces.archiver import ArchivePolicy
36
38
from mailman.testing.layers import ConfigLayer
37
39
from mailman.utilities.importer import import_config_pck, Import21Error
38
40
from mailman.interfaces.archiver import ArchivePolicy
298
300
 
299
301
 
300
302
class TestArchiveImport(unittest.TestCase):
301
 
    # The mlist.archive_policy gets set from the old list's archive and
302
 
    # archive_private values
 
303
    """Test conversion of the archive policies.
303
304
 
 
305
    Mailman 2.1 had two variables `archive` and `archive_private`.  Now
 
306
    there's just a single `archive_policy` enum.
 
307
    """
304
308
    layer = ConfigLayer
305
309
 
306
310
    def setUp(self):
315
319
        self.assertEqual(self._mlist.archive_policy, expected)
316
320
 
317
321
    def test_public(self):
318
 
        self._do_test({ "archive": True, "archive_private": False },
 
322
        self._do_test(dict(archive=True, archive_private=False),
319
323
                      ArchivePolicy.public)
320
324
 
321
325
    def test_private(self):
322
 
        self._do_test({ "archive": True, "archive_private": True },
 
326
        self._do_test(dict(archive=True, archive_private=True),
323
327
                      ArchivePolicy.private)
324
328
 
325
329
    def test_no_archive(self):
326
 
        self._do_test({ "archive": False, "archive_private": False },
327
 
                      ArchivePolicy.never)
 
330
        self._do_test(dict(archive=False, archive_private=False),
 
331
                      ArchivePolicy.never)
 
332
 
 
333
    def test_bad_state(self):
 
334
        # For some reason, the old list has the invalid archiving state where
 
335
        # `archive` is False and `archive_private` is True.  It doesn't matter
 
336
        # because this still collapses to the same enum value.
 
337
        self._do_test(dict(archive=False, archive_private=True),
 
338
                      ArchivePolicy.never)
 
339
 
 
340
    def test_missing_archive_key(self):
 
341
        # For some reason, the old list didn't have an `archive` key.  We
 
342
        # treat this as if no archiving is done.
 
343
        self._do_test(dict(archive_private=False), ArchivePolicy.never)
 
344
 
 
345
    def test_missing_archive_key_archive_public(self):
 
346
        # For some reason, the old list didn't have an `archive` key, and it
 
347
        # has weird value for archive_private.  We treat this as if no
 
348
        # archiving is done.
 
349
        self._do_test(dict(archive_private=True), ArchivePolicy.never)
 
350
 
 
351
    def test_missing_archive_private_key(self):
 
352
        # For some reason, the old list was missing an `archive_private` key.
 
353
        # For maximum safety, we treat this as private archiving.
 
354
        self._do_test(dict(archive=True), ArchivePolicy.private)
328
355
 
329
356
 
330
357
 
342
369
        remove_list(self._mlist)
343
370
 
344
371
    def _do_test(self, original, expected):
345
 
        import_config_pck(self._mlist, { "filter_action": original })
 
372
        import_config_pck(self._mlist, dict(filter_action=original))
346
373
        self.assertEqual(self._mlist.filter_action, expected)
347
374
 
348
375
    def test_discard(self):
376
403
        self._mlist = create_list('blank@example.com')
377
404
        self._mlist.default_member_action = DummyEnum.val
378
405
        self._mlist.default_nonmember_action = DummyEnum.val
379
 
        self._pckdict = {
380
 
            b"member_moderation_action": DummyEnum.val,
381
 
            b"generic_nonmember_action": DummyEnum.val,
382
 
        }
 
406
        self._pckdict = dict(
 
407
            member_moderation_action=DummyEnum.val,
 
408
            generic_nonmember_action=DummyEnum.val,
 
409
            )
383
410
 
384
411
    def tearDown(self):
385
412
        remove_list(self._mlist)
391
418
 
392
419
    def test_member_hold(self):
393
420
        self._pckdict[b"member_moderation_action"] = 0
394
 
        self._do_test({"default_member_action": Action.hold})
 
421
        self._do_test(dict(default_member_action=Action.hold))
395
422
 
396
423
    def test_member_reject(self):
397
424
        self._pckdict[b"member_moderation_action"] = 1
398
 
        self._do_test({"default_member_action": Action.reject})
 
425
        self._do_test(dict(default_member_action=Action.reject))
399
426
 
400
427
    def test_member_discard(self):
401
428
        self._pckdict[b"member_moderation_action"] = 2
402
 
        self._do_test({"default_member_action": Action.discard})
 
429
        self._do_test(dict(default_member_action=Action.discard))
403
430
 
404
431
    def test_nonmember_accept(self):
405
432
        self._pckdict[b"generic_nonmember_action"] = 0
406
 
        self._do_test({"default_nonmember_action": Action.accept})
 
433
        self._do_test(dict(default_nonmember_action=Action.accept))
407
434
 
408
435
    def test_nonmember_hold(self):
409
436
        self._pckdict[b"generic_nonmember_action"] = 1
410
 
        self._do_test({"default_nonmember_action": Action.hold})
 
437
        self._do_test(dict(default_nonmember_action=Action.hold))
411
438
 
412
439
    def test_nonmember_reject(self):
413
440
        self._pckdict[b"generic_nonmember_action"] = 2
414
 
        self._do_test({"default_nonmember_action": Action.reject})
 
441
        self._do_test(dict(default_nonmember_action=Action.reject))
415
442
 
416
443
    def test_nonmember_discard(self):
417
444
        self._pckdict[b"generic_nonmember_action"] = 3
418
 
        self._do_test({"default_nonmember_action": Action.discard})
 
445
        self._do_test(dict(default_nonmember_action=Action.discard))
419
446
 
420
447
 
421
448
 
437
464
 
438
465
    def setUp(self):
439
466
        self._mlist = create_list('blank@example.com')
440
 
        self._conf_mapping = {
441
 
            "welcome_msg": "welcome_message_uri",
442
 
            "goodbye_msg": "goodbye_message_uri",
443
 
            "msg_header": "header_uri",
444
 
            "msg_footer": "footer_uri",
445
 
            "digest_header": "digest_header_uri",
446
 
            "digest_footer": "digest_footer_uri",
447
 
        }
448
 
        self._pckdict = {}
 
467
        self._conf_mapping = dict(
 
468
            welcome_msg="welcome_message_uri",
 
469
            goodbye_msg="goodbye_message_uri",
 
470
            msg_header="header_uri",
 
471
            msg_footer="footer_uri",
 
472
            digest_header="digest_header_uri",
 
473
            digest_footer="digest_footer_uri",
 
474
        )
 
475
        self._pckdict = dict()
449
476
        #self._pckdict = {
450
477
        #    "preferred_language": "XX", # templates are lang-specific
451
478
        #}
555
582
    def setUp(self):
556
583
        self._mlist = create_list('blank@example.com')
557
584
        self._pckdict = {
558
 
            b"members": {
559
 
                b"anne@example.com": 0,
560
 
                b"bob@example.com": b"bob@ExampLe.Com",
561
 
            },
562
 
            b"digest_members": {
563
 
                b"cindy@example.com": 0,
564
 
                b"dave@example.com": b"dave@ExampLe.Com",
565
 
            },
566
 
            b"passwords": {
567
 
                b"anne@example.com" : b"annepass",
568
 
                b"bob@example.com"  : b"bobpass",
569
 
                b"cindy@example.com": b"cindypass",
570
 
                b"dave@example.com" : b"davepass",
571
 
            },
572
 
            b"language": {
573
 
                b"anne@example.com" : b"fr",
574
 
                b"bob@example.com"  : b"de",
575
 
                b"cindy@example.com": b"es",
576
 
                b"dave@example.com" : b"it",
577
 
            },
578
 
            b"usernames": { # Usernames are unicode strings in the pickle
579
 
                b"anne@example.com" : "Anne",
580
 
                b"bob@example.com"  : "Bob",
581
 
                b"cindy@example.com": "Cindy",
582
 
                b"dave@example.com" : "Dave",
583
 
            },
584
 
            b"owner": [
585
 
                b"anne@example.com",
586
 
                b"emily@example.com",
 
585
            "members": {
 
586
                "anne@example.com": 0,
 
587
                "bob@example.com": b"bob@ExampLe.Com",
 
588
            },
 
589
            "digest_members": {
 
590
                "cindy@example.com": 0,
 
591
                "dave@example.com": b"dave@ExampLe.Com",
 
592
            },
 
593
            "passwords": {
 
594
                "anne@example.com" : b"annepass",
 
595
                "bob@example.com"  : b"bobpass",
 
596
                "cindy@example.com": b"cindypass",
 
597
                "dave@example.com" : b"davepass",
 
598
            },
 
599
            "language": {
 
600
                "anne@example.com" : b"fr",
 
601
                "bob@example.com"  : b"de",
 
602
                "cindy@example.com": b"es",
 
603
                "dave@example.com" : b"it",
 
604
            },
 
605
            "usernames": { # Usernames are unicode strings in the pickle
 
606
                "anne@example.com" : "Anne",
 
607
                "bob@example.com"  : "Bob",
 
608
                "cindy@example.com": "Cindy",
 
609
                "dave@example.com" : "Dave",
 
610
            },
 
611
            "owner": [
 
612
                "anne@example.com",
 
613
                "emily@example.com",
587
614
            ],
588
 
            b"moderator": [
589
 
                b"bob@example.com",
590
 
                b"fred@example.com",
 
615
            "moderator": [
 
616
                "bob@example.com",
 
617
                "fred@example.com",
591
618
            ],
592
619
        }
593
620
        self._usermanager = getUtility(IUserManager)
594
621
        language_manager = getUtility(ILanguageManager)
595
 
        for code in self._pckdict[b"language"].values():
 
622
        for code in self._pckdict["language"].values():
596
623
            if code not in language_manager.codes:
597
624
                language_manager.add(code, 'utf-8', code)
598
625
 
635
662
                             self._pckdict["language"][addr])
636
663
 
637
664
    def test_new_language(self):
638
 
        self._pckdict[b"language"][b"anne@example.com"] = b'xx_XX'
 
665
        self._pckdict[b"language"]["anne@example.com"] = b'xx_XX'
639
666
        try:
640
667
            import_config_pck(self._mlist, self._pckdict)
641
668
        except Import21Error, e:
704
731
    def test_owner_and_moderator_not_lowercase(self):
705
732
        # In the v2.1 pickled dict, the owner and moderator lists are not
706
733
        # necessarily lowercased already
707
 
        self._pckdict[b"owner"] = [b"Anne@example.com"]
708
 
        self._pckdict[b"moderator"] = [b"Anne@example.com"]
 
734
        self._pckdict["owner"] = [b"Anne@example.com"]
 
735
        self._pckdict["moderator"] = [b"Anne@example.com"]
709
736
        try:
710
737
            import_config_pck(self._mlist, self._pckdict)
711
738
        except AssertionError:
751
778
 
752
779
    def setUp(self):
753
780
        self._mlist = create_list('blank@example.com')
754
 
        self._pckdict = {
755
 
            b"members": { b"anne@example.com": 0 },
756
 
            b"user_options": {},
757
 
            b"delivery_status": {},
758
 
        }
 
781
        self._pckdict = dict(
 
782
            members={ "anne@example.com": 0 },
 
783
            user_options=dict(),
 
784
            delivery_status=dict(),
 
785
        )
759
786
        self._usermanager = getUtility(IUserManager)
760
787
 
761
788
    def tearDown(self):
762
789
        remove_list(self._mlist)
763
790
 
764
791
    def _do_test(self, oldvalue, expected):
765
 
        self._pckdict[b"user_options"][b"anne@example.com"] = oldvalue
 
792
        self._pckdict["user_options"]["anne@example.com"] = oldvalue
766
793
        import_config_pck(self._mlist, self._pckdict)
767
794
        user = self._usermanager.get_user("anne@example.com")
768
795
        self.assertTrue(user is not None, "User was not imported")
781
808
 
782
809
    def test_acknowledge_posts(self):
783
810
        # AcknowledgePosts
784
 
        self._do_test(4, {"acknowledge_posts": True})
 
811
        self._do_test(4, dict(acknowledge_posts=True))
785
812
 
786
813
    def test_hide_address(self):
787
814
        # ConcealSubscription
788
 
        self._do_test(16, {"hide_address": True})
 
815
        self._do_test(16, dict(hide_address=True))
789
816
 
790
817
    def test_receive_own_postings(self):
791
818
        # DontReceiveOwnPosts
792
 
        self._do_test(2, {"receive_own_postings": False})
 
819
        self._do_test(2, dict(receive_own_postings=False))
793
820
 
794
821
    def test_receive_list_copy(self):
795
822
        # DontReceiveDuplicates
796
 
        self._do_test(256, {"receive_list_copy": False})
 
823
        self._do_test(256, dict(receive_list_copy=False))
797
824
 
798
825
    def test_digest_plain(self):
799
826
        # Digests & DisableMime
800
 
        self._pckdict[b"digest_members"] = self._pckdict[b"members"].copy()
801
 
        self._pckdict[b"members"] = {}
802
 
        self._do_test(8, {"delivery_mode": DeliveryMode.plaintext_digests})
 
827
        self._pckdict["digest_members"] = self._pckdict["members"].copy()
 
828
        self._pckdict["members"] = dict()
 
829
        self._do_test(8, dict(delivery_mode=DeliveryMode.plaintext_digests))
803
830
 
804
831
    def test_digest_mime(self):
805
832
        # Digests & not DisableMime
806
 
        self._pckdict[b"digest_members"] = self._pckdict[b"members"].copy()
807
 
        self._pckdict[b"members"] = {}
808
 
        self._do_test(0, {"delivery_mode": DeliveryMode.mime_digests})
 
833
        self._pckdict["digest_members"] = self._pckdict["members"].copy()
 
834
        self._pckdict["members"] = dict()
 
835
        self._do_test(0, dict(delivery_mode=DeliveryMode.mime_digests))
809
836
 
810
837
    def test_delivery_status(self):
811
838
        # look for the pckdict["delivery_status"] key which will look like
818
845
        for oldval, expected in enumerate((DeliveryStatus.enabled,
819
846
                DeliveryStatus.unknown, DeliveryStatus.by_user,
820
847
                DeliveryStatus.by_moderator, DeliveryStatus.by_bounces)):
821
 
            self._pckdict[b"delivery_status"][b"anne@example.com"] = (oldval, 0)
 
848
            self._pckdict["delivery_status"]["anne@example.com"] = (oldval, 0)
822
849
            import_config_pck(self._mlist, self._pckdict)
823
850
            member = self._mlist.members.get_member("anne@example.com")
824
851
            self.assertTrue(member is not None, "Address was not subscribed")
828
855
    def test_moderate(self):
829
856
        # Option flag Moderate is translated to
830
857
        # member.moderation_action = Action.hold
831
 
        self._do_test(128, {"moderation_action": Action.hold})
 
858
        self._do_test(128, dict(moderation_action=Action.hold))
832
859
 
833
860
    def test_multiple_options(self):
834
861
        # DontReceiveDuplicates & DisableMime & SuppressPasswordReminder
835
862
        self._pckdict[b"digest_members"] = self._pckdict[b"members"].copy()
836
 
        self._pckdict[b"members"] = {}
837
 
        self._do_test(296, {
838
 
                "receive_list_copy": False,
839
 
                "delivery_mode": DeliveryMode.plaintext_digests,
840
 
                })
 
863
        self._pckdict[b"members"] = dict()
 
864
        self._do_test(296, dict(
 
865
                receive_list_copy=False,
 
866
                delivery_mode=DeliveryMode.plaintext_digests,
 
867
                ))