def test_many_and_one(self): lang = Dict(dict( nb = "Norwegian", en = "English", dk = "Danish" )) form = Form("http://example.com/submit", "send") model = dict(a=One(lang)) manip = Manip(model) manip.a = "en" form["x"] = ModelData(manip) xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</one>"), 1) self.assertEquals(xml.count("</item>"), 2) self.assertEquals(xml.count("</sel_item>"), 1) model = dict(a=Many(lang)) manip = Manip(model) manip.a = ["en", "nb"] form["x"] = ModelData(manip) xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</many>"), 1) self.assertEquals(xml.count("</item>"), 1) self.assertEquals(xml.count("</sel_item>"), 2) form["x"].display["a"] = {"hidden": True} xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</hidden>"), 2) form["x"].display["a"] = {"readonly": True} self.assertRaises(ValueError, form.create)
def test_read_only_and_hidden_and_xmlns(self): model = dict(a=Int()) manip = Manip(model) form = Form("http://example.com/submit", "send") form["x"] = ModelData(manip) # test read only form["x"].display["a"] = {"readonly": True} xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</readonly>"), 1) self.assertEquals(xml.count("xmlns="), 1) # test hidden form["x"].display["a"] = {"hidden": True} xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</hidden>"), 1) # test disable namespace form.xmlns = None xml = form.create() self.assertEquals(xml.count("xmlns="), 0) form.xmlns = "XXXX" xml = form.create() self.assertEquals(xml.count("xmlns=\"XXXX\""), 1)
def test_read_only_and_hidden_and_xmlns(self): model = dict(a = Int()) manip = Manip(model) form = Form("http://example.com/submit", "send") form["x"] = ModelData(manip) # test read only form["x"].display["a"] = {"readonly": True} xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</readonly>"), 1) self.assertEquals(xml.count("xmlns="), 1) # test hidden form["x"].display["a"] = {"hidden": True} xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</hidden>"), 1) # test disable namespace form.xmlns = None xml = form.create() self.assertEquals(xml.count("xmlns="), 0) form.xmlns = "XXXX" xml = form.create() self.assertEquals(xml.count("xmlns=\"XXXX\""), 1)
def _create_edit_form(self, manip, validate=False): self.preform_edit_manip(manip) form = Form("save", "Save", method="post") form["e_"] = ModelData(manip) form["e_"].meta = self.META if validate: form["e_"].validate() self.w.raw_node(form.create())
def _test_fieldgen(self, model, value): m = data.Manip(model) m.x = value form = Form("http://example.com/myform", "Submit") form["x"] = ModelData(m) form["x"].meta["x"] = {"label": "The label"} s = form.create() self.assertEquals(s.count("The label"), 1) RelaxNG(parse(RNG)).assertValid(XML(s)) return s
def test_hidden_and_readonly(self): m = data.Manip(dict(x=String())) m.x = "test" form = Form("http://example.com/myform", "Submit") form["x"] = ModelData(m) form["x"].display["x"] = {"hidden": True} s = form.create() RelaxNG(parse(RNG)).assertValid(XML(s)) form["x"].display["x"] = {"readonly": True} s = form.create() RelaxNG(parse(RNG)).assertValid(XML(s))
def checkField(self, fieldobj, value, expected): model = dict(a=fieldobj) manip = Manip(model) manip.a = value form = Form("http://example.com/submit", "send") form["x"] = ModelData(manip) xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</%s>" % expected), 1)
def test_many_and_one(self): lang = Dict(dict(nb="Norwegian", en="English", dk="Danish")) form = Form("http://example.com/submit", "send") model = dict(a=One(lang)) manip = Manip(model) manip.a = "en" form["x"] = ModelData(manip) xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</one>"), 1) self.assertEquals(xml.count("</item>"), 2) self.assertEquals(xml.count("</sel_item>"), 1) model = dict(a=Many(lang)) manip = Manip(model) manip.a = ["en", "nb"] form["x"] = ModelData(manip) xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</many>"), 1) self.assertEquals(xml.count("</item>"), 1) self.assertEquals(xml.count("</sel_item>"), 2) form["x"].display["a"] = {"hidden": True} xml = form.create() validate_form(XML(xml)) self.assertEquals(xml.count("</hidden>"), 2) form["x"].display["a"] = {"readonly": True} self.assertRaises(ValueError, form.create)