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_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 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 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)