Exemple #1
0
    def test_render_soap_fault(self):
        """
        `SmsNotificationService.render_POST` logs any exceptions that occur
        during processing and writes a SOAP fault back to the request. If the
        logged exception is a `SoapFault` its ``to_element`` method is invoked
        to serialize the fault.
        """
        service = SmsNotificationService(None, None)
        service.process = lambda *a, **kw: L.done()
        request = DummyRequest([])
        request.content = StringIO(tostring(L.hello()))
        d = request.notifyFinish()

        service.render_POST(request)
        self.successResultOf(d)
        self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
        failures = self.flushLoggedErrors(SoapFault)
        self.assertEqual(1, len(failures))
        self.assertEqual(
            {
                str(SOAP_ENV.Envelope): {
                    str(SOAP_ENV.Body): {
                        str(SOAP_ENV.Fault): {
                            'faultcode': 'soapenv:Client',
                            'faultstring': 'Malformed SOAP request'
                        }
                    }
                }
            }, element_to_dict(fromstring(''.join(request.written))))
Exemple #2
0
    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))))
Exemple #3
0
    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))))
Exemple #4
0
    def test_render_soap_fault(self):
        """
        `SmsNotificationService.render_POST` logs any exceptions that occur
        during processing and writes a SOAP fault back to the request. If the
        logged exception is a `SoapFault` its ``to_element`` method is invoked
        to serialize the fault.
        """
        service = SmsNotificationService(None, None)
        service.process = lambda *a, **kw: L.done()
        request = DummyRequest([])
        request.content = StringIO(tostring(L.hello()))
        d = request.notifyFinish()

        service.render_POST(request)
        self.successResultOf(d)
        self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
        failures = self.flushLoggedErrors(SoapFault)
        self.assertEqual(1, len(failures))
        self.assertEqual(
            {str(SOAP_ENV.Envelope): {
                str(SOAP_ENV.Body): {
                    str(SOAP_ENV.Fault): {
                        'faultcode': 'soapenv:Client',
                        'faultstring': 'Malformed SOAP request'}}}},
            element_to_dict(fromstring(''.join(request.written))))
Exemple #5
0
    def test_render_invalid_xml(self):
        """
        `SmsNotificationService.render_POST` does not accept invalid XML body
        content.
        """
        service = SmsNotificationService(None, None)
        request = DummyRequest([])
        request.content = StringIO('sup')
        d = request.notifyFinish()

        service.render_POST(request)
        self.successResultOf(d)
        self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
        failures = self.flushLoggedErrors(ParseError)
        self.assertEqual(1, len(failures))
Exemple #6
0
    def test_render_invalid_xml(self):
        """
        `SmsNotificationService.render_POST` does not accept invalid XML body
        content.
        """
        service = SmsNotificationService(None, None)
        request = DummyRequest([])
        request.content = StringIO('sup')
        d = request.notifyFinish()

        service.render_POST(request)
        self.successResultOf(d)
        self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
        failures = self.flushLoggedErrors(ParseError)
        self.assertEqual(1, len(failures))
Exemple #7
0
 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))))
Exemple #8
0
 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))))