def testConfirmViaForm(self):
        form = EmailChangeForm({'email': '*****@*****.**'}, instance=self.user)
        self.assertTrue(form.is_valid())

        defered = form.save()
        self.assertEquals(len(defered), LONG[1])

        # refetch user-object from db before checking the email,
        # because django objects don't reflect db changes done
        # elsewhere
        user_obj = User.objects.get(username=self.user.username)
        self.assertEquals(user_obj.email, '*****@*****.**')

        # ========================
        # in practice this is the boundary, where code excution will be defered.
        # ========================

        confirm_form = ConfirmationForm({'token': defered})
        self.assertTrue(confirm_form.is_valid())
        obj = confirm_form.save()
        self.assertNotEqual(obj, False)

        # refetch user-object from db before checking the email,
        # because django objects don't reflect db changes done
        # elsewhere
        user_obj = User.objects.get(username=self.user.username)
        self.assertEquals(user_obj.email, '*****@*****.**')
    def testConfirmViaForm(self):
        form = EmailChangeForm({'email': '*****@*****.**'},
                               instance=self.user)
        self.assertTrue(form.is_valid())

        defered = form.save()
        self.assertEquals(len(defered), LONG[1])

        # refetch user-object from db before checking the email,
        # because django objects don't reflect db changes done
        # elsewhere
        user_obj = User.objects.get(username=self.user.username)
        self.assertEquals(user_obj.email, '*****@*****.**')

        # ========================
        # in practice this is the boundary, where code excution will be defered.
        # ========================

        confirm_form = ConfirmationForm({'token': defered})
        self.assertTrue(confirm_form.is_valid())
        obj = confirm_form.save()
        self.assertNotEqual(obj, False)

        # refetch user-object from db before checking the email,
        # because django objects don't reflect db changes done
        # elsewhere
        user_obj = User.objects.get(username=self.user.username)
        self.assertEquals(user_obj.email, '*****@*****.**')
示例#3
0
def confirm_join(request, token):
    """
    This view does basically the same as generic_confirmation.views.confirm_by_get,
    but as it didn't allow enough customizations to be made, the view is partia
    copied here and the behavior customized.
    """
    form = ConfirmationForm({'token': token})
    if form.is_valid() or (settings.DEBUG and request.GET.get("member_id")):
        # ConfirmationForm.save returns either the object
        # or False, if the token was not found in the database (I guess
        # this is a bug, since is_valid() should not return True if token
        # cannot be found)
        #from .models import Member
        #member = Member.objects.get(pk=1)
        if settings.DEBUG and request.GET.get("member_id"):
            member = Member.objects.get(pk=request.GET.get("member_id"))
        else:
            member = form.save()

        if member:
            fields = Member.PUBLIC_FIELDS

            # Pass form in to show the user data that was submitted
            # The invoice shown here is the one that is created in post_save
            context = {"fields": fields,
                       "member": member,
                       # This is safe, since at join there will be only one
                       # invoice anyway
                       "invoice": member.invoices.get(status=Invoice.STATUS.sent)}
            return render(request, "members/confirm_join_success.html", context)

    return render(request, "members/confirm_join_error.html")
示例#4
0
def confirm_email_change(request, token):
    form = ConfirmationForm({'token': token})
    if form.is_valid():
        member = form.save()
        # See confirm_join - this may be buggy behavior
        if member:
            return render(request, "members/confirm_email_success.html",
                    {"member": member})

    return render(request, "members/confirm_email_error.html")
    def testFormPrefix(self):
        """
        Testing the situation when deferred form has prefix. Prefixes also
        should be saved, otherwise form_input will not be accepted when
        save operation will be resumed.

        """
        PREFIX = 'test_prefix'

        model = TestingModel.objects.create(pickle_field='none')

        model_form = TestingModelForm(instance=model, prefix=PREFIX)

        data = {f.html_name: str(f.value() + '-changed') for f in model_form}

        unprefixed_form = TestingModelForm(data, instance=model)
        self.assertFalse(unprefixed_form.is_valid())

        model_form = TestingModelForm(data, instance=model, prefix=PREFIX)
        self.assertTrue(model_form.is_valid())
        self.assertTrue(model_form.has_changed())

        token = model_form.save()

        form = ConfirmationForm({'token': token})
        self.assertTrue(form.is_valid())
        action = DeferredAction.objects.get(token=token)

        resume_form = action.get_resume_form()

        self.assertEqual(
            resume_form.prefix,
            model_form.prefix,
            msg="Resume form has to have the same prefix as initial form")

        model = TestingModel.objects.get(pk=model.pk)
        self.assertEqual(model.pickle_field, 'none')
        form.save()
        model = TestingModel.objects.get(pk=model.pk)
        self.assertEqual(model.pickle_field, 'none-changed')
    def testFormPrefix(self):
        """
        Testing the situation when deferred form has prefix. Prefixes also
        should be saved, otherwise form_input will not be accepted when
        save operation will be resumed.

        """
        PREFIX = 'test_prefix'

        model = TestingModel.objects.create(pickle_field='none')

        model_form = TestingModelForm(instance=model, prefix=PREFIX)

        data = {f.html_name: str(f.value() + '-changed') for f in model_form}

        unprefixed_form = TestingModelForm(data, instance=model)
        self.assertFalse(unprefixed_form.is_valid())

        model_form = TestingModelForm(data, instance=model, prefix=PREFIX)
        self.assertTrue(model_form.is_valid())
        self.assertTrue(model_form.has_changed())

        token = model_form.save()

        form = ConfirmationForm({'token': token})
        self.assertTrue(form.is_valid())
        action = DeferredAction.objects.get(token=token)

        resume_form = action.get_resume_form()

        self.assertEqual(
            resume_form.prefix, model_form.prefix,
            msg="Resume form has to have the same prefix as initial form")

        model = TestingModel.objects.get(pk=model.pk)
        self.assertEqual(model.pickle_field, 'none')
        form.save()
        model = TestingModel.objects.get(pk=model.pk)
        self.assertEqual(model.pickle_field, 'none-changed')
 def testConfirmBogusViaForm(self):
     confirm_form = ConfirmationForm({'token': 'some-bogus-token-2'})
     self.assertFalse(confirm_form.is_valid())
 def testConfirmBogusViaForm(self):
     confirm_form = ConfirmationForm({'token': 'some-bogus-token-2'})
     self.assertFalse(confirm_form.is_valid())