13 |
13 |
# You should have received a copy of the GNU Affero General Public License
|
14 |
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15 |
15 |
|
|
16 |
import logging
|
|
17 |
|
16 |
18 |
import mock
|
17 |
19 |
import pytest
|
18 |
20 |
import requests
|
... | ... | |
21 |
23 |
from zeep.exceptions import TransportError, XMLParseError
|
22 |
24 |
from zeep.plugins import Plugin
|
23 |
25 |
|
|
26 |
from passerelle.utils import Request
|
24 |
27 |
from passerelle.utils.soap import SOAPClient
|
25 |
28 |
|
26 |
29 |
WSDL = 'tests/data/soap.wsdl'
|
... | ... | |
79 |
82 |
assert result['price'] == 4.2
|
80 |
83 |
|
81 |
84 |
|
82 |
|
@mock.patch('requests.sessions.Session.post')
|
83 |
|
def test_remove_first_bytes_for_xml(mocked_post):
|
|
85 |
@mock.patch('requests.sessions.Session.send')
|
|
86 |
def test_remove_first_bytes_for_xml(mocked_send, caplog):
|
84 |
87 |
response = requests.Response()
|
85 |
88 |
response.status_code = 200
|
86 |
|
response._content = force_bytes(
|
|
89 |
response.headers = {'Content-Type': 'application/xml'}
|
|
90 |
response._content = b'\x8b' + force_bytes(
|
87 |
91 |
'''blabla \n<?xml version='1.0' encoding='utf-8'?>
|
88 |
92 |
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
|
89 |
93 |
<soap-env:Body>
|
... | ... | |
94 |
98 |
</soap-env:Body>
|
95 |
99 |
</soap-env:Envelope>\n bloublou'''
|
96 |
100 |
)
|
97 |
|
mocked_post.return_value = response
|
|
101 |
mocked_send.return_value = response
|
98 |
102 |
|
99 |
103 |
soap_resource = SOAPResource()
|
|
104 |
logger = logging.getLogger('soap_resource')
|
|
105 |
logger.setLevel(logging.INFO)
|
|
106 |
soap_resource.requests = Request(logger=logger)
|
100 |
107 |
|
101 |
108 |
client = SOAPClient(soap_resource)
|
102 |
109 |
with pytest.raises(TransportError):
|
... | ... | |
107 |
114 |
assert len(result) == 2
|
108 |
115 |
assert result['skipMe'] == 1.2
|
109 |
116 |
assert result['price'] == 4.2
|
|
117 |
|
|
118 |
assert len(caplog.records) == 2
|
|
119 |
assert 'response_content' not in caplog.records[-1].__dict__
|
|
120 |
logger.setLevel(logging.DEBUG)
|
|
121 |
result = client.service.GetLastTradePrice(tickerSymbol='banana')
|
|
122 |
assert len(caplog.records) == 3
|
|
123 |
assert 'response_content' in caplog.records[-1].__dict__
|
110 |
|
-
|