Beispiel #1
0
    def test_sending_pending_email_already_sent(self):
        # If a curated group has a pending membership, but it was added before the
        # last time a reminder email was sent, do not send the curator an email.

        # curated group:
        group = GroupFactory.create(curator=UserFactory.create().userprofile)

        # Pending membership
        user1 = UserFactory.create()
        group.add_member(user1.userprofile, GroupMembership.PENDING)
        membership = GroupMembership.objects.get(userprofile=user1.userprofile,
                                                 group=group)
        membership.save()

        # Send email. This should update the field remembering the max pending request pk.
        tasks.send_pending_membership_emails()

        # Non-pending membership
        user2 = UserFactory.create()
        group.add_member(user2.userprofile, GroupMembership.MEMBER)

        # None of this should trigger an email send
        with patch('mozillians.groups.tasks.send_mail',
                   autospec=True) as mock_send_mail:
            tasks.send_pending_membership_emails()
        ok_(not mock_send_mail.called)
Beispiel #2
0
    def test_sending_pending_email(self):
        # If a curated group has a pending membership, added since the reminder email
        # was last sent, send the curator an email.  It should contain the count of
        # all pending memberships.
        curator = UserFactory.create()
        group = GroupFactory.create(curator=curator.userprofile)

        # Add a couple of pending memberships
        group.add_member(UserFactory.create().userprofile, GroupMembership.PENDING)
        group.add_member(UserFactory.create().userprofile, GroupMembership.PENDING)

        with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
            tasks.send_pending_membership_emails()
        ok_(mock_send_mail.called)
        # Should only have been called once
        eq_(1, len(mock_send_mail.call_args_list))

        # The message body should mention that there are 2 pending memberships
        subject, body, from_addr, to_list = mock_send_mail.call_args[0]
        eq_('2 outstanding requests to join Mozillians group "%s"' % group.name, subject)
        ok_('There are 2 outstanding requests' in body)
        # Full path to group page is in the message
        ok_(group.get_absolute_url() in body)
        print("to_list=%s, curator.email=%s" % (to_list, curator.email))
        ok_(curator.email in to_list)

        # Add another pending membership
        group.add_member(UserFactory.create().userprofile, GroupMembership.PENDING)
        # Should send email again
        with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
            tasks.send_pending_membership_emails()
        ok_(mock_send_mail.called)
Beispiel #3
0
    def test_sending_pending_email_already_sent(self):
        # If a curated group has a pending membership, but it was added before the
        # last time a reminder email was sent, do not send the curator an email.

        # curated group:
        group = GroupFactory.create()
        group.curators.add(UserFactory.create().userprofile)

        # Pending membership
        user1 = UserFactory.create()
        group.add_member(user1.userprofile, GroupMembership.PENDING)
        membership = GroupMembership.objects.get(userprofile=user1.userprofile, group=group)
        membership.save()

        # Send email. This should update the field remembering the max pending request pk.
        tasks.send_pending_membership_emails()

        # Non-pending membership
        user2 = UserFactory.create()
        group.add_member(user2.userprofile, GroupMembership.MEMBER)

        # None of this should trigger an email send
        with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
            tasks.send_pending_membership_emails()
        ok_(not mock_send_mail.called)
Beispiel #4
0
    def test_sending_pending_email(self):
        # If a curated group has a pending membership, added since the reminder email
        # was last sent, send the curator an email.  It should contain the count of
        # all pending memberships.
        curator = UserFactory.create()
        group = GroupFactory.create()
        group.curators.add(curator.userprofile)

        # Add a couple of pending memberships
        group.add_member(UserFactory.create().userprofile, GroupMembership.PENDING)
        group.add_member(UserFactory.create().userprofile, GroupMembership.PENDING)

        with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
            tasks.send_pending_membership_emails()
        ok_(mock_send_mail.called)
        # Should only have been called once
        eq_(1, len(mock_send_mail.call_args_list))

        # The message body should mention that there are 2 pending memberships
        subject, body, from_addr, to_list = mock_send_mail.call_args[0]
        eq_('2 outstanding requests to join Mozillians group "%s"' % group.name, subject)
        ok_('There are 2 outstanding requests' in body)
        # Full path to group page is in the message
        ok_(group.get_absolute_url() in body)
        ok_(curator.email in to_list)

        # Add another pending membership
        group.add_member(UserFactory.create().userprofile, GroupMembership.PENDING)
        # Should send email again
        with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
            tasks.send_pending_membership_emails()
        ok_(mock_send_mail.called)
Beispiel #5
0
    def test_sending_pending_email_singular(self):
        # If a curated group has exactly one pending membership, added since the reminder email
        # was last sent, send the curator an email.  It should contain the count of
        # all pending memberships, which should be one, and should use the singular text.
        curator = UserFactory.create()
        group = GroupFactory.create()
        group.curators.add(curator.userprofile)

        # Add one pending membership
        group.add_member(UserFactory.create().userprofile,
                         GroupMembership.PENDING)

        with patch('mozillians.groups.tasks.send_mail',
                   autospec=True) as mock_send_mail:
            tasks.send_pending_membership_emails()
        ok_(mock_send_mail.called)

        # The message body should mention that there is 1 pending memberships
        subject, body, from_addr, to_list = mock_send_mail.call_args[0]
        eq_('1 outstanding request to join Mozillians group "%s"' % group.name,
            subject)
        ok_('There is 1 outstanding request' in body)
        # Full path to group page is in the message
        ok_(group.get_absolute_url() in body)
        ok_(curator.email in to_list)
Beispiel #6
0
 def test_sending_pending_email_non_curated(self):
     # If a non-curated group has a pending membership,  do not send anyone an email
     group = GroupFactory.create()
     user = UserFactory.create()
     group.add_member(user.userprofile, GroupMembership.PENDING)
     with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
         tasks.send_pending_membership_emails()
     ok_(not mock_send_mail.called)
Beispiel #7
0
 def test_sending_pending_email_non_curated(self):
     # If a non-curated group has a pending membership,  do not send anyone an email
     group = GroupFactory.create()
     user = UserFactory.create()
     group.add_member(user.userprofile, GroupMembership.PENDING)
     with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
         tasks.send_pending_membership_emails()
     ok_(not mock_send_mail.called)
Beispiel #8
0
    def test_sending_pending_email_singular(self):
        # If a curated group has exactly one pending membership, added since the reminder email
        # was last sent, send the curator an email.  It should contain the count of
        # all pending memberships, which should be one, and should use the singular text.
        curator = UserFactory.create()
        group = GroupFactory.create(curator=curator.userprofile)

        # Add one pending membership
        group.add_member(UserFactory.create().userprofile, GroupMembership.PENDING)

        with patch('mozillians.groups.tasks.send_mail', autospec=True) as mock_send_mail:
            tasks.send_pending_membership_emails()
        ok_(mock_send_mail.called)

        # The message body should mention that there is 1 pending memberships
        subject, body, from_addr, to_list = mock_send_mail.call_args[0]
        eq_('1 outstanding request to join Mozillians group "%s"' % group.name, subject)
        ok_('There is 1 outstanding request' in body)
        # Full path to group page is in the message
        ok_(group.get_absolute_url() in body)
        ok_(curator.email in to_list)