コード例 #1
0
ファイル: soaputil.py プロジェクト: AndrewCvekl/vumi
def parse_soap_fault(body, expected_faults=None):
    """
    Parse a SOAP fault element and its details.

    :param body: SOAP ``Body`` element.
    :param expected_faults:
        A `list` of `SoapFault` subclasses whose ``detail_type`` attribute will
        be used to determine a match against each top-level SOAP fault detail
        element.
    :return:
        A 2-tuple of: matching exception type and an instance of it's
        ``detail_type``; and SOAP fault information (code, string, actor,
        detail). ``None`` if there is no SOAP fault.
    """
    fault = elemfind(body, SOAP_ENV.Fault)
    if fault is None:
        return None
    faultcode = gettext(fault, u'faultcode')
    faultstring = gettext(fault, u'faultstring')
    faultactor = gettext(fault, u'faultactor')
    detail = elemfind(fault, u'detail')

    if expected_faults is None:
        expected_faults = []
    parsed = _parse_expected_faults(detail, expected_faults)
    return parsed, (faultcode, faultstring, faultactor, detail)
コード例 #2
0
ファイル: test_client.py プロジェクト: musabaloyi/vumi
 def test_stop_sms_notification(self):
     """
     `ParlayXClient.stop_sms_notification` performs a SOAP request to the
     remote ParlayX notification endpoint indicating that delivery and
     receipt notifications for a particular service activation number can be
     deactivated.
     """
     client = self._make_client(
         MockResponse.build(
             http.OK, NOTIFICATION_MANAGER_NS.stopSmsNotificationResponse))
     client._now = partial(datetime, 2013, 6, 18, 10, 59, 33)
     self.successResultOf(client.stop_sms_notification())
     self.assertEqual(1, len(self.requests))
     self.assertEqual('notification', self.requests[0][0])
     body, header = unwrap_soap_envelope(fromstring(self.requests[0][1]))
     self.assertEqual(
         {
             str(NOTIFICATION_MANAGER_NS.stopSmsNotification): {
                 'correlator': client._service_correlator
             }
         },
         element_to_dict(
             elemfind(body, NOTIFICATION_MANAGER_NS.stopSmsNotification)))
     self.assertEqual(
         {
             str(PARLAYX_HEAD_NS.RequestSOAPHeader): {
                 str(PARLAYX_HEAD_NS.serviceId): 'service_id',
                 str(PARLAYX_HEAD_NS.spId): 'user',
                 str(PARLAYX_HEAD_NS.spPassword):
                 '1f2e67e642b16f6623459fa76dc3894f',
                 str(PARLAYX_HEAD_NS.timeStamp): '20130618105933'
             }
         },
         element_to_dict(elemfind(header,
                                  PARLAYX_HEAD_NS.RequestSOAPHeader)))
コード例 #3
0
def parse_soap_fault(body, expected_faults=None):
    """
    Parse a SOAP fault element and its details.

    :param body: SOAP ``Body`` element.
    :param expected_faults:
        A `list` of `SoapFault` subclasses whose ``detail_type`` attribute will
        be used to determine a match against each top-level SOAP fault detail
        element.
    :return:
        A 2-tuple of: matching exception type and an instance of it's
        ``detail_type``; and SOAP fault information (code, string, actor,
        detail). ``None`` if there is no SOAP fault.
    """
    fault = elemfind(body, SOAP_ENV.Fault)
    if fault is None:
        return None
    faultcode = gettext(fault, u'faultcode')
    faultstring = gettext(fault, u'faultstring')
    faultactor = gettext(fault, u'faultactor')
    detail = elemfind(fault, u'detail')

    if expected_faults is None:
        expected_faults = []
    parsed = _parse_expected_faults(detail, expected_faults)
    return parsed, (faultcode, faultstring, faultactor, detail)
コード例 #4
0
ファイル: soaputil.py プロジェクト: AndrewCvekl/vumi
def unwrap_soap_envelope(root):
    """
    Unwrap a SOAP request and return the SOAP header and body elements.
    """
    header = elemfind(root, SOAP_ENV.Header)
    body = elemfind(root, SOAP_ENV.Body)
    if body is None:
        raise SoapFault(u'soapenv:Client', u'Malformed SOAP request')
    return body, header
コード例 #5
0
def unwrap_soap_envelope(root):
    """
    Unwrap a SOAP request and return the SOAP header and body elements.
    """
    header = elemfind(root, SOAP_ENV.Header)
    body = elemfind(root, SOAP_ENV.Body)
    if body is None:
        raise SoapFault(u'soapenv:Client', u'Malformed SOAP request')
    return body, header
コード例 #6
0
ファイル: test_xmlutil.py プロジェクト: AndrewCvekl/vumi
 def test_elemfind(self):
     """
     `elemfind` finds the first `QualifiedName` or path specified.
     """
     self.assertEqual(
         '<child1 />',
         tostring(elemfind(self.root, 'child1')))
     self.assertEqual(
         '<child2 />',
         tostring(elemfind(self.root, L.child2)))
コード例 #7
0
ファイル: test_client.py プロジェクト: musabaloyi/vumi
    def test_send_sms(self):
        """
        `ParlayXClient.send_sms` performs a SOAP request to the
        remote ParlayX send endpoint to deliver a message via SMS.
        """
        client = self._make_client(
            MockResponse.build(
                http.OK, SEND_NS.sendSmsResponse(SEND_NS.result('reference'))))
        client._now = partial(datetime, 2013, 6, 18, 10, 59, 33)
        response = self.successResultOf(
            client.send_sms('+27117654321', 'content', 'message_id', 'linkid'))
        self.assertEqual('reference', response)
        self.assertEqual(1, len(self.requests))
        self.assertEqual('send', self.requests[0][0])

        body, header = unwrap_soap_envelope(fromstring(self.requests[0][1]))
        self.assertEqual(
            {
                str(SEND_NS.sendSms): {
                    str(SEND_NS.addresses): 'tel:27117654321',
                    str(SEND_NS.message): 'content',
                    str(SEND_NS.receiptRequest): {
                        'correlator': 'message_id',
                        'endpoint': 'endpoint',
                        'interfaceName': 'SmsNotification'
                    }
                }
            }, element_to_dict(elemfind(body, SEND_NS.sendSms)))
        self.assertEqual(
            {
                str(PARLAYX_HEAD_NS.RequestSOAPHeader): {
                    str(PARLAYX_HEAD_NS.serviceId): 'service_id',
                    str(PARLAYX_HEAD_NS.spId): 'user',
                    str(PARLAYX_HEAD_NS.spPassword):
                    '1f2e67e642b16f6623459fa76dc3894f',
                    str(PARLAYX_HEAD_NS.timeStamp): '20130618105933',
                    str(PARLAYX_HEAD_NS.linkid): 'linkid',
                    str(PARLAYX_HEAD_NS.OA): 'tel:27117654321'
                }
            },
            element_to_dict(elemfind(header,
                                     PARLAYX_HEAD_NS.RequestSOAPHeader)))
コード例 #8
0
ファイル: server.py プロジェクト: musabaloyi/vumi
 def process_notifySmsDeliveryReceipt(self, root, header, name):
     """
     Process a text message delivery receipt.
     """
     correlator = gettext(root, NOTIFICATION_NS.correlator)
     delivery_info = DeliveryInformation.from_element(
         elemfind(root, NOTIFICATION_NS.deliveryStatus))
     d = maybeDeferred(self.callback_message_delivered,
         correlator, delivery_info.delivery_status.value)
     d.addCallback(
         lambda ignored: NOTIFICATION_NS.notifySmsDeliveryReceiptResponse())
     return d
コード例 #9
0
ファイル: server.py プロジェクト: musabaloyi/vumi
    def process_notifySmsReception(self, root, header, name):
        """
        Process a received text message.
        """
        linkid = None
        if header is not None:
            linkid = gettext(header, './/' + str(PARLAYX_COMMON_NS.linkid))

        correlator = gettext(root, NOTIFICATION_NS.correlator)
        message = SmsMessage.from_element(
            elemfind(root, NOTIFICATION_NS.message))
        d = maybeDeferred(
            self.callback_message_received, correlator, linkid, message)
        d.addCallback(
            lambda ignored: NOTIFICATION_NS.notifySmsReceptionResponse())
        return d
コード例 #10
0
ファイル: test_xmlutil.py プロジェクト: musabaloyi/vumi
 def test_elemfind_none(self):
     """
     `elemfind` returns ``None`` if the `QualifiedName` or path specified
     cannot be found.
     """
     self.assertIdentical(None, elemfind(self.root, L.what))
コード例 #11
0
ファイル: test_xmlutil.py プロジェクト: musabaloyi/vumi
 def test_elemfind(self):
     """
     `elemfind` finds the first `QualifiedName` or path specified.
     """
     self.assertEqual('<child1 />', tostring(elemfind(self.root, 'child1')))
     self.assertEqual('<child2 />', tostring(elemfind(self.root, L.child2)))
コード例 #12
0
ファイル: test_xmlutil.py プロジェクト: AndrewCvekl/vumi
 def test_elemfind_none(self):
     """
     `elemfind` returns ``None`` if the `QualifiedName` or path specified
     cannot be found.
     """
     self.assertIdentical(None, elemfind(self.root, L.what))