def test_exception(self): try: Attachment.to_xml(Attachment()) except: self.assertTrue(True) else: self.assertFalse(True)
def test_exception(self): try: Attachment.to_xml(Attachment(), ns_test) except: self.assertTrue(True) else: self.assertFalse(True)
def test_from_xml(self): f = open(self.tmpfile) data = f.read() f.close() a = Attachment() a.data = data element = Attachment.to_xml(a) a2 = Attachment.from_xml(element) self.assertEquals(data, a2.data)
def test_to_from_xml_file(self): a = Attachment() a.fileName = self.tmpfile element = Attachment.to_xml(a) data = Attachment.from_xml(element).data f = open(self.tmpfile, 'rb') fdata = f.read() f.close() self.assertEquals(data, fdata)
def test_to_xml_data(self): f = open(self.tmpfile) data = f.read() f.close() a = Attachment() a.data = data element = Attachment.to_xml(a, ns_test) encoded_data = base64.encodestring(data) self.assertNotEquals(element.text, None) self.assertEquals(element.text, encoded_data)
def test_to_xml_file(self): a = Attachment() a.fileName = self.tmpfile f = open(self.tmpfile, 'rb') data = f.read() f.close() element = Attachment.to_xml(a) encoded_data = base64.encodestring(data) self.assertNotEquals(element.text, None) self.assertEquals(element.text, encoded_data)
def test_to_xml_file(self): a = Attachment() a.file_name = self.tmpfile f = open(self.tmpfile, "rb") data = f.read() f.close() element = Attachment.to_xml(a, ns_test) encoded_data = base64.encodestring(data) self.assertNotEquals(element.text, None) self.assertEquals(element.text, encoded_data)
def test_to_xml_data(self): f = open(self.tmpfile) data = f.read() f.close() a = Attachment() a.data = data element = Attachment.to_xml(a) 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_xml(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_xml(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_results(self, job_id): cur_job = Job.objects.get(job_id=job_id, state=JobState.DONE) files = Retrieval.objects.filter(parent_job=cur_job) attachment = Attachment() for file in files: try: self.storage.get_contents(self.job_id, file.name) # Hack to avoid error if no data if file_data == '': file_data = ' ' except: file_data = ' ' attachment.__setattr__(file.name, Attachment()) attachement_elem = retrieval.__getattribute__(file.name) attachement_elem.data = file_data return attachment
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(fileName=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
#!/usr/bin/env python # # soaplib - Copyright (C) 2009 Aaron Bickell, Jamie Kirkpatrick # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 # from soaplib.client import make_service_client from soaplib.serializers.binary import Attachment from helloworld_attach import HelloWorldService from soaplib.client import debug debug(True) client = make_service_client('http://localhost:7789/', HelloWorldService()) print client.say_hello(Attachment(data="Dave"), 5, mtom=True)
def test_add_to_schema(self): schema = {} Attachment.add_to_schema(schema, NamespaceLookup()) self.assertEquals(0, len(schema.keys()))
def test_get_datatype(self): dt = Attachment.get_type_name() self.assertEquals("base64Binary", dt) dt = Attachment.get_namespace() assert soaplib.nsmap["xs"] == dt
def test_add_to_schema(self): schema = {} Attachment.add_to_schema(schema) self.assertEquals(0, len(schema.keys()))
def test_get_datatype(self): dt = Attachment.get_datatype() self.assertEquals('base64Binary', dt) dt = Attachment.get_datatype(ns) self.assertEquals(ns.get('xs') + 'base64Binary', dt)
def test_get_datatype(self): dt = Attachment.get_type_name() self.assertEquals('base64Binary', dt) dt = Attachment.get_namespace() assert dt == soaplib.ns_xsd