예제 #1
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)
예제 #2
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)
예제 #3
0
 def test_to_element_no_detail(self):
     """
     `SoapFault.to_element` serializes the fault to a SOAP ``Fault``
     ElementTree element, omitting the ``detail`` element if
     `SoapFault.detail` is None.
     """
     fault = SoapFault.from_element(_make_fault(
         'soapenv:Client', 'message', 'actor'))
     self.assertEqual(
         {str(SOAP_ENV.Fault): {
             'faultcode': fault.code,
             'faultstring': fault.string,
             'faultactor': fault.actor}},
         element_to_dict(fault.to_element()))
예제 #4
0
 def test_to_element_no_detail(self):
     """
     `SoapFault.to_element` serializes the fault to a SOAP ``Fault``
     ElementTree element, omitting the ``detail`` element if
     `SoapFault.detail` is None.
     """
     fault = SoapFault.from_element(
         _make_fault('soapenv:Client', 'message', 'actor'))
     self.assertEqual(
         {
             str(SOAP_ENV.Fault): {
                 'faultcode': fault.code,
                 'faultstring': fault.string,
                 'faultactor': fault.actor
             }
         }, element_to_dict(fault.to_element()))
예제 #5
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()))
예제 #6
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))
예제 #7
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()))
예제 #8
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))