Ejemplo n.º 1
0
	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)
Ejemplo n.º 2
0
	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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
	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())
Ejemplo n.º 6
0
	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)
Ejemplo n.º 7
0
 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)