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)
def get_archived_document(self, file_path): ''' This method loads a document from the specified file path and returns it. If the path isn't found, an exception is raised. ''' if not os.path.exists(file_path): raise Exception("File [%s] not found" % file_path) document = Attachment(file_name=file_path) # the service automatically loads the data from the file. # alternatively, The data could be manually loaded into memory # and loaded into the Attachment like: # document = Attachment(data=data_from_file) return document
def test_get_datatype(self): dt = Attachment.get_type_name() self.assertEquals('base64Binary', dt) dt = Attachment.get_namespace() assert dt == namespaces.ns_xsd
def test_add_to_schema(self): schema = {} Attachment.add_to_schema(schema) self.assertEquals(0, len(schema.keys()))