def test_exception(self): try: Attachment.to_parent_element(Attachment(), ns_test) except: self.assertTrue(True) else: self.assertFalse(True)
def test_to_parent_element_file(self): a = Attachment() a.file_name = self.tmpfile f = open(self.tmpfile, 'rb') data = f.read() f.close() element = etree.Element('test') Attachment.to_parent_element(a, ns_test, element) element = element[0] encoded_data = base64.encodestring(data) self.assertNotEquals(element.text, None) self.assertEquals(element.text, encoded_data)
def test_from_xml(self): f = open(self.tmpfile) data = f.read() f.close() a = Attachment() a.data = data element = etree.Element('test') Attachment.to_parent_element(a, ns_test, element) element = element[0] a2 = Attachment.from_xml(element) self.assertEquals(data, a2.data)
def test_to_from_xml_file(self): a = Attachment() a.file_name = self.tmpfile element = etree.Element('test') Attachment.to_parent_element(a, ns_test, element) element = element[0] data = Attachment.from_xml(element).data f = open(self.tmpfile, 'rb') fdata = f.read() f.close() self.assertEquals(data, fdata)