Exemplo n.º 1
0
 def test_unmatched(self):
     """
     `PolicyExceptionDetail.from_element` returns ``None`` if the element's
     tag is not a policy exception detail.
     """
     elem = L.WhatIsThis(L.foo('a'), L.bar('b'))
     self.assertIdentical(None, PolicyExceptionDetail.from_element(elem))
Exemplo n.º 2
0
    def test_expected_faults(self):
        """
        `SoapFault.from_element` creates an instance of a specified `SoapFault`
        subclass if a fault detail of a recognised type occurs.
        """
        detail = [
            L.WhatIsThis(L.foo('a'), L.bar('b')),
            L.ToyFaultDetail(L.foo('c'), L.bar('d'))
        ]

        fault = SoapFault.from_element(_make_fault('soapenv:Client',
                                                   'message',
                                                   'actor',
                                                   detail=detail),
                                       expected_faults=[ToyFault])
        self.assertEqual(('soapenv:Client', 'message', 'actor'),
                         (fault.code, fault.string, fault.actor))
        parsed_detail = fault.parsed_detail
        self.assertEqual(('c', 'd'), (parsed_detail.foo, parsed_detail.bar))
Exemplo n.º 3
0
    def test_from_element(self):
        """
        `SoapFault.from_element` creates a `SoapFault` instance from an
        ElementTree element and parses known SOAP fault details.
        """
        detail = L.ToyFaultDetail(L.foo('a'), L.bar('b'))

        fault = SoapFault.from_element(
            _make_fault('soapenv:Client', 'message', 'actor', detail=detail))
        self.assertEqual(('soapenv:Client', 'message', 'actor'),
                         (fault.code, fault.string, fault.actor))
        self.assertIdentical(None, fault.parsed_detail)
Exemplo n.º 4
0
    def test_from_element(self):
        """
        `SoapFault.from_element` creates a `SoapFault` instance from an
        ElementTree element and parses known SOAP fault details.
        """
        detail = L.ToyFaultDetail(L.foo('a'), L.bar('b'))

        fault = SoapFault.from_element(_make_fault(
            'soapenv:Client', 'message', 'actor', detail=detail))
        self.assertEqual(
            ('soapenv:Client', 'message', 'actor'),
            (fault.code, fault.string, fault.actor))
        self.assertIdentical(None, fault.parsed_detail)
Exemplo n.º 5
0
    def test_expected_faults(self):
        """
        `SoapFault.from_element` creates an instance of a specified `SoapFault`
        subclass if a fault detail of a recognised type occurs.
        """
        detail = [
            L.WhatIsThis(
                L.foo('a'),
                L.bar('b')),
            L.ToyFaultDetail(
                L.foo('c'),
                L.bar('d'))]

        fault = SoapFault.from_element(_make_fault(
            'soapenv:Client', 'message', 'actor', detail=detail),
            expected_faults=[ToyFault])
        self.assertEqual(
            ('soapenv:Client', 'message', 'actor'),
            (fault.code, fault.string, fault.actor))
        parsed_detail = fault.parsed_detail
        self.assertEqual(
            ('c', 'd'),
            (parsed_detail.foo, parsed_detail.bar))
Exemplo n.º 6
0
    def test_to_element(self):
        """
        `SoapFault.to_element` serializes the fault to a SOAP ``Fault``
        ElementTree element.
        """
        detail = L.ToyFaultDetail(L.foo('a'), L.bar('b'))

        fault = SoapFault.from_element(_make_fault(
            'soapenv:Client', 'message', 'actor', detail=detail))
        self.assertEqual(
            {str(SOAP_ENV.Fault): {
                'faultcode': fault.code,
                'faultstring': fault.string,
                'faultactor': fault.actor,
                'detail': {
                    'ToyFaultDetail': {'foo': 'a', 'bar': 'b'}}}},
            element_to_dict(fault.to_element()))
Exemplo n.º 7
0
 def test_expected_fault(self):
     """
     `perform_soap_request` raises a `SoapFault` subclass when a SOAP fault
     detail matches one of the expected fault types.
     """
     detail = L.ToyFaultDetail(L.foo('a'), L.bar('b'))
     response = MockResponse.build(
         http.INTERNAL_SERVER_ERROR,
         soap_fault('soapenv:Server', 'Whoops', detail=detail))
     f = self.failureResultOf(
         self._perform_soap_request(response,
                                    'uri',
                                    'action',
                                    'request',
                                    expected_faults=[ToyFault]), ToyFault)
     self.assertEqual(('soapenv:Server', 'Whoops'),
                      (f.value.code, f.getErrorMessage()))
     parsed_detail = f.value.parsed_detail
     self.assertEqual(('a', 'b'), (parsed_detail.foo, parsed_detail.bar))
Exemplo n.º 8
0
 def test_expected_fault(self):
     """
     `perform_soap_request` raises a `SoapFault` subclass when a SOAP fault
     detail matches one of the expected fault types.
     """
     detail = L.ToyFaultDetail(L.foo('a'), L.bar('b'))
     response = MockResponse.build(
         http.INTERNAL_SERVER_ERROR,
         soap_fault('soapenv:Server', 'Whoops', detail=detail))
     f = self.failureResultOf(
         self._perform_soap_request(
             response, 'uri', 'action', 'request',
             expected_faults=[ToyFault]),
         ToyFault)
     self.assertEqual(
         ('soapenv:Server', 'Whoops'),
         (f.value.code, f.getErrorMessage()))
     parsed_detail = f.value.parsed_detail
     self.assertEqual(
         ('a', 'b'),
         (parsed_detail.foo, parsed_detail.bar))
Exemplo n.º 9
0
    def test_to_element(self):
        """
        `SoapFault.to_element` serializes the fault to a SOAP ``Fault``
        ElementTree element.
        """
        detail = L.ToyFaultDetail(L.foo('a'), L.bar('b'))

        fault = SoapFault.from_element(
            _make_fault('soapenv:Client', 'message', 'actor', detail=detail))
        self.assertEqual(
            {
                str(SOAP_ENV.Fault): {
                    'faultcode': fault.code,
                    'faultstring': fault.string,
                    'faultactor': fault.actor,
                    'detail': {
                        'ToyFaultDetail': {
                            'foo': 'a',
                            'bar': 'b'
                        }
                    }
                }
            }, element_to_dict(fault.to_element()))