Пример #1
0
 def test_confim_token_twice(self):
     # Don't try to confirm the same token twice.
     # We test this by passing a result that already confirms the same
     # token and it doesn't try to look at the database.
     result = Results()
     result.confirms = self._token
     status = self._command.process(self._mlist, Message(), {},
                                    (self._token, ), result)
     self.assertEqual(status, ContinueProcessing.no)
 def test_join_bad_argument_no_equal(self):
     # Try to subscribe a member with a bad argument via join.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     self._command.process(self._mlist, msg, {}, ('digest', ), results)
     self.assertIn('bad argument: digest', str(results))
 def test_join_posting_address(self):
     # Try to subscribe the list posting address.
     msg = Message()
     msg['From'] = self._mlist.posting_address
     results = Results()
     self._command.process(self._mlist, msg, {}, (), results)
     self.assertEqual(
         str(results).splitlines()[-1], 'List posting address not allowed')
 def test_join_digest(self):
     # Subscribe a member to digest via join.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     self._command.process(self._mlist, msg, {}, ('digest=mime', ), results)
     self.assertIn('Confirmation email sent to [email protected]',
                   str(results))
Пример #5
0
 def test_no_welcome_message(self):
     # When configured not to send a welcome message, none is sent.
     self._mlist.send_welcome_message = False
     status = self._command.process(self._mlist, Message(), {},
                                    (self._token, ), Results())
     self.assertEqual(status, ContinueProcessing.yes)
     # There will be no messages in the queue.
     get_queue_messages('virgin', expected_count=0)
 def test_join_other_bogus(self):
     # Try to subscribe a bogus different address via join.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     self._command.process(self._mlist, msg, {}, ('address=bogus', ),
                           results)
     self.assertIn('Invalid email address: bogus', str(results))
 def test_join_other(self):
     # Subscribe a different address via join.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     self._command.process(self._mlist, msg, {},
                           ('[email protected]', ), results)
     self.assertIn('Confirmation email sent to [email protected]',
                   str(results))
 def test_member_visible_roster_owner(self):
     self._mlist.member_roster_visibility = RosterVisibility.members
     # An owner should be able to get a member visible roster.
     msg = Message()
     msg['From'] = self._owner.address.email
     results = Results()
     ret = self._command.process(self._mlist, msg, {}, (), results)
     self.assertIs(ContinueProcessing.yes, ret)
     self.assertEqual(self._expected, results._output.getvalue())
 def test_non_public_roster(self):
     self._mlist.member_roster_visibility = RosterVisibility.members
     # An unknown address should not be able to get a non-public roster.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     ret = self._command.process(self._mlist, msg, {}, (), results)
     self.assertIs(ContinueProcessing.no, ret)
     self.assertEqual(self._noperm, results._output.getvalue())
 def test_moderator_visible_roster_nonmember(self):
     self._mlist.member_roster_visibility = RosterVisibility.moderators
     # An unknown address can't get a moderator visible roster.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     ret = self._command.process(self._mlist, msg, {}, (), results)
     self.assertIs(ContinueProcessing.no, ret)
     self.assertEqual(self._noperm, results._output.getvalue())
 def test_moderator_visible_roster(self):
     self._mlist.member_roster_visibility = RosterVisibility.moderators
     # A member should not be able to get a moderator visible roster.
     msg = Message()
     msg['From'] = self._member.address.email
     results = Results()
     ret = self._command.process(self._mlist, msg, {}, (), results)
     self.assertIs(ContinueProcessing.no, ret)
     self.assertEqual(self._noperm, results._output.getvalue())
Пример #12
0
    def test_confirm_leave(self):
        msg = mfs("""\
From: Anne Person <*****@*****.**>
To: test-confirm+{token}@example.com
Subject: Re: confirm {token}

""".format(token=self._token))
        Confirm().process(self._mlist, msg, {}, (self._token, ), Results())
        # Anne is no longer a member of the mailing list.
        member = self._mlist.members.get_member('*****@*****.**')
        self.assertIsNone(member)
Пример #13
0
    def test_no_such_command(self):
        # Error message when asking for help on an existent command.
        results = Results()
        status = self._help.process(self._mlist, Message(), {},
                                    ('doesnotexist',), results)
        self.assertEqual(status, ContinueProcessing.no)
        self.assertEqual(str(results), """\
The results of your email command are provided below.

help: no such command: doesnotexist
""")
Пример #14
0
    def test_too_many_arguments(self):
        # Error message when too many help arguments are given.
        results = Results()
        status = self._help.process(self._mlist, Message(), {},
                                    ('more', 'than', 'one'),
                                    results)
        self.assertEqual(status, ContinueProcessing.no)
        self.assertEqual(str(results), """\
The results of your email command are provided below.

help: too many arguments: more than one
""")
 def test_confirm_banned_address(self):
     # Confirmation of a banned address should return an appropriate error.
     IBanManager(self._mlist).ban('*****@*****.**')
     result = Results()
     status = self._command.process(self._mlist, Message(), {},
                                    (self._token, ), result)
     self.assertEqual(status, ContinueProcessing.no)
     # Anne will not be subscribed.
     self.assertFalse(self._mlist.is_subscribed('*****@*****.**'))
     # The result will contain an error message.
     self.assertIn(
         '[email protected] is not allowed to subscribe to '
         '*****@*****.**', str(result))
Пример #16
0
 def test_welcome_message(self):
     # A confirmation causes a welcome message to be sent to the member, if
     # enabled by the mailing list.
     status = self._command.process(self._mlist, Message(), {},
                                    (self._token, ), Results())
     self.assertEqual(status, ContinueProcessing.yes)
     # There should be one messages in the queue; the welcome message.
     items = get_queue_messages('virgin', expected_count=1)
     # Grab the welcome message.
     welcome = items[0].msg
     self.assertEqual(welcome['subject'],
                      'Welcome to the "Test" mailing list')
     self.assertEqual(welcome['to'], 'Anne Person <*****@*****.**>')
 def test_join_banned(self):
     # Try to subscribe someone who is banned.  Anne is a real
     # user, with a validated address, but she is not a member of the
     # mailing list and is banned from joining.
     # Add anne to the ban list.
     IBanManager(self._mlist).ban('*****@*****.**')
     # Then initiate a subscription.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     self._command.process(self._mlist, msg, {}, (), results)
     self.assertEqual(
         str(results).splitlines()[-1],
         '[email protected] is not allowed to subscribe to [email protected]')
 def test_confirm_leave_not_a_member(self):
     self._mlist.unsubscription_policy = SubscriptionPolicy.confirm
     # Try to unsubscribe someone who is not a member.  Anne is a real
     # user, with a validated address, but she is not a member of the
     # mailing list.
     anne = getUtility(IUserManager).create_user('*****@*****.**')
     set_preferred(anne)
     # Initiate an unsubscription.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     self._command.process(self._mlist, msg, {}, (), results)
     self.assertEqual(
         str(results).splitlines()[-1],
         'leave: [email protected] is not a member of [email protected]')
    def test_args_mode_yes(self):
        self._mlist.member_roster_visibility = RosterVisibility.moderators
        # Test mode=digest.
        msg = Message()
        msg['From'] = self._moderator.address.email
        results = Results()
        args = ['mode=digest']
        ret = self._command.process(self._mlist, msg, {}, args, results)
        self.assertIs(ContinueProcessing.yes, ret)
        self.assertEqual(
            results._output.getvalue(), """\
The results of your email command are provided below.

Members of the [email protected] mailing list:
    Elly Person <*****@*****.**>
""")
    def test_args_mode_bogus(self):
        self._mlist.member_roster_visibility = RosterVisibility.moderators
        # Test mode=bogus.
        msg = Message()
        msg['From'] = self._moderator.address.email
        results = Results()
        args = ['mode=bogus']
        ret = self._command.process(self._mlist, msg, {}, args, results)
        self.assertIs(ContinueProcessing.no, ret)
        self.assertEqual(
            results._output.getvalue(), """\
The results of your email command are provided below.

Unrecognized or invalid argument(s):
mode=bogus
""")
 def test_join_pending(self):
     self._mlist.subscription_policy = SubscriptionPolicy.confirm
     # Try to subscribe someone who already has a subscription pending.
     # Anne is a real user, with a validated address, who already has a
     # pending subscription for this mailing list.
     anne = getUtility(IUserManager).create_user('*****@*****.**')
     set_preferred(anne)
     # Initiate a subscription.
     ISubscriptionManager(self._mlist).register(anne)
     # And try to subscribe.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     self._command.process(self._mlist, msg, {}, (), results)
     self.assertEqual(
         str(results).splitlines()[-1],
         '[email protected] has a pending subscription for [email protected]')
    def test_confirm_leave_moderate(self):
        msg = mfs("""\
From: Anne Person <*****@*****.**>
To: test-confirm+{token}@example.com
Subject: Re: confirm {token}

""".format(token=self._token))
        self._mlist.unsubscription_policy = (
            SubscriptionPolicy.confirm_then_moderate)
        # Clear any previously queued confirmation messages.
        get_queue_messages('virgin')
        Confirm().process(self._mlist, msg, {}, (self._token, ), Results())
        # Anne is still a member of the mailing list.
        member = self._mlist.members.get_member('*****@*****.**')
        self.assertIsNotNone(member)
        # There should be a notice to the list owners
        item = get_queue_messages('virgin', expected_count=1)[0]
        self.assertEqual(item.msg['to'], '*****@*****.**')
 def test_join_rfc2047_display(self):
     # Subscribe a member with RFC 2047 encoded display name via join.
     msg = Message()
     msg['From'] = '=?utf-8?q?Anne?= <*****@*****.**>'
     results = Results()
     self._command.process(self._mlist, msg, {}, (), results)
     self.assertIn('Confirmation email sent to Anne <*****@*****.**>',
                   str(results))
     # Check the pending confirmation.
     pendings = list(
         getUtility(IPendings).find(self._mlist,
                                    'subscription',
                                    confirm=False))
     self.assertEqual(1, len(pendings))
     token = pendings[0][0]
     pended = getUtility(IPendings).confirm(token, expunge=False)
     self.assertEqual('Anne', pended['display_name'])
     self.assertEqual('*****@*****.**', pended['email'])
    def test_args_mode_no(self):
        self._mlist.member_roster_visibility = RosterVisibility.moderators
        # Test mode=regular.
        msg = Message()
        msg['From'] = self._moderator.address.email
        results = Results()
        args = ['mode=regular']
        ret = self._command.process(self._mlist, msg, {}, args, results)
        self.assertIs(ContinueProcessing.yes, ret)
        self.assertEqual(
            results._output.getvalue(), """\
The results of your email command are provided below.

Members of the [email protected] mailing list:
    Anne Person <*****@*****.**>
    Bart Person <*****@*****.**>
    Cate Person <*****@*****.**>
    Doug Person <*****@*****.**>
    Fred Person <*****@*****.**>
""")
 def test_join_already_a_member(self):
     # Try to subscribe someone who is already a member.  Anne is a real
     # user, with a validated address, but she is not a member of the
     # mailing list yet.
     anne = getUtility(IUserManager).create_user('*****@*****.**')
     set_preferred(anne)
     # First subscribe anne.
     ISubscriptionManager(self._mlist).register(anne,
                                                pre_verified=True,
                                                pre_confirmed=True,
                                                pre_approved=True)
     # Then initiate a subscription.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     self._command.process(self._mlist, msg, {}, (), results)
     self.assertEqual(
         str(results).splitlines()[-1],
         '[email protected] is already a MemberRole.member of '
         'mailing list [email protected]')