-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathwsgi_soap_application_test.py
58 lines (52 loc) · 2.11 KB
/
wsgi_soap_application_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import io
import unittest
from soapfish.soap_dispatch import SOAPDispatcher, WsgiSoapApplication
from soapfish.testutil import echo_service
class WsgiSoapApplicationTest(unittest.TestCase):
def test_can_dispatch_soap_request_with_plain_wsgi(self):
dispatcher = SOAPDispatcher(echo_service())
app = WsgiSoapApplication(dispatcher)
start_response = self._response_mock()
soap_message = (
b'<?xml version="1.0" encoding="utf-8"?>'
b'<senv:Envelope xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://soap.example/echo/types">'
b'<senv:Body>'
b'<ns1:echoRequest xmlns:ns1="http://soap.example/echo/types">'
b'<value>foobar</value>'
b'</ns1:echoRequest>'
b'</senv:Body>'
b'</senv:Envelope>'
)
response = app(self._wsgi_env(soap_message), start_response)
self.assertEqual('200 OK', start_response.code)
self.assertEqual('text/xml', dict(start_response.headers)['Content-Type'])
expected_xml = (
b'<ns0:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/">'
b'<ns0:Body>'
b'<ns0:echoResponse xmlns:ns0="http://soap.example/echo/types">'
b'<value>foobar</value>'
b'</ns0:echoResponse>'
b'</ns0:Body>'
b'</ns0:Envelope>'
)
self.assertEqual(expected_xml, b''.join(response))
def _response_mock(self):
class StartResponse():
self.code = None
self.headers = None
def __call__(self, code, headers):
self.code = code
self.headers = headers
return StartResponse()
def _wsgi_env(self, soap_xml):
return {
'SOAPACTION': 'echo',
'PATH_INFO': '/service',
'CONTENT_LENGTH': len(soap_xml),
'QUERY_STRING': '',
'SERVER_NAME': 'localhost',
'SERVER_PORT': '7000',
'REQUEST_METHOD': 'POST',
'wsgi.url_scheme': 'http',
'wsgi.input': io.BytesIO(soap_xml),
}