def test_deserialize_attributes_unexpected_element_need_definition(self): root = Element('whatever') attribute = SubElement(root, 'attribute') SubElement(attribute, 'wrong').text = 'element' with self.assertRaisesMessage(ValidationError, "'<whatever><attribute><wrong>': \"Unexpected element 'wrong'\""): deserialize_attributes(root)
def test_deserialize_attributes_ok(self): root = Element('whatever') attribute = SubElement(root, 'attribute') SubElement(attribute, 'definition').text = 'name1' SubElement(attribute, 'value').text = 'value1' SubElement(attribute, 'value').text = 'value2' attribute = SubElement(root, 'attribute') SubElement(attribute, 'definition').text = 'name2' self.assertDictEqual(deserialize_attributes(root), { 'name1': ['value1', 'value2'], 'name2': [], })
def test_deserialize_attributes_missing_definition_element(self): root = Element('whatever') SubElement(root, 'attribute').text = 'name' with self.assertRaisesMessage(ValidationError, "'<whatever><attribute>': 'Missing attribute.definition element.'"): deserialize_attributes(root)
def test_deserialize_attributes_unexpected_element_need_attribute(self): root = Element('whatever') SubElement(root, 'myName').text = 'name' with self.assertRaisesMessage(ValidationError, "'<whatever><myName>': \"Unexpected element 'myName'\""): deserialize_attributes(root)
def test_deserialize_attributes_empty(self): root = Element('whatever') self.assertDictEqual(deserialize_attributes(root), {})