def test_attributes(self): user = User.parse(PythonDocumentBuilder, self.source) self.assertTrue(user.has_attributes()) attrs = user.get_attributes() self.assertEqual(len(attrs.values()), 6) self.assertEqual(attrs.first_name, 'User') self.assertEqual(attrs.last_name, 'last name') self.assertEqual(attrs.age, 30) self.assertEqual(attrs.gender, 'male') self.assertEqual(attrs.email, '*****@*****.**') self.assertEqual(attrs.phone, '79110001020')
def test_to_dict(self): source_node = etree.XML(self.xml_file) user = User.parse(LXMLDocumentBuilder, source_node) self.assertEqual( User.build(PythonDocumentBuilder, user), { '_attributes': { 'first_name': 'Alexander', 'last_name': 'Pepyako', 'age': 23, 'gender': 'male', 'phone': '+79110010203', 'email': '*****@*****.**' }, 'id': 1, 'sign': 'Pepyako inc.' } )
def test_to_xml(self): source_node = etree.XML(self.xml_file) user = User.parse(LXMLDocumentBuilder, source_node) xml_node = User.build(LXMLDocumentBuilder, user) source = User.parse(LXMLDocumentBuilder, xml_node) self.assert_user(source)
def test_build_from_xml(self): node = etree.fromstring(self.xml_file) user = User.parse(LXMLDocumentBuilder, node) self.assert_user(user)