greco: raise APIError on http transport error (#40974)

This commit is contained in:
Thomas NOËL 2020-03-24 15:50:58 +01:00
parent 6cdd8fd1bb
commit 54c64ec747
3 changed files with 664 additions and 0 deletions

View File

@ -178,6 +178,12 @@ class Greco(BaseResource):
headers=request.headers,
verify=self.instance.verify_cert,
timeout=60)
if resp.status_code >= 400 and resp.status_code != 500:
raise APIError('HTTP Transport Error %s' % resp.status_code,
err_code='transport-error-%s' % resp.status_code)
elif resp.status_code == 500 and b'Fault' not in resp.content:
raise APIError('Error 500, not a SOAP Fault',
err_code='transport-error-500')
return Reply(resp.status_code, resp.headers, resp.content)
return Client(url=self.wsdl_url, transport=Transport(self, attachments))

602
tests/data/greco.wsdl Normal file
View File

@ -0,0 +1,602 @@
<?xml version="1.0"?>
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://mairies.services.external.coheris.com" xmlns:intf="http://mairies.services.external.coheris.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://mairies.services.external.coheris.com">
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://mairies.services.external.coheris.com">
<element name="ajouterComplementInformation">
<complexType>
<sequence>
<element name="demandeAjoutComplementInfo" type="impl:DemandeAjoutComplementInfo"/>
</sequence>
</complexType>
</element>
<complexType name="DemandeAjoutComplementInfo">
<sequence>
<element name="complementInfo" nillable="true" type="xsd:string"/>
<element name="iddemande" nillable="true" type="xsd:string"/>
<element name="idgreco" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="ajouterComplementInformationResponse">
<complexType>
<sequence>
<element name="ajouterComplementInformationReturn" type="impl:Reponse"/>
</sequence>
</complexType>
</element>
<complexType name="Reponse">
<sequence>
<element name="iddemande" nillable="true" type="xsd:string"/>
<element name="idgreco" nillable="true" type="xsd:string"/>
<element name="motifsrejet" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="attachmentTest">
<complexType/>
</element>
<element name="attachmentTestResponse">
<complexType>
<sequence>
<element name="attachmentTestReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="communicationTest">
<complexType>
<sequence>
<element name="input" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="communicationTestResponse">
<complexType>
<sequence>
<element name="communicationTestReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="relancer">
<complexType>
<sequence>
<element name="demandeRelance" type="impl:DemandeRelance"/>
</sequence>
</complexType>
</element>
<complexType name="DemandeRelance">
<sequence>
<element name="commentaire" nillable="true" type="xsd:string"/>
<element name="iddemande" nillable="true" type="xsd:string"/>
<element name="idgreco" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="relancerResponse">
<complexType>
<sequence>
<element name="relancerReturn" type="impl:Reponse"/>
</sequence>
</complexType>
</element>
<element name="consulter">
<complexType>
<sequence>
<element name="demandeConsultation" type="impl:DemandeConsultation"/>
</sequence>
</complexType>
</element>
<complexType name="DemandeConsultation">
<sequence>
<element name="iddemande" nillable="true" type="xsd:string"/>
<element name="idgreco" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="consulterResponse">
<complexType>
<sequence>
<element name="consulterReturn" type="impl:ReponseConsultation"/>
</sequence>
</complexType>
</element>
<complexType name="ReponseEtat">
<complexContent>
<extension base="impl:Reponse">
<sequence>
<element name="etat" nillable="true" type="xsd:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="CompteRendu">
<sequence>
<element name="compteRenduContent" nillable="true" type="xsd:string"/>
<element name="dateValidationCompteRendu" nillable="true" type="xsd:dateTime"/>
</sequence>
</complexType>
<complexType name="ArrayOfCompteRendu">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item" type="impl:CompteRendu"/>
</sequence>
</complexType>
<complexType name="ReponseConsultation">
<complexContent>
<extension base="impl:ReponseEtat">
<sequence>
<element name="commentaireReponse" nillable="true" type="xsd:string"/>
<element name="comptesRendus" nillable="true" type="impl:ArrayOfCompteRendu"/>
<element name="dateResolutionEffective" nillable="true" type="xsd:dateTime"/>
<element name="dateResolutionPrevue" nillable="true" type="xsd:dateTime"/>
<element name="groupeResponsable" nillable="true" type="xsd:string"/>
<element name="suiteDonnee" nillable="true" type="xsd:string"/>
<element name="idOrganismeExterne" nillable="true" type="xsd:string"/>
<element name="nomOrganisme" nillable="true" type="xsd:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="getMail">
<complexType>
<sequence>
<element name="demandeGetMail" type="impl:DemandeGetMail"/>
</sequence>
</complexType>
</element>
<complexType name="DemandeGetMail">
<sequence>
<element name="iddemande" nillable="true" type="xsd:string"/>
<element name="idgreco" nillable="true" type="xsd:string"/>
<element name="taCode" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="getMailResponse">
<complexType>
<sequence>
<element name="getMailReturn" type="impl:ReponseGetMail"/>
</sequence>
</complexType>
</element>
<complexType name="ArrayOf_xsd_string">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="Message">
<sequence>
<element name="bcc" nillable="true" type="impl:ArrayOf_xsd_string"/>
<element name="cc" nillable="true" type="impl:ArrayOf_xsd_string"/>
<element name="content" nillable="true" type="xsd:string"/>
<element name="date" nillable="true" type="xsd:string"/>
<element name="subject" nillable="true" type="xsd:string"/>
<element name="to" nillable="true" type="impl:ArrayOf_xsd_string"/>
</sequence>
</complexType>
<complexType name="ReponseGetMail">
<complexContent>
<extension base="impl:ReponseEtat">
<sequence>
<element name="message" nillable="true" type="impl:Message"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="getListOrganisme">
<complexType/>
</element>
<element name="getListOrganismeResponse">
<complexType>
<sequence>
<element name="getListOrganismeReturn" type="impl:GetListOrganismeResp"/>
</sequence>
</complexType>
</element>
<complexType name="organisme">
<sequence>
<element name="idOrganisme" nillable="true" type="xsd:string"/>
<element name="nomOrganisem" nillable="true" type="xsd:string"/>
<element name="mailOrganisme" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="GetListOrganismeResp">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="organismes" type="impl:organisme"/>
</sequence>
</complexType>
<element name="getListDemande">
<complexType>
<sequence>
<element name="nbJours" type="impl:GetListDemandeRequest"/>
</sequence>
</complexType>
</element>
<complexType name="GetListDemandeRequest">
<sequence>
<element name="nbJours" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="getListDemandeResponse">
<complexType>
<sequence>
<element name="getListDemandeReturn" type="impl:GetListDemandeResponse"/>
</sequence>
</complexType>
</element>
<complexType name="DemandeList">
<sequence>
<element name="mailBeneficiaire" nillable="true" type="xsd:string"/>
<element name="idGreco" nillable="true" type="xsd:string"/>
<element name="numDemandeLogicielExterne" nillable="true" type="xsd:string"/>
<element name="idLogicielExterne" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="GetListDemandeResponse">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="demandeListe" type="impl:DemandeList"/>
</sequence>
</complexType>
<element name="getContenuDossier">
<complexType>
<sequence>
<element name="idGreco" type="impl:GetContenuDossierRequest"/>
</sequence>
</complexType>
</element>
<complexType name="GetContenuDossierRequest">
<sequence>
<element name="idGreco" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="getContenuDossierResponse">
<complexType>
<sequence>
<element name="getContenuDossierReturn" type="impl:GetContenuDossierResponse"/>
</sequence>
</complexType>
</element>
<complexType name="BeneficiaireContact">
<sequence>
<element name="civilite" nillable="true" type="xsd:string"/>
<element name="prenom" nillable="true" type="xsd:string"/>
<element name="nom" nillable="true" type="xsd:string"/>
<element name="Organisation" nillable="true" type="xsd:string"/>
<element name="email" nillable="true" type="xsd:string"/>
<element name="telephone1" nillable="true" type="xsd:string"/>
<element name="telephone2" nillable="true" type="xsd:string"/>
<element name="telephone3" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="BeneficiaireAdresse">
<sequence>
<element name="codePostal" nillable="true" type="xsd:string"/>
<element name="voie" nillable="true" type="xsd:string"/>
<element name="codeRivolivoie" nillable="true" type="xsd:string"/>
<element name="codeFuvVoie" nillable="true" type="xsd:string"/>
<element name="numeroVoie" nillable="true" type="xsd:string"/>
<element name="commune" nillable="true" type="xsd:string"/>
<element name="complement" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="LocalisationV2">
<sequence>
<element name="voie" nillable="true" type="xsd:string"/>
<element name="codeRivoliVoie" nillable="true" type="xsd:string"/>
<element name="codeFuvVoie" nillable="true" type="xsd:string"/>
<element name="numeroVoie" nillable="true" type="xsd:string"/>
<element name="commune" nillable="true" type="xsd:string"/>
<element name="complement" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="VoieSecante">
<sequence>
<element name="codeRivoliVoieSecante" nillable="true" type="xsd:string"/>
<element name="codeFuvVoieSecante" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="GetContenuDossierResponse">
<complexContent>
<extension base="impl:ReponseEtat">
<sequence>
<element name="dateDeDepot" nillable="true" type="xsd:string"/>
<element name="mediaDeReponse" nillable="true" type="xsd:string"/>
<element name="description" nillable="true" type="xsd:string"/>
<element name="isDangerRsque" nillable="true" type="xsd:string"/>
<element name="beneficiaireContact" nillable="true" type="impl:BeneficiaireContact"/>
<element name="beneficiaireAdresse" nillable="true" type="impl:BeneficiaireAdresse"/>
<element name="localisationV2" nillable="true" type="impl:LocalisationV2"/>
<element name="voieSecante" nillable="true" type="impl:VoieSecante"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="creer">
<complexType>
<sequence>
<element name="demandeCreation" type="impl:DemandeCreation"/>
</sequence>
</complexType>
</element>
<complexType name="Contact">
<sequence>
<element name="civilite" nillable="true" type="xsd:string"/>
<element name="email" nillable="true" type="xsd:string"/>
<element name="fax" nillable="true" type="xsd:string"/>
<element name="mobile" nillable="true" type="xsd:string"/>
<element name="nom" nillable="true" type="xsd:string"/>
<element name="prenom" nillable="true" type="xsd:string"/>
<element name="telephone" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="Beneficiaire">
<complexContent>
<extension base="impl:Contact">
<sequence>
<element name="codefuvvoie" nillable="true" type="xsd:string"/>
<element name="codepostal" nillable="true" type="xsd:string"/>
<element name="coderivolivoie" nillable="true" type="xsd:string"/>
<element name="commune" nillable="true" type="xsd:string"/>
<element name="complement" nillable="true" type="xsd:string"/>
<element name="numerovoie" nillable="true" type="xsd:string"/>
<element name="organisation" nillable="true" type="xsd:string"/>
<element name="typetiers" nillable="true" type="xsd:string"/>
<element name="voie" nillable="true" type="xsd:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="Localisation">
<sequence>
<element name="codefuvvoie" nillable="true" type="xsd:string"/>
<element name="codefuvvoiesecante" nillable="true" type="xsd:string"/>
<element name="coderivolivoie" nillable="true" type="xsd:string"/>
<element name="coderivolivoiesecante" nillable="true" type="xsd:string"/>
<element name="commune" nillable="true" type="xsd:string"/>
<element name="complement" nillable="true" type="xsd:string"/>
<element name="numerovoie" nillable="true" type="xsd:string"/>
<element name="voie" nillable="true" type="xsd:string"/>
<element name="voiesecante" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="Transmetteur">
<complexContent>
<extension base="impl:Contact">
<sequence>
<element name="service" nillable="true" type="xsd:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="DemandeCreation">
<sequence>
<element name="application" nillable="true" type="xsd:string"/>
<element name="beneficiaire" nillable="true" type="impl:Beneficiaire"/>
<element name="danger" type="xsd:boolean"/>
<element name="datecreation" nillable="true" type="xsd:dateTime"/>
<element name="datedepot" nillable="true" type="xsd:dateTime"/>
<element name="description" nillable="true" type="xsd:string"/>
<element name="domaineobjettype" nillable="true" type="xsd:string"/>
<element name="iddemande" nillable="true" type="xsd:string"/>
<element name="localisation" nillable="true" type="impl:Localisation"/>
<element name="mediareponse" nillable="true" type="xsd:string"/>
<element name="priorite" nillable="true" type="xsd:string"/>
<element name="transmetteur" nillable="true" type="impl:Transmetteur"/>
</sequence>
</complexType>
<element name="creerResponse">
<complexType>
<sequence>
<element name="creerReturn" type="impl:ReponseCreation"/>
</sequence>
</complexType>
</element>
<complexType name="ReponseCreation">
<complexContent>
<extension base="impl:ReponseEtat">
<sequence>
<element name="application" nillable="true" type="xsd:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="getListOrganismeResponse">
<wsdl:part element="impl:getListOrganismeResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="ajouterComplementInformationRequest">
<wsdl:part element="impl:ajouterComplementInformation" name="parameters"/>
</wsdl:message>
<wsdl:message name="getListDemandeRequest">
<wsdl:part element="impl:getListDemande" name="parameters"/>
</wsdl:message>
<wsdl:message name="getContenuDossierRequest">
<wsdl:part element="impl:getContenuDossier" name="parameters"/>
</wsdl:message>
<wsdl:message name="relancerRequest">
<wsdl:part element="impl:relancer" name="parameters"/>
</wsdl:message>
<wsdl:message name="creerRequest">
<wsdl:part element="impl:creer" name="parameters"/>
</wsdl:message>
<wsdl:message name="getListOrganismeRequest">
<wsdl:part element="impl:getListOrganisme" name="parameters"/>
</wsdl:message>
<wsdl:message name="communicationTestRequest">
<wsdl:part element="impl:communicationTest" name="parameters"/>
</wsdl:message>
<wsdl:message name="relancerResponse">
<wsdl:part element="impl:relancerResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="ajouterComplementInformationResponse">
<wsdl:part element="impl:ajouterComplementInformationResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getContenuDossierResponse">
<wsdl:part element="impl:getContenuDossierResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="attachmentTestResponse">
<wsdl:part element="impl:attachmentTestResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="consulterRequest">
<wsdl:part element="impl:consulter" name="parameters"/>
</wsdl:message>
<wsdl:message name="attachmentTestRequest">
<wsdl:part element="impl:attachmentTest" name="parameters"/>
</wsdl:message>
<wsdl:message name="creerResponse">
<wsdl:part element="impl:creerResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getListDemandeResponse">
<wsdl:part element="impl:getListDemandeResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getMailRequest">
<wsdl:part element="impl:getMail" name="parameters"/>
</wsdl:message>
<wsdl:message name="communicationTestResponse">
<wsdl:part element="impl:communicationTestResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="consulterResponse">
<wsdl:part element="impl:consulterResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getMailResponse">
<wsdl:part element="impl:getMailResponse" name="parameters"/>
</wsdl:message>
<wsdl:portType name="Mairies">
<wsdl:operation name="ajouterComplementInformation">
<wsdl:input message="impl:ajouterComplementInformationRequest" name="ajouterComplementInformationRequest"/>
<wsdl:output message="impl:ajouterComplementInformationResponse" name="ajouterComplementInformationResponse"/>
</wsdl:operation>
<wsdl:operation name="attachmentTest">
<wsdl:input message="impl:attachmentTestRequest" name="attachmentTestRequest"/>
<wsdl:output message="impl:attachmentTestResponse" name="attachmentTestResponse"/>
</wsdl:operation>
<wsdl:operation name="communicationTest">
<wsdl:input message="impl:communicationTestRequest" name="communicationTestRequest"/>
<wsdl:output message="impl:communicationTestResponse" name="communicationTestResponse"/>
</wsdl:operation>
<wsdl:operation name="relancer">
<wsdl:input message="impl:relancerRequest" name="relancerRequest"/>
<wsdl:output message="impl:relancerResponse" name="relancerResponse"/>
</wsdl:operation>
<wsdl:operation name="consulter">
<wsdl:input message="impl:consulterRequest" name="consulterRequest"/>
<wsdl:output message="impl:consulterResponse" name="consulterResponse"/>
</wsdl:operation>
<wsdl:operation name="getMail">
<wsdl:input message="impl:getMailRequest" name="getMailRequest"/>
<wsdl:output message="impl:getMailResponse" name="getMailResponse"/>
</wsdl:operation>
<wsdl:operation name="getListOrganisme">
<wsdl:input message="impl:getListOrganismeRequest" name="getListOrganismeRequest"/>
<wsdl:output message="impl:getListOrganismeResponse" name="getListOrganismeResponse"/>
</wsdl:operation>
<wsdl:operation name="getListDemande">
<wsdl:input message="impl:getListDemandeRequest" name="getListDemandeRequest"/>
<wsdl:output message="impl:getListDemandeResponse" name="getListDemandeResponse"/>
</wsdl:operation>
<wsdl:operation name="getContenuDossier">
<wsdl:input message="impl:getContenuDossierRequest" name="getContenuDossierRequest"/>
<wsdl:output message="impl:getContenuDossierResponse" name="getContenuDossierResponse"/>
</wsdl:operation>
<wsdl:operation name="creer">
<wsdl:input message="impl:creerRequest" name="creerRequest"/>
<wsdl:output message="impl:creerResponse" name="creerResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MairiesSoapBinding" type="impl:Mairies">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ajouterComplementInformation">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="ajouterComplementInformationRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="ajouterComplementInformationResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="attachmentTest">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="attachmentTestRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="attachmentTestResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="communicationTest">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="communicationTestRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="communicationTestResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="relancer">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="relancerRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="relancerResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="consulter">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="consulterRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="consulterResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getMail">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getMailRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getMailResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getListOrganisme">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getListOrganismeRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getListOrganismeResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getListDemande">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getListDemandeRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getListDemandeResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getContenuDossier">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getContenuDossierRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getContenuDossierResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="creer">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="creerRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="creerResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MairiesService">
<wsdl:port binding="impl:MairiesSoapBinding" name="Mairies">
<wsdlsoap:address location="https://api.grandlyon.com/grc-pro/1.0.0"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

56
tests/test_greco.py Normal file
View File

@ -0,0 +1,56 @@
import os
import pytest
import mock
from requests import Response
import utils
from django.core.urlresolvers import reverse
from django.contrib.contenttypes.models import ContentType
from passerelle.base.models import ApiUser, AccessRight
from passerelle.contrib.greco.models import Greco
pytestmark = pytest.mark.django_db
WSDL_FILENAME = os.path.join(os.path.dirname(__file__), 'data', 'greco.wsdl')
@pytest.fixture
def conn():
api_user = ApiUser.objects.create(username='greco', keytype='API', key='grecokey')
connector = Greco.objects.create(title='Greco', slug='greco',
application='appid',
token_url='http://greco.example.net/token',
token_authorization='authtoken',
wsdl_url='file://%s' % WSDL_FILENAME,
verify_cert=False)
obj_type = ContentType.objects.get_for_model(Greco)
AccessRight.objects.create(codename='can_access',
apiuser=api_user, resource_type=obj_type,
resource_pk=connector.pk)
return connector
def post_effect_503(url, *args, **kwargs):
if url == 'http://greco.example.net/token':
return utils.FakedResponse(
content='{"token_type": "tt", "access_token": "at", "expires_in": "600"}',
status_code=200)
return utils.FakedResponse(content='Service Unavailable', status_code=503)
@mock.patch('passerelle.utils.Request.post', side_effect=post_effect_503)
def test_greco_ping(mocked_post, app, conn):
url = reverse('generic-endpoint', kwargs={
'connector': 'greco',
'endpoint': 'ping',
'slug': conn.slug
})
app.get(url, status=403)
assert mocked_post.call_count == 0
url += '?apikey=grecokey'
resp = app.get(url).json
assert mocked_post.call_count == 2 # token + communcationTest (ping -> 503)
assert resp['err'] == 'transport-error-503'