コード例 #1
0
ファイル: test_soaputil.py プロジェクト: AndrewCvekl/vumi
 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'))))
コード例 #2
0
 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'))))
コード例 #3
0
ファイル: utils.py プロジェクト: AndrewCvekl/vumi
 def build(cls, code, body, header=None):
     """
     Build a `MockResponse` containing a SOAP envelope.
     """
     return cls(
         code=code,
         delivered_body=tostring(soap_envelope(body, header)))
コード例 #4
0
ファイル: test_server.py プロジェクト: musabaloyi/vumi
    def test_render_exceptions(self):
        """
        `SmsNotificationService.render_POST` logs any exceptions that occur
        during processing and writes a SOAP fault back to the request.
        """
        def process(*a, **kw):
            raise ValueError('What is this')

        service = SmsNotificationService(None, None)
        service.process = process
        request = DummyRequest([])
        request.content = StringIO(tostring(soap_envelope('hello')))
        d = request.notifyFinish()

        service.render_POST(request)
        self.successResultOf(d)
        self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
        failures = self.flushLoggedErrors(ValueError)
        self.assertEqual(1, len(failures))
        self.assertEqual(
            {
                str(SOAP_ENV.Envelope): {
                    str(SOAP_ENV.Body): {
                        str(SOAP_ENV.Fault): {
                            'faultcode': 'soapenv:Server',
                            'faultstring': 'What is this'
                        }
                    }
                }
            }, element_to_dict(fromstring(''.join(request.written))))
コード例 #5
0
ファイル: test_server.py プロジェクト: AndrewCvekl/vumi
    def test_render_exceptions(self):
        """
        `SmsNotificationService.render_POST` logs any exceptions that occur
        during processing and writes a SOAP fault back to the request.
        """
        def process(*a, **kw):
            raise ValueError('What is this')
        service = SmsNotificationService(None, None)
        service.process = process
        request = DummyRequest([])
        request.content = StringIO(tostring(soap_envelope('hello')))
        d = request.notifyFinish()

        service.render_POST(request)
        self.successResultOf(d)
        self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
        failures = self.flushLoggedErrors(ValueError)
        self.assertEqual(1, len(failures))
        self.assertEqual(
            {str(SOAP_ENV.Envelope): {
                str(SOAP_ENV.Body): {
                    str(SOAP_ENV.Fault): {
                        'faultcode': 'soapenv:Server',
                        'faultstring': 'What is this'}}}},
            element_to_dict(fromstring(''.join(request.written))))
コード例 #6
0
 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))
コード例 #7
0
ファイル: test_soaputil.py プロジェクト: AndrewCvekl/vumi
 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))
コード例 #8
0
 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))
コード例 #9
0
 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)
コード例 #10
0
ファイル: test_server.py プロジェクト: AndrewCvekl/vumi
 def test_render(self):
     """
     `SmsNotificationService.render_POST` parses a SOAP request and
     dispatches it to `SmsNotificationService.process` for processing.
     """
     service = SmsNotificationService(None, None)
     service.process = lambda *a, **kw: L.done()
     request = DummyRequest([])
     request.content = StringIO(tostring(soap_envelope('hello')))
     d = request.notifyFinish()
     service.render_POST(request)
     self.successResultOf(d)
     self.assertEqual(http.OK, request.responseCode)
     self.assertEqual(
         {str(SOAP_ENV.Envelope): {
             str(SOAP_ENV.Body): {
                 'done': None}}},
         element_to_dict(fromstring(''.join(request.written))))
コード例 #11
0
ファイル: test_soaputil.py プロジェクト: AndrewCvekl/vumi
 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)
コード例 #12
0
ファイル: test_server.py プロジェクト: musabaloyi/vumi
 def test_render(self):
     """
     `SmsNotificationService.render_POST` parses a SOAP request and
     dispatches it to `SmsNotificationService.process` for processing.
     """
     service = SmsNotificationService(None, None)
     service.process = lambda *a, **kw: L.done()
     request = DummyRequest([])
     request.content = StringIO(tostring(soap_envelope('hello')))
     d = request.notifyFinish()
     service.render_POST(request)
     self.successResultOf(d)
     self.assertEqual(http.OK, request.responseCode)
     self.assertEqual(
         {str(SOAP_ENV.Envelope): {
              str(SOAP_ENV.Body): {
                  'done': None
              }
          }}, element_to_dict(fromstring(''.join(request.written))))
コード例 #13
0
ファイル: test_soaputil.py プロジェクト: AndrewCvekl/vumi
 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))
コード例 #14
0
ファイル: utils.py プロジェクト: musabaloyi/vumi
 def build(cls, code, body, header=None):
     """
     Build a `MockResponse` containing a SOAP envelope.
     """
     return cls(code=code,
                delivered_body=tostring(soap_envelope(body, header)))
コード例 #15
0
ファイル: server.py プロジェクト: musabaloyi/vumi
 def _writeResponse(response):
     request.setHeader('Content-Type', 'text/xml; charset="utf-8"')
     request.write(tostring(soap_envelope(response)))
     request.finish()