Beispiel #1
0
	def test_create_multi_sub_element_xml_from_dict(self):
		xml_data = {
			"toast": {
				"attrs": {
					"key": "value"
				},
				"children": {
					"visual": {
						"children": {
							"binding": {
								"attrs": {"template": "ToastText02"},
								"children": {
									"text": [
										{"attrs": {"id": "1"}, "children": "first text"},
										{"attrs": {"id": "2"}, "children": "second text"},
									]
								}
							}
						}
					}
				}
			}
		}
		# Converting xml to str via tostring is inconsistent, so we have to check each element.
		xml_tree = dict_to_xml_schema(xml_data)
		self.assertEqual(xml_tree.tag, "toast")
		self.assertEqual(xml_tree.attrib, {"key": "value"})
		visual = xml_tree.getchildren()[0]
		self.assertEqual(visual.tag, "visual")
		binding = visual.getchildren()[0]
		self.assertEqual(binding.tag, "binding")
		self.assertEqual(binding.attrib, {"template": "ToastText02"})
		children = binding.getchildren()
		self.assertEqual(len(children), 2)
Beispiel #2
0
	def test_create_simple_xml_from_dict(self):
		xml_data = {
			"toast": {
				"attrs": {"key": "value"},
				"children": {
					"visual": {
						"children": {
							"binding": {
								"attrs": {"template": "ToastText01"},
								"children": {
									"text": {
										"attrs": {"id": "1"},
										"children": "toast notification"
									}
								}
							}
						}
					}
				}
			}
		}
		# Converting xml to str via tostring is inconsistent, so we have to check each element.
		xml_tree = dict_to_xml_schema(xml_data)
		self.assertEqual(xml_tree.tag, "toast")
		self.assertEqual(xml_tree.attrib, {"key": "value"})
		visual = xml_tree.getchildren()[0]
		self.assertEqual(visual.tag, "visual")
		binding = visual.getchildren()[0]
		self.assertEqual(binding.tag, "binding")
		self.assertEqual(binding.attrib, {"template": "ToastText01"})
		text = binding.getchildren()[0]
		self.assertEqual(text.tag, "text")
		self.assertEqual(text.attrib, {"id": "1"})
		self.assertEqual(text.text, "toast notification")