Esempio n. 1
0
 def test_email_change_email_complete(self):
     """
     Integration test
     """
     req = RequestFactory().get('/')
     send_email_change_email(req, self.user, "*****@*****.**")
     self.assertEquals(len(mail.outbox), 1)
Esempio n. 2
0
    def test_email_change_email(self):
        """
        Send change email
        """
        self._monkey_sender_called = False

        def monkey_sender(request, subject, template_name, context, email):
            self.assertEqual(request, req)
            self.assertEqual(email, [self.user.email, ])

            change_token = UserEmailChangeTokenGenerator()
            token = change_token.generate(self.user, new_email)
            self.assertDictEqual(context, {'token': token, })

            self.assertEqual(subject, _("Email change"))
            self.assertEqual(template_name, 'spirit/user/email_change_email.html')

            self._monkey_sender_called = True

        req = RequestFactory().get('/')
        new_email = "*****@*****.**"

        org_sender, email.sender = email.sender, monkey_sender
        try:
            send_email_change_email(req, self.user, new_email)
            self.assertTrue(self._monkey_sender_called)
        finally:
            email.sender = org_sender
Esempio n. 3
0
 def test_email_change_email_complete(self):
     """
     Integration test
     """
     req = RequestFactory().get('/')
     send_email_change_email(req, self.user, "*****@*****.**")
     self.assertEquals(len(mail.outbox), 1)
Esempio n. 4
0
    def test_email_change_email(self):
        """
        Send change email
        """
        self._monkey_sender_called = False

        def monkey_sender(request, subject, template_name, context, email):
            self.assertEqual(request, req)
            self.assertEqual(email, [
                self.user.email,
            ])

            change_token = UserEmailChangeTokenGenerator()
            token = change_token.generate(self.user, new_email)
            self.assertDictEqual(context, {
                'token': token,
            })

            self.assertEqual(subject, _("Email change"))
            self.assertEqual(template_name,
                             'spirit/user/email_change_email.html')

            self._monkey_sender_called = True

        req = RequestFactory().get('/')
        new_email = "*****@*****.**"

        org_sender, email.sender = email.sender, monkey_sender
        try:
            send_email_change_email(req, self.user, new_email)
            self.assertTrue(self._monkey_sender_called)
        finally:
            email.sender = org_sender
Esempio n. 5
0
def profile_email_change(request):
    if request.method == 'POST':
        form = EmailChangeForm(user=request.user, data=request.POST)

        if form.is_valid():
            send_email_change_email(request, request.user, form.get_email())
            messages.info(request, _("We have sent you an email so you can confirm the change!"))
            return redirect(reverse('spirit:profile-update'))
    else:
        form = EmailChangeForm()

    return render(request, 'spirit/user/profile_email_change.html', {'form': form, })
Esempio n. 6
0
def profile_email_change(request):
    if request.method == 'POST':
        form = EmailChangeForm(user=request.user, data=request.POST)

        if form.is_valid():
            send_email_change_email(request, request.user, form.get_email())
            messages.info(request, _("We have sent you an email so you can confirm the change!"))
            return redirect(reverse('spirit:profile-update'))
    else:
        form = EmailChangeForm()

    return render(request, 'spirit/user/profile_email_change.html', {'form': form, })