Exemple #1
0
    def test_json(self, **kw):
        user = UserO(u"test")
        root = self.app.GetRoot()
        obj = root.Create("type1", data1_2, user)
        obj.data["fjson"] = {}
        obj.Commit(user=user)
        self.remove.append(obj.id)
        v = Viewy()

        form = JsonMappingForm(request=Request(),
                               app=self.app,
                               context=obj,
                               view=v)
        form.fields = (
            FieldConf(id="parameter1", datatype="string", size=1000),
            FieldConf(id="parameter2", datatype="string", size=100),
        )
        form.jsonDataField = "fjson"
        form.Setup()

        data = {"parameter1": "True", "parameter2": "test"}
        form.request = data
        form.Process()

        data["edit$"] = 1
        form.request = data
        form.Process()

        self.assert_(obj.data.get("ftext"))
Exemple #2
0
 def test_html3(self, **kw):
     form = HTMLForm(loadFromType="type1",
                     app=self.app,
                     view=self.view,
                     request=Request())
     form.formUrl = "form/url"
     form.cssID = u"upload"
     form.css_class = u"niveform"
     form.subsets = {
         u"test": {
             "fields": [
                 u"ftext",
                 FieldConf(
                     **{
                         "id": "section1",
                         "name": "Section 1",
                         "datatype": "number"
                     })
             ]
         }
     }
     form.Setup(subset=u"test")
     v, d, e = form.Validate(data1_2)
     self.assert_(v, e)
     form.Render(d, msgs=None, errors=None)
Exemple #3
0
 def test_form(self, **kw):
     form = Form(loadFromType="type1",
                 context=None,
                 request=Request(),
                 app=self.app,
                 view=self.view)
     form.Setup()
     self.assert_(form.GetFields())
     form._SetUpSchema()
     self.assertFalse(form.GetField("test000"))
     request = Request()
     form.LoadDefaultData()
     form.GetActions(True)
     form.GetActions(False)
     form.GetFormValue("test", request=request, method=None)
     form.GetFormValues(request)
Exemple #4
0
 def test_html2(self, **kw):
     form = HTMLForm(loadFromType="type1",
                     app=self.app,
                     view=self.view,
                     request=Request())
     form.formUrl = "form/url"
     form.cssID = u"upload"
     form.css_class = u"niveform"
     form.subsets = {u"test": {"fields": [u"ftext", u"funit"]}}
     form.Setup(subset=u"test")
     v, d, e = form.Validate(data1_2)
     self.assert_(v, e)
     form.Render(d, msgs=None, errors=None)
Exemple #5
0
    def test_actions(self, **kw):
        form = HTMLForm(loadFromType="type1",
                        app=self.app,
                        view=self.view,
                        request=Request())
        form.formUrl = "form/url"
        form.cssID = u"upload"
        form.css_class = u"niveform"

        # create
        form.actions = [
            Conf(
                **{
                    "id": "default",
                    "method": "StartForm",
                    "name": "Initialize",
                    "hidden": True,
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                }),
            Conf(
                **{
                    "id": "create",
                    "method": "CreateObj",
                    "name": "Create",
                    "hidden": False,
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                }),
            Conf(
                **{
                    "id": "cancel",
                    "method": "Cancel",
                    "name": "Cancel",
                    "hidden": False,
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                })
        ]
        form.Setup()
        a = form.GetActions(removeHidden=False)
        self.assert_(len(a) == 3)
        a = form.GetActions(removeHidden=True)
        self.assert_(len(a) == 2)
Exemple #6
0
    def test_fields(self, **kw):
        form = HTMLForm(loadFromType="type1",
                        app=self.app,
                        view=self.view,
                        request=Request())
        form.formUrl = "form/url"
        form.cssID = u"upload"
        form.css_class = u"niveform"
        # create
        form.Setup()

        f = form.GetFields(removeReadonly=True)
        self.assert_(len(f) == 9)
        f = form.GetFields(removeReadonly=False)
        self.assert_(len(f) == 14)
Exemple #7
0
    def test_json(self, **kw):
        form = JsonMappingForm(request=Request(), app=self.app, view=self.view)
        form.fields = (
            FieldConf(id="parameter1", datatype="text", size=1000),
            FieldConf(id="parameter2", datatype="string", size=100),
        )
        form.Setup()

        data = {"parameter1": "True", "parameter2": "test"}
        r, v, e = form.Validate(data)
        self.assert_(r, e)
        self.assert_(isinstance(v, dict))
        data = {"parameter1": "True", "parameter2": "test"}
        r, v = form.Extract(data)
        self.assert_(r, v)
        self.assert_(isinstance(v, dict))
Exemple #8
0
    def test_html(self, **kw):
        form = HTMLForm(loadFromType="type1",
                        app=self.app,
                        view=self.view,
                        request=Request())
        form.formUrl = "form/url"
        form.cssID = u"upload"
        form.css_class = u"niveform"
        form.Setup()

        v, d, e = form.Validate(data1_1)
        self.assert_(v, str(e))

        v, d, e = form.Validate(data1_2)
        self.assertFalse(v, e)
        form.Render(d, msgs=None, errors=None)

        result, data = form.Extract(data1_1)
        self.assert_(data)
        result, data = form.Extract(data1_2)
        self.assert_(data)
Exemple #9
0
    def test_obj2(self, **kw):
        user = UserO(u"test")
        root = self.app.GetRoot()
        obj = root.Create("type1", data1_2, user)
        self.remove.append(obj.id)
        v = Viewy()

        form = ObjectForm(loadFromType="type1",
                          context=obj,
                          view=v,
                          request=Request(),
                          app=self.app)
        form.formUrl = "form/url"
        form.cssID = u"upload"
        form.css_class = u"niveform"
        count = self.app.db.GetCountEntries()
        # edit
        form.actions = [
            Conf(
                **{
                    "id": "default",
                    "method": "StartObject",
                    "name": "Initialize",
                    "hidden": True,
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                }),
            Conf(
                **{
                    "id": "save",
                    "method": "UpdateObj",
                    "name": "Save",
                    "hidden": False,
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                }),
            Conf(
                **{
                    "id": "cancel",
                    "method": "Cancel",
                    "name": "Cancel",
                    "hidden": False,
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                })
        ]
        form.Setup()
        form.Process()
        req = {"save$": 1}
        req.update(data1_1)
        form.request = req
        form.Process()
        req = {"cancel$": 1}
        form.request = req
        form.Process()
        d = form.LoadObjData()
        self.assertEqual(count, self.app.db.GetCountEntries())

        form = ObjectForm(loadFromType="type1",
                          context=obj,
                          view=v,
                          request=Request(),
                          app=self.app)
        form.subsets = {
            u"test": {
                "fields": [u"ftext", u"funit"],
                "actions": [u"defaultEdit", u"edit", u"cancel"]
            }
        }
        form.Setup(subset="test")
        form.Process()
        req = {"edit$": 1}
        req.update(data1_2)
        form.request = req
        form.Process(values={"fnumber": 333})
        req = {"cancel$": 1}
        form.request = req
        form.Process()
        self.assertEqual(count, self.app.db.GetCountEntries())

        form = ObjectForm(loadFromType="type1",
                          context=obj,
                          view=v,
                          request=Request(),
                          app=self.app)
        form.subsets = {
            u"test": {
                "fields": [
                    u"ftext",
                    FieldConf(**{
                        "id": "section1",
                        "name": "Section 1",
                        "datatype": "url"
                    })
                ],
                "actions": [u"defaultEdit", u"edit", u"cancel"]
            }
        }
        form.subset = "test"
        form.Setup(subset="test")
        form.Process()
        req = {"edit$": 1}
        req.update(data1_2)
        form.request = req
        form.Process()
        req = {"cancel$": 1}
        form.request = req
        form.Process()
        self.assertEqual(count, self.app.db.GetCountEntries())

        form = ObjectForm(loadFromType="type1",
                          context=obj,
                          view=v,
                          request=Request(),
                          app=self.app)
        form.subsets = {
            u"test": {
                "fields": [
                    u"ftext",
                    FieldConf(
                        **{
                            "id": "section1",
                            "name": "Section 1",
                            "datatype": "unitlist"
                        })
                ],
                "actions": [u"defaultEdit", u"edit", u"cancel"]
            }
        }
        try:
            form.Setup(subset="test3")
            form.Process()
            self.assert_(False)
        except ConfigurationError:
            pass
        self.assertEqual(count, self.app.db.GetCountEntries())
Exemple #10
0
    def test_obj(self, **kw):
        root = self.app.GetRoot()
        v = Viewy()
        form = ObjectForm(loadFromType="type1",
                          context=root,
                          view=v,
                          request=Request(),
                          app=self.app)
        form.formUrl = "form/url"
        form.cssID = u"upload"
        form.css_class = u"niveform"

        # create
        form.actions = [
            Conf(
                **{
                    "id": "default",
                    "method": "StartForm",
                    "name": "Initialize",
                    "hidden": True,
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                }),
            Conf(
                **{
                    "id": "create",
                    "method": "CreateObj",
                    "name": "Create",
                    "hidden": False,
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                }),
            Conf(
                **{
                    "id": "cancel",
                    "method": "Cancel",
                    "name": "Cancel",
                    "hidden": False,
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                })
        ]
        form.Setup(addTypeField=True)

        count = self.app.db.GetCountEntries()
        result, data, action = form.Process()
        self.assert_(result)
        self.assertEqual(action.id, "default")
        self.assertEqual(count, self.app.db.GetCountEntries())

        req = {"create$": 1, "pool_type": "type1"}
        req.update(data1_1)
        form.request = req
        result, data, action = form.Process(values={"fnumber": 999})
        self.assert_(result)
        self.assertEqual(action.id, "create")
        self.assertEqual(count + 1, self.app.db.GetCountEntries())
        self.remove.append(result.id)

        req = {"cancel$": 1}
        form.request = req
        result, data, action = form.Process()
        self.assert_(result)
        self.assertEqual(action.id, "cancel")
        self.assertEqual(count + 1, self.app.db.GetCountEntries())

        form = ObjectForm(loadFromType="type1",
                          context=root,
                          view=v,
                          request=Request(),
                          app=self.app)
        form.subsets = {
            u"test": {
                "fields": [u"ftext", u"funit"],
                "actions": [u"default", u"create", u"cancel"]
            }
        }
        form.Setup(subset="test", addTypeField=True)
        result, data, action = form.Process()
        self.assert_(result)
        self.assertEqual(action.id, "default")
        self.assertEqual(count + 1, self.app.db.GetCountEntries())

        req = {"create$": 1, "pool_type": "type1"}
        req.update(data1_2)
        form.request = req
        result, data, action = form.Process()
        self.assert_(result)
        self.assertEqual(action.id, "create")
        self.assertEqual(count + 2, self.app.db.GetCountEntries())
        self.remove.append(result.id)

        req = {"cancel$": 1}
        form.request = req
        result, data, action = form.Process()
        self.assert_(result)
        self.assertEqual(action.id, "cancel")
        self.assertEqual(count + 2, self.app.db.GetCountEntries())

        form = ObjectForm(loadFromType="type1",
                          context=root,
                          view=v,
                          request=Request(),
                          app=self.app)
        form.subsets = {
            u"test": {
                "fields": [
                    u"ftext",
                    FieldConf(**{
                        "id": "section1",
                        "name": "Section 1",
                        "datatype": "email"
                    })
                ],
                "actions": [u"default", u"create", u"cancel"]
            }
        }
        form.Setup(subset="test", addTypeField=True)
        result, data, action = form.Process()
        self.assert_(result)
        self.assertEqual(action.id, "default")
        self.assertEqual(count + 2, self.app.db.GetCountEntries())

        req = {"create$": 1, "pool_type": "type1"}
        req.update(data1_2)
        form.request = req
        result, data, action = form.Process()
        self.assert_(result)
        self.assertEqual(action.id, "create")
        self.assertEqual(count + 3, self.app.db.GetCountEntries())
        self.remove.append(result.id)

        req = {"cancel$": 1}
        form.request = req
        result, data, action = form.Process()
        self.assert_(result)
        self.assertEqual(action.id, "cancel")
        self.assertEqual(count + 3, self.app.db.GetCountEntries())
Exemple #11
0
 def __init__(self):
     self.request = Request()
     self.context = None
Exemple #12
0
    def test_tool(self, **kw):
        tool = self.app.GetTool("nive.tools.example")
        form = ToolForm(loadFromType=tool.configuration,
                        context=tool,
                        app=self.app,
                        view=self.view,
                        request=Request())
        form.formUrl = "form/url"
        form.cssID = u"upload"
        form.css_class = u"niveform"
        form.actions = [
            Conf(
                **{
                    "id": "default",
                    "name": "Speichern",
                    "method": "StartForm",
                    "description": "",
                    "hidden": True,
                    "css_class": "",
                    "html": "",
                    "tag": ""
                }),
            Conf(
                **{
                    "id": "run",
                    "name": "Speichern",
                    "method": "RunTool",
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                }),
            Conf(
                **{
                    "id": "cancel",
                    "name": "Abbrechen",
                    "method": "Cancel",
                    "description": "",
                    "css_class": "",
                    "html": "",
                    "tag": ""
                })
        ]
        form.Setup()
        data = {"parameter1": "True", "parameter2": "test"}

        form.Process()
        req = {"run$": 1}
        req.update(data)
        form.request = req
        form.Process()
        req = {"cancel$": 1}
        form.request = req
        form.Process()

        form.subsets = {u"test": {"fields": [u"parameter1"]}}
        form.Setup("test")
        form.Process()
        req = {"run$": 1}
        req.update(data)
        form.request = req
        form.Process()
        req = {"cancel$": 1}
        form.request = req
        form.Process()

        form.subset = "test"
        form.subsets = {
            u"test": {
                "fields": [
                    u"parameter1",
                    FieldConf(**{
                        "id": "section1",
                        "name": "Section 1",
                        "datatype": "lines"
                    })
                ]
            }
        }
        form.Setup("test")
        form.Process()
        req = {"run$": 1}
        req.update(data)
        form.request = req
        form.Process()
        req = {"cancel$": 1}
        form.request = req
        form.Process()