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))
def send_sms(self, to_addr, content, message_id, linkid=None): """ Send an SMS. """ def _extractRequestIdentifier((body, header)): return gettext(body, './/' + str(SEND_NS.result), default='') body = SEND_NS.sendSms( SEND_NS.addresses(format_address(to_addr)), SEND_NS.message(content), SEND_NS.receiptRequest( L.endpoint(self.endpoint), L.interfaceName(u'SmsNotification'), L.correlator(message_id))) header = self._make_header( service_subscription_address=to_addr, linkid=linkid) d = self.perform_soap_request( uri=self.send_uri, action='', body=body, header=header, expected_faults=[PolicyException, ServiceException]) d.addCallback(_extractRequestIdentifier) return d
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))))
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))))
def create_sms_delivery_receipt(correlator, address, delivery_status): """ Helper for creating an ``notifySmsDeliveryReceipt`` element. """ return NOTIFICATION_NS.notifySmsDeliveryReceipt( NOTIFICATION_NS.correlator(correlator), NOTIFICATION_NS.deliveryStatus( L.address(format_address(normalize_address(address))), L.deliveryStatus(delivery_status.name)))
def test_children_multiple(self): """ Multiple child elements with the same tag name are coalesced into a ``list``. """ self.assertEqual( {'root': {'child': [{'@attr': 'value'}, 'hello']}}, element_to_dict( L.root(L.child(attr='value'), L.child('hello'))))
def test_children_text(self): """ Child elements are recursively nested. An element containing only text content, has its text keyed against its tag name. """ self.assertEqual({'root': { 'child': 'hello' }}, element_to_dict(L.root(L.child('hello'))))
def test_children_multiple(self): """ Multiple child elements with the same tag name are coalesced into a ``list``. """ self.assertEqual({'root': { 'child': [{ '@attr': 'value' }, 'hello'] }}, element_to_dict(L.root(L.child(attr='value'), L.child('hello'))))
def test_children_text(self): """ Child elements are recursively nested. An element containing only text content, has its text keyed against its tag name. """ self.assertEqual( {'root': {'child': 'hello'}}, element_to_dict( L.root(L.child('hello'))))
def test_children_text_attributes(self): """ Child elements are recursively nested. An element containing attributes and text content, has its attributes, prefixed with an ``@`` keyed against its tag name and its text keyed against ``#text``. """ self.assertEqual( {'root': {'child': {'#text': 'hello', '@attr': 'value'}}}, element_to_dict(L.root(L.child('hello', attr='value'))))
def test_from_element(self): """ `ServiceExceptionDetail.from_element` returns a `ServiceExceptionDetail` instance by parsing a ``ServiceExceptionDetail`` detail element. """ elem = PARLAYX_COMMON_NS.ServiceExceptionDetail( L.messageId('a'), L.text('b'), L.variables('c'), L.variables('d')) detail = ServiceExceptionDetail.from_element(elem) self.assertEqual(('a', 'b', ['c', 'd']), (detail.message_id, detail.text, detail.variables))
def create_sms_reception_element(correlator, message, sender_address, service_activation_number): """ Helper for creating an ``notifySmsReception`` element. """ return NOTIFICATION_NS.notifySmsReception( NOTIFICATION_NS.correlator(correlator), NOTIFICATION_NS.message( L.message(message), L.senderAddress(format_address(normalize_address(sender_address))), L.smsServiceActivationNumber(service_activation_number)))
def test_children_attributes(self): """ Child elements are recursively nested. An element containing only attributes, and no content, has its attributes, prefixed with an ``@`` keyed against its tag name. """ self.assertEqual( {'root': {'child': {'@attr': 'value'}}}, element_to_dict( L.root(L.child(attr='value'))))
def test_from_element_unknown_status(self): """ `DeliveryInformation.from_element` raises ``ValueError`` if an unknown ``DeliveryStatus`` enumeration value is specified. """ e = self.assertRaises( ValueError, DeliveryInformation.from_element, NOTIFICATION_NS.deliveryStatus(L.address('tel:27117654321'), L.deliveryStatus('WhatIsThis'))) self.assertEqual( "No such delivery status enumeration value: 'WhatIsThis'", str(e))
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)
def test_from_element_missing_timestamp(self): """ `SmsMessage.from_element` parses a ParlayX ``SmsMessage`` complex type, without a timestamp, into an `SmsMessage` instance. """ msg = SmsMessage.from_element( NOTIFICATION_NS.message(L.message('message'), L.senderAddress('tel:27117654321'), L.smsServiceActivationNumber('54321'))) self.assertEqual(('message', '+27117654321', '54321', None), (msg.message, msg.sender_address, msg.service_activation_number, msg.timestamp))
def test_children_attributes(self): """ Child elements are recursively nested. An element containing only attributes, and no content, has its attributes, prefixed with an ``@`` keyed against its tag name. """ self.assertEqual({'root': { 'child': { '@attr': 'value' } }}, element_to_dict(L.root(L.child(attr='value'))))
def test_from_element_unknown_status(self): """ `DeliveryInformation.from_element` raises ``ValueError`` if an unknown ``DeliveryStatus`` enumeration value is specified. """ e = self.assertRaises(ValueError, DeliveryInformation.from_element, NOTIFICATION_NS.deliveryStatus( L.address('tel:27117654321'), L.deliveryStatus('WhatIsThis'))) self.assertEqual( "No such delivery status enumeration value: 'WhatIsThis'", str(e))
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)
def test_from_element(self): """ `DeliveryInformation.from_element` parses a ParlayX ``DeliveryInformation`` complex type into a `DeliveryInformation` instance. Known ``DeliveryStatus`` enumeration values are parsed into `DeliveryStatus` attributes. """ info = DeliveryInformation.from_element( NOTIFICATION_NS.deliveryStatus( L.address('tel:27117654321'), L.deliveryStatus('DeliveredToNetwork'))) self.assertEqual(('+27117654321', DeliveryStatus.DeliveredToNetwork), (info.address, info.delivery_status))
def test_from_element(self): """ `DeliveryInformation.from_element` parses a ParlayX ``DeliveryInformation`` complex type into a `DeliveryInformation` instance. Known ``DeliveryStatus`` enumeration values are parsed into `DeliveryStatus` attributes. """ info = DeliveryInformation.from_element( NOTIFICATION_NS.deliveryStatus( L.address('tel:27117654321'), L.deliveryStatus('DeliveredToNetwork'))) self.assertEqual( ('+27117654321', DeliveryStatus.DeliveredToNetwork), (info.address, info.delivery_status))
def test_from_element_missing_timestamp(self): """ `SmsMessage.from_element` parses a ParlayX ``SmsMessage`` complex type, without a timestamp, into an `SmsMessage` instance. """ msg = SmsMessage.from_element( NOTIFICATION_NS.message( L.message('message'), L.senderAddress('tel:27117654321'), L.smsServiceActivationNumber('54321'))) self.assertEqual( ('message', '+27117654321', '54321', None), (msg.message, msg.sender_address, msg.service_activation_number, msg.timestamp))
def test_children_text_attributes(self): """ Child elements are recursively nested. An element containing attributes and text content, has its attributes, prefixed with an ``@`` keyed against its tag name and its text keyed against ``#text``. """ self.assertEqual( {'root': { 'child': { '#text': 'hello', '@attr': 'value' } }}, element_to_dict(L.root(L.child('hello', attr='value'))))
def test_empty(self): """ An empty element produces a ``None`` value keyed against its tag name. """ self.assertEqual( {'root': None}, element_to_dict(L.root()))
def test_send_sms_policy_fault(self): """ `ParlayXClient.send_sms` expects `PolicyExceptionDetail` fault details in SOAP requests that fail for remote policy-related reasons. """ detail = PARLAYX_COMMON_NS.PolicyExceptionDetail( L.messageId('a'), L.text('b'), L.variables('c'), L.variables('d')) client = self._make_client( MockResponse.build( http.INTERNAL_SERVER_ERROR, soap_fault('soapenv:Server', 'Whoops', detail=detail))) f = self.failureResultOf( client.send_sms('+27117654321', 'content', 'message_id'), PolicyException) detail = f.value.parsed_detail self.assertEqual(('a', 'b', ['c', 'd']), (detail.message_id, detail.text, detail.variables))
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()))
def test_stop_sms_notification_service_fault(self): """ `ParlayXClient.stop_sms_notification` expects `ServiceExceptionDetail` fault details in SOAP requests that fail for remote service-related reasons. """ detail = PARLAYX_COMMON_NS.ServiceExceptionDetail( L.messageId('a'), L.text('b'), L.variables('c'), L.variables('d')) client = self._make_client( MockResponse.build( http.INTERNAL_SERVER_ERROR, soap_fault('soapenv:Server', 'Whoops', detail=detail))) f = self.failureResultOf(client.stop_sms_notification(), ServiceException) detail = f.value.parsed_detail self.assertEqual(('a', 'b', ['c', 'd']), (detail.message_id, detail.text, detail.variables))
def test_empty_attributes(self): """ An element containing only attributes, and no content, has its attributes, prefixed with an ``@`` keyed against its tag name. """ self.assertEqual( {'root': {'@attr': 'value'}}, element_to_dict(L.root(attr='value')))
def test_text(self): """ An element containing only text content, has its text keyed against its tag name. """ self.assertEqual( {'root': 'hello'}, element_to_dict(L.root('hello')))
def test_empty_attributes(self): """ An element containing only attributes, and no content, has its attributes, prefixed with an ``@`` keyed against its tag name. """ self.assertEqual({'root': { '@attr': 'value' }}, element_to_dict(L.root(attr='value')))
def test_from_element(self): """ `SmsMessage.from_element` parses a ParlayX ``SmsMessage`` complex type, with an ISO8601 timestamp, into an `SmsMessage` instance. """ timestamp = datetime( 2013, 6, 12, 13, 15, 0, tzinfo=iso8601.iso8601.Utc()) msg = SmsMessage.from_element( NOTIFICATION_NS.message( L.message('message'), L.senderAddress('tel:27117654321'), L.smsServiceActivationNumber('54321'), L.dateTime('2013-06-12T13:15:00'))) self.assertEqual( ('message', '+27117654321', '54321', timestamp), (msg.message, msg.sender_address, msg.service_activation_number, msg.timestamp))
def test_namespaced(self): """ `element_to_dict` supports namespaced element names and namespaced attributes. """ ns = Namespace('http://example.com', 'ex') self.assertEqual( {str(ns.root): { 'child': [ {'@' + str(ns.attr): 'value'}, {'@attr2': 'value2', '#text': 'hello'}, 'world']}}, element_to_dict( ns.root( L.child({ns.attr: 'value'}), L.child('hello', attr2='value2'), L.child('world'))))
def test_process_empty(self): """ `SmsNotificationService.process` raises `SoapFault` if there are no actionable child elements in the request body. """ service = SmsNotificationService(None, None) exc = self.assertRaises(SoapFault, service.process, None, L.root()) self.assertEqual(('soapenv:Client', 'No actionable items'), (exc.code, str(exc)))
def start_sms_notification(self): """ Register a notification delivery endpoint with the remote ParlayX service. """ body = NOTIFICATION_MANAGER_NS.startSmsNotification( NOTIFICATION_MANAGER_NS.reference( L.endpoint(self.endpoint), L.interfaceName('notifySmsReception'), L.correlator(self._service_correlator)), NOTIFICATION_MANAGER_NS.smsServiceActivationNumber( self.short_code)) header = self._make_header() return self.perform_soap_request(uri=self.notification_uri, action='', body=body, header=header, expected_faults=[ServiceException])
def setUp(self): self.root = L.top( L.a('hello'), L.b('42'), L.b('24'), L.c('Foo'), L.d, L.sub( L.e('world'), L.e('all'), L.f))
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))
def start_sms_notification(self): """ Register a notification delivery endpoint with the remote ParlayX service. """ body = NOTIFICATION_MANAGER_NS.startSmsNotification( NOTIFICATION_MANAGER_NS.reference( L.endpoint(self.endpoint), L.interfaceName('notifySmsReception'), L.correlator(self._service_correlator)), NOTIFICATION_MANAGER_NS.smsServiceActivationNumber( self.short_code)) header = self._make_header() return self.perform_soap_request( uri=self.notification_uri, action='', body=body, header=header, expected_faults=[ServiceException])
def test_typemap(self): """ Providing a type map to `ElementMaker` allows the caller to specify how to serialize types other than strings and dictionaries. """ E = ElementMaker(typemap={ float: lambda e, v: '%0.2f' % (v, ), int: lambda e, v: L.int(str(v)) }) self.assertEqual('<tag>2.50</tag>', tostring(E('tag', 2.5))) self.assertEqual('<tag><int>42</int></tag>', tostring(E('tag', 42)))
def test_process_empty(self): """ `SmsNotificationService.process` raises `SoapFault` if there are no actionable child elements in the request body. """ service = SmsNotificationService(None, None) exc = self.assertRaises(SoapFault, service.process, None, L.root()) self.assertEqual( ('soapenv:Client', 'No actionable items'), (exc.code, str(exc)))
def test_namespaced(self): """ `element_to_dict` supports namespaced element names and namespaced attributes. """ ns = Namespace('http://example.com', 'ex') self.assertEqual( { str(ns.root): { 'child': [{ '@' + str(ns.attr): 'value' }, { '@attr2': 'value2', '#text': 'hello' }, 'world'] } }, element_to_dict( ns.root(L.child({ns.attr: 'value'}), L.child('hello', attr2='value2'), L.child('world'))))
def test_process_unknown(self): """ `SmsNotificationService.process` invokes `SmsNotificationService.process_unknown`, for handling otherwise unknown requests, which raises `SoapFault`. """ service = SmsNotificationService(None, None) exc = self.assertRaises(SoapFault, service.process, None, L.root(L.WhatIsThis)) self.assertEqual(('soapenv:Server', 'No handler for WhatIsThis'), (exc.code, str(exc)))
def test_from_element(self): """ `SmsMessage.from_element` parses a ParlayX ``SmsMessage`` complex type, with an ISO8601 timestamp, into an `SmsMessage` instance. """ timestamp = datetime(2013, 6, 12, 13, 15, 0, tzinfo=iso8601.iso8601.Utc()) msg = SmsMessage.from_element( NOTIFICATION_NS.message(L.message('message'), L.senderAddress('tel:27117654321'), L.smsServiceActivationNumber('54321'), L.dateTime('2013-06-12T13:15:00'))) self.assertEqual(('message', '+27117654321', '54321', timestamp), (msg.message, msg.sender_address, msg.service_activation_number, msg.timestamp))
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))
def test_process_unknown(self): """ `SmsNotificationService.process` invokes `SmsNotificationService.process_unknown`, for handling otherwise unknown requests, which raises `SoapFault`. """ service = SmsNotificationService(None, None) exc = self.assertRaises(SoapFault, service.process, None, L.root(L.WhatIsThis)) self.assertEqual( ('soapenv:Server', 'No handler for WhatIsThis'), (exc.code, str(exc)))
def stop_sms_notification(self): """ Deregister notification delivery with the remote ParlayX service. """ body = NOTIFICATION_MANAGER_NS.stopSmsNotification( L.correlator(self._service_correlator)) header = self._make_header() return self.perform_soap_request(uri=self.notification_uri, action='', body=body, header=header, expected_faults=[ServiceException])
def stop_sms_notification(self): """ Deregister notification delivery with the remote ParlayX service. """ body = NOTIFICATION_MANAGER_NS.stopSmsNotification( L.correlator(self._service_correlator)) header = self._make_header() return self.perform_soap_request( uri=self.notification_uri, action='', body=body, header=header, expected_faults=[ServiceException])
def test_typemap(self): """ Providing a type map to `ElementMaker` allows the caller to specify how to serialize types other than strings and dictionaries. """ E = ElementMaker(typemap={ float: lambda e, v: '%0.2f' % (v,), int: lambda e, v: L.int(str(v))}) self.assertEqual( '<tag>2.50</tag>', tostring(E('tag', 2.5))) self.assertEqual( '<tag><int>42</int></tag>', tostring(E('tag', 42)))
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))
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()))
def send_sms(self, to_addr, content, message_id, linkid=None): """ Send an SMS. """ def _extractRequestIdentifier((body, header)): return gettext(body, './/' + str(SEND_NS.result), default='') body = SEND_NS.sendSms( SEND_NS.addresses(format_address(to_addr)), SEND_NS.message(content), SEND_NS.receiptRequest(L.endpoint(self.endpoint), L.interfaceName(u'SmsNotification'), L.correlator(message_id))) header = self._make_header(service_subscription_address=to_addr, linkid=linkid) d = self.perform_soap_request( uri=self.send_uri, action='', body=body, header=header, expected_faults=[PolicyException, ServiceException]) d.addCallback(_extractRequestIdentifier) return d
def soap_fault(faultcode, faultstring=None, faultactor=None, detail=None): """ Create a SOAP fault response. """ def _maybe(f, value): if value is not None: return f(value) return None xs = [ LocalNamespace.faultcode(faultcode), _maybe(LocalNamespace.faultstring, faultstring), _maybe(LocalNamespace.faultactor, faultactor), _maybe(LocalNamespace.detail, detail)] # filter(None, xs) doesn't do what we want because of weird implicit # truthiness with ElementTree elements. return SOAP_ENV.Fault(*[x for x in xs if x is not None])
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))))
def soap_fault(faultcode, faultstring=None, faultactor=None, detail=None): """ Create a SOAP fault response. """ def _maybe(f, value): if value is not None: return f(value) return None xs = [ LocalNamespace.faultcode(faultcode), _maybe(LocalNamespace.faultstring, faultstring), _maybe(LocalNamespace.faultactor, faultactor), _maybe(LocalNamespace.detail, detail) ] # filter(None, xs) doesn't do what we want because of weird implicit # truthiness with ElementTree elements. return SOAP_ENV.Fault(*[x for x in xs if x is not None])
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))))
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))
def setUp(self): self.root = L.parent( L.child1, L.child2, L.child2, L.child3)
def test_text(self): """ An element containing only text content, has its text keyed against its tag name. """ self.assertEqual({'root': 'hello'}, element_to_dict(L.root('hello')))