diff --git a/mutalyzer/services/rpc.py b/mutalyzer/services/rpc.py index ad0834284b9be279275803633da8b884d8a47c13..0c1b042d5be1ff795ca2e8e117819ec9cf90a6e0 100644 --- a/mutalyzer/services/rpc.py +++ b/mutalyzer/services/rpc.py @@ -1039,16 +1039,49 @@ class MutalyzerService(ServiceBase): return transcripts #getTranscriptsAndInfo - @srpc(Mandatory.String, _returns=Mandatory.String) - def upLoadGenBankLocalFile(content) : + @srpc(Mandatory.ByteArray, _returns=Mandatory.String) + def upLoadGenBankLocalFile(data): """ - Not implemented yet. + Upload a genbank file. + + @arg data: Genbank file. + @return: UD accession number for the uploaded genbank file. """ - raise Fault('ENOTIMPLEMENTED', 'Not implemented yet') + output = Output(__file__) + retriever = Retriever.GenBankRetriever(output) + + output.addMessage(__file__, -1, 'INFO', + 'Received request uploadGenBankLocalFile()') + + # Note that the max file size check below might be bogus, since Spyne + # first checks the total request size, which by default has a maximum + # of 2 megabytes. + # In that case, a senv:Client.RequestTooLong faultstring is returned. + + # Todo: Set maximum request size by specifying the max_content_length + # argument for spyne.server.wsgi.WsgiApplication in all webservice + # instantiations. + if sum(len(s) for s in data) > settings.MAX_FILE_SIZE: + raise Fault('EMAXSIZE', + 'Only files up to %d megabytes are accepted.' + % (settings.MAX_FILE_SIZE // 1048576)) + + ud = retriever.uploadrecord(''.join(data)) + + output.addMessage(__file__, -1, 'INFO', + 'Finished processing uploadGenBankLocalFile()') + + # Todo: use SOAP Fault object here (see Trac issue #41). + if not ud: + error = 'The request could not be completed\n' \ + + '\n'.join(map(lambda m: str(m), output.getMessages())) + raise Exception(error) + + return ud #upLoadGenBankLocalFile @srpc(Mandatory.String, _returns=Mandatory.String) - def upLoadGenBankRemoteFile(url) : + def uploadGenBankRemoteFile(url) : """ Not implemented yet. """ diff --git a/tests/test_services_soap.py b/tests/test_services_soap.py index 7bd688316ecae145708e77fec54349515d7929f2..5735e9be55297114c9ef4aa1cb579bf0ae135c85 100644 --- a/tests/test_services_soap.py +++ b/tests/test_services_soap.py @@ -648,3 +648,22 @@ facilisi.""" # - EMAXSIZE: Raised by Mutalyzer, depending on the # batchInputMaxSize configuration setting. assert e.faultcode in ('senv:Client.RequestTooLong', 'EMAXSIZE') + + @fix(database) + def test_upload_local_genbank(self): + """ + Upload local genbank file. + """ + path = os.path.join(os.path.dirname(os.path.realpath(__file__)), + 'data', + 'AB026906.1.gb.bz2') + with bz2.BZ2File(path) as f: + data = f.read() + + result = self._call('upLoadGenBankLocalFile', data) + ud = str(result) + + r = self._call('runMutalyzer', ud + '(SDHD):g.7872G>T') + assert r.errors == 0 + assert r.genomicDescription == ud + ':g.7872G>T' + assert ud + '(SDHD_v001):c.274G>T' in r.transcriptDescriptions.string