Beispiel #1
0
    def test_form2(self):
        view = TestView(context=self.root, request=self.request)
        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.settings["mail"] = None
        form.Setup(subset="create")
        self.request.GET = {}
        self.request.POST = {
            "name": "testuser",
            "email": "*****@*****.**",
            "password": "******",
            "password-confirm": "12345"
        }
        r, v = form.AddUser("action", redirectSuccess="")
        self.assert_(r)

        # UpdatePass -----------------------------------------------------------------------------------------------------

        view = TestView(context=self.root, request=self.request)
        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="updatepass")
        self.request.POST = {
            "oldpassword": "******",
            "password": "******",
            "password-confirm": "67890"
        }
        self.request.GET = {}
        r, v = form.UpdatePass("action", redirectSuccess="")
        self.assertFalse(r)

        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="updatepass")
        self.request.POST = {
            "oldpassword": "******",
            "password": "******",
            "password-confirm": "67890"
        }
        self.request.GET = {}
        r, v = form.UpdatePass("action", redirectSuccess="")
        self.assert_(r)

        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="updatepass")
        self.request.POST = {
            "oldpassword": "******",
            "password": "******",
            "password-confirm": "12345"
        }
        self.request.GET = {}
        r, v = form.UpdatePass("action", redirectSuccess="")
        self.assert_(r)

        # UpdateMail -----------------------------------------------------------------------------------------------------

        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="updatemail1")
        self.request.POST = {"newmail": "testuser"}
        self.request.GET = {}
        r, v = form.UpdateMail("action", redirectSuccess="")
        self.assertFalse(r)

        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="updatemail1")
        self.request.POST = {"newmail": "*****@*****.**"}
        self.request.GET = {}
        r, v = form.UpdateMail("action", redirectSuccess="", url="")
        self.assertFalse(r)

        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="updatemail1")
        self.request.POST = {"newmail": "*****@*****.**"}
        self.request.GET = {}
        form.UpdateMail("action", redirectSuccess="", url="")
        m = self.root.LookupUser(name="testuser",
                                 reloadFromDB=1).data.tempcache
        self.assert_(m == "verifymail:[email protected]", m)

        # UpdateMailToken -----------------------------------------------------------------------------------------------------

        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="updatemail1")
        self.request.GET = {"token": "000"}
        r, v = form.UpdateMailToken("action", redirectSuccess="")
        self.assertFalse(r)

        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="updatemail2")
        self.request.GET = {
            "token":
            self.root.LookupUser(name="testuser", reloadFromDB=1).data.token
        }
        form.UpdateMailToken("action", redirectSuccess="")
        self.assert_(
            self.root.GetUser("testuser").data.email == "*****@*****.**")

        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="updatemail2")
        self.request.POST = {
            "token":
            self.root.LookupUser(name="testuser", reloadFromDB=1).data.token
        }
        self.request.GET = {}
        r, v = form.UpdateMailToken("action", redirectSuccess="")
        self.assertFalse(r)

        # ResetPass -----------------------------------------------------------------------------------------------------

        view = BaseView(context=self.root, request=self.request)
        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="resetpass")
        self.request.POST = {"email": "*****@*****.**"}
        self.request.GET = {}
        form.ResetPass("action", redirectSuccess="")

        # Contact -----------------------------------------------------------------------------------------------------

        view = BaseView(context=self.root, request=self.request)
        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="contact")
        self.request.POST = {
            "receiver":
            str(self.root.LookupUser(name="testuser", reloadFromDB=1))
        }
        self.request.GET = {}
        form.Contact("action", redirectSuccess="")
Beispiel #2
0
    def test_form(self):
        view = TestView(context=self.root, request=self.request)
        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.settings["mail"] = None
        form.Setup(subset="create")
        self.request.GET = {}
        self.request.POST = {
            "name": "testuser",
            "email": "*****@*****.**"
        }

        r, v = form.AddUser("action", redirectSuccess="")
        self.assertFalse(r)

        self.request.POST = {
            "name": "",
            "email": "*****@*****.**",
            "password": "******",
            "password-confirm": "12345"
        }
        r, v = form.AddUser("action", redirectSuccess="")
        self.assertFalse(r)

        self.request.POST = {
            "name": "testuser",
            "email": "*****@*****.**",
            "password": "******",
            "password-confirm": "12345"
        }
        r, v = form.AddUser("action", redirectSuccess="")
        self.assert_(r)

        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="edit")
        self.request.POST = {
            "surname": "12345",
            "password": "******",
            "password-confirm": "12345"
        }
        self.request.GET = {}

        r, v = form.LoadUser("action", redirectSuccess="")
        self.assert_(r)
        r, v = form.Update("action", redirectSuccess="")
        self.assert_(r, v)
        self.request.POST = {
            "name": "testuser123",
            "email": "*****@*****.**",
            "surname": "12345",
            "password": "******"
        }
        r, v = form.Update("action", redirectSuccess="")
        self.assertFalse(r)

        view = BaseView(context=self.root, request=self.request)
        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="login")
        self.request.POST = {"name": "testuser", "password": "******"}
        self.request.GET = {}
        r, v = form.Login("action", redirectSuccess="")
        self.assert_(r)

        # activate -----------------------------------------------------------------------------------------------------
        u = self.root.LookupUser(name="testuser", reloadFromDB=1)
        u.meta["pool_state"] = 0
        u.data["token"] = "1111111111"
        u.Commit(user=u)

        view = BaseView(context=self.root, request=self.request)
        form = UserForm(loadFromType="user",
                        context=self.root,
                        request=self.request,
                        view=view,
                        app=self.app)
        form.Setup(subset="activate")
        form.method = u"GET"
        self.request.POST = {}
        self.request.GET = {"token": "aaaa"}
        r, v = form.Activate("action", redirectSuccess="")
        self.assertFalse(r)

        self.request.GET = {"token": "1111111111"}
        r, v = form.Activate("action", redirectSuccess="")
        self.assert_(r)
        u = self.root.LookupUser(name="testuser", reloadFromDB=1)
        self.assert_(u.meta["pool_state"])
        self.assertFalse(u.data["token"])