def test_soap_envelope(self): """ `soap_envelope` wraps content in a SOAP envelope element. """ self.assertEqual( '<soapenv:Envelope xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>' 'hello</soapenv:Body></soapenv:Envelope>', tostring(soap_envelope('hello'))) self.assertEqual( '<soapenv:Envelope xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>' '<tag>hello</tag></soapenv:Body></soapenv:Envelope>', tostring(soap_envelope(Element('tag', 'hello'))))
def test_soap_envelope(self): """ `soap_envelope` wraps content in a SOAP envelope element. """ self.assertEqual( '<soapenv:Envelope xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>' 'hello</soapenv:Body></soapenv:Envelope>', tostring(soap_envelope('hello'))) self.assertEqual( '<soapenv:Envelope xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>' '<tag>hello</tag></soapenv:Body></soapenv:Envelope>', tostring(soap_envelope(Element('tag', 'hello'))))
def test_unwrap_soap_envelope_header(self): """ `unwrap_soap_envelope` unwraps a SOAP envelope element, with a header, to a tuple of the SOAP body and header elements. """ body, header = unwrap_soap_envelope( soap_envelope(Element('tag', 'hello'), Element('header', 'value'))) self.assertEqual( '<soapenv:Header xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/">' '<header>value</header></soapenv:Header>', tostring(header)) self.assertEqual( '<soapenv:Body xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/">' '<tag>hello</tag></soapenv:Body>', tostring(body))
def test_unwrap_soap_envelope_header(self): """ `unwrap_soap_envelope` unwraps a SOAP envelope element, with a header, to a tuple of the SOAP body and header elements. """ body, header = unwrap_soap_envelope( soap_envelope( Element('tag', 'hello'), Element('header', 'value'))) self.assertEqual( '<soapenv:Header xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/">' '<header>value</header></soapenv:Header>', tostring(header)) self.assertEqual( '<soapenv:Body xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/">' '<tag>hello</tag></soapenv:Body>', tostring(body))
def test_soap_fault(self): """ `soap_fault` constructs a SOAP fault element from a code and description. """ self.assertEqual( '<soapenv:Fault xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/">' '<faultcode>soapenv:Client</faultcode>' '<faultstring>Oops.</faultstring></soapenv:Fault>', tostring(soap_fault('soapenv:Client', 'Oops.')))
def test_response_no_body(self): """ `perform_soap_request` raises `SoapFault` if the response contains no SOAP body element.. """ response = MockResponse(http.OK, tostring(SOAP_ENV.Envelope('hello'))) f = self.failureResultOf( self._perform_soap_request(response, 'uri', 'action', 'request'), SoapFault) self.assertEqual('soapenv:Client', f.value.code) self.assertEqual('Malformed SOAP request', f.getErrorMessage())
def test_soap_fault(self): """ `soap_fault` constructs a SOAP fault element from a code and description. """ self.assertEqual( '<soapenv:Fault xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/">' '<faultcode>soapenv:Client</faultcode>' '<faultstring>Oops.</faultstring></soapenv:Fault>', tostring(soap_fault('soapenv:Client', 'Oops.')))
def test_response_no_body(self): """ `perform_soap_request` raises `SoapFault` if the response contains no SOAP body element.. """ response = MockResponse(http.OK, tostring(SOAP_ENV.Envelope('hello'))) f = self.failureResultOf( self._perform_soap_request(response, 'uri', 'action', 'request'), SoapFault) self.assertEqual('soapenv:Client', f.value.code) self.assertEqual('Malformed SOAP request', f.getErrorMessage())
def test_unwrap_soap_envelope(self): """ `unwrap_soap_envelope` unwraps a SOAP envelope element, with no header, to a tuple of the SOAP body element and ``None``. """ body, header = unwrap_soap_envelope( soap_envelope(Element('tag', 'hello'))) self.assertIdentical(None, header) self.assertEqual( '<soapenv:Body xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/"><tag>hello</tag>' '</soapenv:Body>', tostring(body))
def test_unwrap_soap_envelope(self): """ `unwrap_soap_envelope` unwraps a SOAP envelope element, with no header, to a tuple of the SOAP body element and ``None``. """ body, header = unwrap_soap_envelope( soap_envelope(Element('tag', 'hello'))) self.assertIdentical(None, header) self.assertEqual( '<soapenv:Body xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/"><tag>hello</tag>' '</soapenv:Body>', tostring(body))
def test_success(self): """ `perform_soap_request` issues a SOAP request, over HTTP, to a URI, sets the ``SOAPAction`` header and parses the response as a SOAP envelope. """ response = MockResponse.build(http.OK, 'response', 'response_header') body, header = self.successResultOf( self._perform_soap_request(response, 'uri', 'action', 'request')) self.assertEqual([('uri', tostring(soap_envelope('request')), { 'SOAPAction': 'action', 'Content-Type': 'text/xml; charset="utf-8"' })], self.requests) self.assertEqual(SOAP_ENV.Body.text, body.tag) self.assertEqual('response', body.text) self.assertEqual(SOAP_ENV.Header.text, header.tag) self.assertEqual('response_header', header.text)
def test_success(self): """ `perform_soap_request` issues a SOAP request, over HTTP, to a URI, sets the ``SOAPAction`` header and parses the response as a SOAP envelope. """ response = MockResponse.build(http.OK, 'response', 'response_header') body, header = self.successResultOf( self._perform_soap_request(response, 'uri', 'action', 'request')) self.assertEqual([ ('uri', tostring(soap_envelope('request')), {'SOAPAction': 'action', 'Content-Type': 'text/xml; charset="utf-8"'})], self.requests) self.assertEqual(SOAP_ENV.Body.text, body.tag) self.assertEqual('response', body.text) self.assertEqual(SOAP_ENV.Header.text, header.tag) self.assertEqual('response_header', header.text)