def test_unchanged_email_form(self): user = create_user(email=self.old_email) form = EmailChangeForm(user=user, data={'email': user.email}) if form.is_valid(): form.save() # Refresh the user object. user = User.objects.get(pk=user.pk) # Check that a confirmation was not sent, since the email hasn't been changed. self.assertEqual(EmailConfirmation.objects.all().count(), 0)
def test_form(self): user = create_user(email=self.old_email) form = EmailChangeForm(user=user, data={'email': self.new_email}) if form.is_valid(): form.save() # Refresh the user object. user = User.objects.get(pk=user.pk) # Check that a confirmation was sent. self.assertEqual(EmailConfirmation.objects.all().count(), 1) self.assertNotEqual(user.email, self.new_email)
def ChangeEmail(request): email = User.objects.get(username = request.user) if request.method == 'POST': form = EmailChangeForm(request.POST, instance=email) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('Yaas_user_home')) else: form = EmailChangeForm(instance=request.user) return render_to_response('change_Email.html', {'form' : form }, context_instance=RequestContext(request))