i-parapheur: add support for get file ws (#10549)

This commit is contained in:
Josue Kouka 2016-04-14 12:10:53 +02:00
parent 9ba00c7024
commit a84de75532
4 changed files with 39 additions and 6 deletions

View File

@ -13,12 +13,14 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import base64
from django.db import models
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse
from passerelle.base.models import BaseResource
@ -105,11 +107,14 @@ class IParapheur(BaseResource):
'message': r.MessageRetour.message}
def get_file(self, file_id):
c = get_client(self)
r = c.service.GetDossier(file_id)
if r.MessageRetour.codeRetour == 'KO':
raise FileError(r.MessageRetour.message)
return r
client = get_client(self)
resp = client.service.GetDossier(file_id)
if resp.MessageRetour.codeRetour == 'KO':
raise FileError(resp.MessageRetour.message)
fichier_nom = resp.MetaDonnees.MetaDonnee[0]['valeur']
fichier = resp.DocumentsAnnexes.DocAnnexe[0].fichier
return HttpResponse(base64.b64decode(fichier['value']),
content_type=fichier['_contentType'])
def get_file_status(self, DossierID):
c = get_client(self)

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -4,6 +4,7 @@ import pytest
import mock
import uuid
import os
import hashlib
import base64
import xml.etree.ElementTree as ET
@ -105,7 +106,6 @@ def test_create_file(http_open, mocked_post, mocked_get, setup, xmlmime, wsdl_fi
@mock.patch('passerelle.utils.LoggedRequest.post')
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
def test_get_file_status(http_open, mocked_post, mocked_get, setup, xmlmime, wsdl_file):
pass
app, conn = setup
file_id = str(uuid.uuid4())
@ -128,3 +128,24 @@ def test_get_file_status(http_open, mocked_post, mocked_get, setup, xmlmime, wsd
assert data['nom'] == 'webservices gru'
assert data['timestamp'] == '2016-04-05T09:58:46.000'
@mock.patch('passerelle.utils.LoggedRequest.get')
@mock.patch('passerelle.utils.LoggedRequest.post')
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
def test_get_file(http_open, mocked_post, mocked_get, setup, xmlmime, wsdl_file):
app, conn = setup
file_id = str(uuid.uuid4())
soap_response = file(os.path.join(os.path.dirname(__file__),
'data/iparapheur_get_file_response.xml')).read()
http_open.return_value = file(xmlmime)
mocked_get.return_value = mock.Mock(content = file(wsdl_file).read(),
status_code=200)
mocked_post.return_value = mock.Mock(status_code=200, content=soap_response)
url = reverse('iparapheur-get-file', kwargs={'slug': conn.slug, 'file_id': file_id})
url += '?apikey=%s' % API_KEY
resp = app.get(url, {'DossierID': file_id}, status=200)
file_sent = os.path.join(os.path.dirname(__file__), 'data/iparapheur_test.pdf')
assert resp.headers['Content-Type'] == 'application/pdf'
assert hashlib.md5(resp.body[:8192]).hexdigest() == hashlib.md5(file(file_sent).read()[:8192]).hexdigest()