def test_user_can_verify(self):
        user = UserFactory()
        verification = VerificationFactory(user=user)
        form = ConfirmEmailForm(
            user=user,
            token=verification.token,
            data={"token": verification.token},
        )

        assert form.is_valid()
    def test_user_can_verify(self):
        call_command("check_permissions")
        user = UserenaSignup.objects.create_user(
            "userena", "*****@*****.**", "testpassword", active=True
        )
        verification = VerificationFactory(user=user)
        form = ConfirmEmailForm(
            user=user,
            token=verification.token,
            data={"token": verification.token},
        )

        assert form.is_valid()
    def test_user_can_not_verify_other_token(self):
        u1 = UserFactory()
        v1 = VerificationFactory(user=u1)

        u2 = UserFactory()
        VerificationFactory(user=u2)

        form = ConfirmEmailForm(
            user=u2,
            token=v1.token,
            data={"token": v1.token},
        )

        assert not form.is_valid()
        assert ["Token is invalid"] == form.errors["token"]
    def test_user_can_not_verify_other_token(self):
        call_command("check_permissions")
        u1 = UserenaSignup.objects.create_user(
            "userena", "*****@*****.**", "testpassword", active=True
        )
        v1 = VerificationFactory(user=u1)

        u2 = UserenaSignup.objects.create_user(
            "userena2", "*****@*****.**", "testpassword", active=True
        )
        VerificationFactory(user=u2)

        form = ConfirmEmailForm(
            user=u2, token=v1.token, data={"token": v1.token},
        )

        assert not form.is_valid()
        assert ["Token is invalid"] == form.errors["token"]
Пример #5
0
    def test_user_can_not_verify_other_token(self, settings):
        settings.task_eager_propagates = (True, )
        settings.task_always_eager = (True, )

        u1 = UserFactory()
        v1 = VerificationFactory(user=u1)

        u2 = UserFactory()

        form = ConfirmEmailForm(user=u2,
                                token=v1.token,
                                data={"token": v1.token})

        assert not form.is_valid()
        assert ["Token is invalid"] == form.errors["token"]

        u1.refresh_from_db()
        u2.refresh_from_db()
        v1.refresh_from_db()

        assert u1.is_active is True
        assert u2.is_active is False
        assert v1.is_verified is None