예제 #1
0
    def test_send_renewal_notification_inviters_email(self, mock_now, mock_send_mail):
        """Test renewal notification functionality for curators"""
        curator1 = UserFactory.create(email='*****@*****.**')
        curator2 = UserFactory.create(email='*****@*****.**')
        curator3 = UserFactory.create(email='*****@*****.**')
        member = UserFactory.create(userprofile={'full_name': 'Example Name'})
        group = GroupFactory.create(name='foobar', invalidation_days=365,
                                    accepting_new_members=Group.CLOSED)

        group.curators.add(curator1.userprofile)
        group.curators.add(curator2.userprofile)
        group.curators.add(curator3.userprofile)
        group.add_member(member.userprofile)

        InviteFactory.create(inviter=curator3.userprofile, redeemer=member.userprofile,
                             group=group)

        datetime_now = now() + timedelta(days=351)
        mock_now.return_value = datetime_now

        notify_membership_renewal()

        ok_(mock_send_mail.called)
        eq_(2, len(mock_send_mail.mock_calls))

        # Check email for inviter
        name, args, kwargs = mock_send_mail.mock_calls[1]
        subject, body, from_addr, to_list = args
        eq_(subject, '[Mozillians][foobar] Membership of "Example Name" is about to expire')
        eq_(from_addr, settings.FROM_NOREPLY)
        eq_(list(to_list), [u'*****@*****.**'])
    def test_send_renewal_notification_inviter_not_curator(
            self, mock_now, mock_send_mail):
        """Test renewal notification functionality for curators"""
        curator1 = UserFactory.create(email='*****@*****.**')
        curator2 = UserFactory.create(email='*****@*****.**')
        inviter = UserFactory.create(email='*****@*****.**')
        member = UserFactory.create(userprofile={'full_name': 'Example Name'})
        group = GroupFactory.create(name='foobar',
                                    invalidation_days=365,
                                    accepting_new_members=Group.CLOSED)

        group.curators.add(curator1.userprofile)
        group.curators.add(curator2.userprofile)
        group.add_member(member.userprofile)

        InviteFactory.create(inviter=inviter.userprofile,
                             redeemer=member.userprofile,
                             group=group)

        datetime_now = now() + timedelta(days=351)
        mock_now.return_value = datetime_now

        notify_membership_renewal()

        ok_(mock_send_mail.called)
        eq_(3, len(mock_send_mail.mock_calls))

        # Check email to mozillians
        name, args, kwargs = mock_send_mail.mock_calls[0]
        subject, body, from_addr, to_list = args
        eq_(
            subject,
            '[Mozillians] Your membership to Mozilla group "foobar" is about to expire'
        )
        eq_(from_addr, settings.FROM_NOREPLY)
        eq_(to_list, [member.userprofile.email])

        # Check email for curator1
        name, args, kwargs = mock_send_mail.mock_calls[1]
        subject, body, from_addr, to_list = args
        eq_(
            subject,
            '[Mozillians][foobar] Membership of "Example Name" is about to expire'
        )
        eq_(from_addr, settings.FROM_NOREPLY)
        eq_(list(to_list), [u'*****@*****.**'])

        # Check email for curator2
        name, args, kwargs = mock_send_mail.mock_calls[2]
        subject, body, from_addr, to_list = args
        eq_(
            subject,
            '[Mozillians][foobar] Membership of "Example Name" is about to expire'
        )
        eq_(from_addr, settings.FROM_NOREPLY)
        eq_(list(to_list), [u'*****@*****.**'])
예제 #3
0
    def test_post_remove_button_removes(self):
        """POST to remove_member view removes member"""
        # Make user 1 the group curator so they can remove users
        self.group.curators.add(self.user_1.userprofile)
        self.group.accepting_new_members = 'by_request'
        self.group.save()
        invite = InviteFactory(group=self.group, redeemer=self.user_2.userprofile,
                               inviter=self.user_1.userprofile)

        group_url = reverse('groups:show_group', prefix='/en-US/', args=[self.group.url])
        next_url = "%s?filtr=members" % group_url
        eq_(self.group.invites.all().count(), 1)

        # We must request the full path, with language, or the
        # LanguageMiddleware will convert the request to GET.
        url = reverse('groups:remove_member', prefix='/en-US/',
                      kwargs=dict(url=self.group.url, user_pk=self.user_2.userprofile.pk))
        with self.login(self.user_1) as client:
            response = client.post(url, data={'next_url': next_url}, follow=True)
        self.assertTemplateNotUsed(response, 'groups/confirm_remove_member.html')
        # make sure filter members is active
        membership_filter_form = response.context['membership_filter_form']
        eq_(membership_filter_form.cleaned_data['filtr'], 'members')
        # Not a member anymore
        ok_(not self.group.has_member(self.user_2.userprofile))
        ok_(not Invite.objects.filter(pk=invite.pk).exists())
예제 #4
0
 def test_send_invitation_rejected_email(self, mock_send_email):
     inviter = UserFactory.create()
     redeemer = UserFactory.create(userprofile={'full_name': u'fôô bar'})
     group = GroupFactory.create(name='Foo')
     template_name = 'groups/email/invite_rejected_email.txt'
     InviteFactory.create(inviter=inviter.userprofile, redeemer=redeemer.userprofile,
                          group=group)
     with patch('mozillians.groups.tasks.get_template', autospec=True) as mock_get_template:
         args = [redeemer.userprofile.pk, inviter.userprofile.pk, group.pk]
         tasks.notify_curators_invitation_rejected(*args)
     args = [u'[Mozillians] fôô bar has rejected your invitation to join group "foo"',
             ANY,
             '*****@*****.**',
             [inviter.userprofile.email]]
     ok_(mock_get_template.called)
     eq_(template_name, mock_get_template.call_args[0][0])
     mock_send_email.assert_called_once_with(*args)
예제 #5
0
    def test_accept_reject_user_not_redeemer(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile, redeemer=redeemer.userprofile)
        user = UserFactory.create()

        with self.login(user) as client:
            url = reverse("groups:accept_reject_invitation", args=[invite.pk, "accept"])
            response = client.get(url, follow=True)
            eq_(response.status_code, 404)
예제 #6
0
 def test_send_invitation_invalid_email(self, mock_send_email):
     inviter, redeemer = UserFactory.create_batch(2)
     group = GroupFactory.create(name='Foo')
     template_name = 'groups/email/invite_invalid_email.txt'
     InviteFactory.create(inviter=inviter.userprofile,
                          redeemer=redeemer.userprofile,
                          group=group)
     with patch('mozillians.groups.tasks.get_template', autospec=True) as mock_get_template:
         tasks.notify_redeemer_invitation_invalid(redeemer.userprofile.pk, group.pk)
     args = [
         '[Mozillians] Invitation to group "foo" is no longer valid',
         ANY,
         '*****@*****.**',
         [redeemer.userprofile.email]
     ]
     ok_(mock_get_template.called)
     eq_(template_name, mock_get_template.call_args[0][0])
     mock_send_email.assert_called_once_with(*args)
예제 #7
0
    def test_send_invitation_email_no_curator_manager(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile, redeemer=redeemer.userprofile)
        user = UserFactory.create()

        with self.login(user) as client:
            url = urlparams(reverse("groups:send_invitation_email", args=[invite.pk]), "invitation")
            response = client.get(url, follow=True)
            eq_(response.status_code, 404)
예제 #8
0
    def test_accept_reject_user_not_redeemer(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile,
                                      redeemer=redeemer.userprofile)
        user = UserFactory.create()

        with self.login(user) as client:
            url = reverse('groups:accept_reject_invitation',
                          args=[invite.pk, 'accept'])
            response = client.get(url, follow=True)
            eq_(response.status_code, 404)
예제 #9
0
    def test_reject_invitation(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile, redeemer=redeemer.userprofile)

        with self.login(redeemer) as client:
            url = reverse("groups:accept_reject_invitation", args=[invite.pk, "reject"])
            response = client.get(url, follow=True)
            eq_(response.status_code, 200)

        invite = Invite.objects.filter(pk=invite.pk)
        ok_(not invite.exists())
예제 #10
0
    def test_send_invitation_email_no_curator_manager(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile,
                                      redeemer=redeemer.userprofile)
        user = UserFactory.create()

        with self.login(user) as client:
            url = urlparams(
                reverse('groups:send_invitation_email', args=[invite.pk]),
                'invitation')
            response = client.get(url, follow=True)
            eq_(response.status_code, 404)
예제 #11
0
    def test_accept_invitation_without_terms(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile, redeemer=redeemer.userprofile)

        with self.login(redeemer) as client:
            url = reverse("groups:accept_reject_invitation", args=[invite.pk, "accept"])
            response = client.get(url, follow=True)
            eq_(response.status_code, 200)

        invite = Invite.objects.get(pk=invite.pk)
        ok_(invite.accepted)
        ok_(invite.group.has_member(redeemer.userprofile))
예제 #12
0
    def test_reject_invitation(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile,
                                      redeemer=redeemer.userprofile)

        with self.login(redeemer) as client:
            url = reverse('groups:accept_reject_invitation',
                          args=[invite.pk, 'reject'])
            response = client.get(url, follow=True)
            eq_(response.status_code, 200)

        invite = Invite.objects.filter(pk=invite.pk)
        ok_(not invite.exists())
예제 #13
0
    def test_accept_invitation_without_terms(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile,
                                      redeemer=redeemer.userprofile)

        with self.login(redeemer) as client:
            url = reverse('groups:accept_reject_invitation',
                          args=[invite.pk, 'accept'])
            response = client.get(url, follow=True)
            eq_(response.status_code, 200)

        invite = Invite.objects.get(pk=invite.pk)
        ok_(invite.accepted)
        ok_(invite.group.has_member(redeemer.userprofile))
예제 #14
0
    def test_send_invitation_email(self, mock_success, mock_notification):
        curator = UserFactory.create()
        redeemer = UserFactory.create(userprofile={"full_name": "Foo Bar"})
        invite = InviteFactory.create(inviter=curator.userprofile, redeemer=redeemer.userprofile)
        invite.group.curators.add(curator.userprofile)

        with self.login(curator) as client:
            url = urlparams(reverse("groups:send_invitation_email", args=[invite.pk]), "invitation")
            response = client.get(url, follow=True)
            eq_(response.status_code, 200)

        mock_notification.delay.assert_called_once_with(invite.pk, "")
        msg = "Invitation to Foo Bar has been sent successfully."
        mock_success.assert_called_once_with(ANY, msg)
예제 #15
0
    def test_send_invitation_email(self, mock_success, mock_notification):
        curator = UserFactory.create()
        redeemer = UserFactory.create(userprofile={'full_name': 'Foo Bar'})
        invite = InviteFactory.create(inviter=curator.userprofile,
                                      redeemer=redeemer.userprofile)
        invite.group.curators.add(curator.userprofile)

        with self.login(curator) as client:
            url = urlparams(
                reverse('groups:send_invitation_email', args=[invite.pk]),
                'invitation')
            response = client.get(url, follow=True)
            eq_(response.status_code, 200)

        mock_notification.delay.assert_called_once_with(invite.pk, '')
        msg = 'Invitation to Foo Bar has been sent successfully.'
        mock_success.assert_called_once_with(ANY, msg)
예제 #16
0
    def test_accept_invitation_with_terms(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile, redeemer=redeemer.userprofile)
        invite.group.terms = "Group Terms"
        invite.group.save()

        with self.login(redeemer) as client:
            url = reverse("groups:accept_reject_invitation", args=[invite.pk, "accept"])
            response = client.get(url, follow=True)
            eq_(response.status_code, 200)

        invite = Invite.objects.get(pk=invite.pk)
        ok_(invite.accepted)
        ok_(
            invite.group.groupmembership_set.filter(
                userprofile=redeemer.userprofile, status=GroupMembership.PENDING_TERMS
            ).exists()
        )
예제 #17
0
    def test_accept_invitation_with_terms(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile,
                                      redeemer=redeemer.userprofile)
        invite.group.terms = 'Group Terms'
        invite.group.save()

        with self.login(redeemer) as client:
            url = reverse('groups:accept_reject_invitation',
                          args=[invite.pk, 'accept'])
            response = client.get(url, follow=True)
            eq_(response.status_code, 200)

        invite = Invite.objects.get(pk=invite.pk)
        ok_(invite.accepted)
        ok_(
            invite.group.groupmembership_set.filter(
                userprofile=redeemer.userprofile,
                status=GroupMembership.PENDING_TERMS).exists())