Пример #1
0
    def asEtreeSubNode(self, rootNode):
        # To (OPTIONAL), defaults to anonymous
        node = etree_.SubElement(rootNode,
                                 wsaTag('To'),
                                 attrib={s12Tag('mustUnderstand'): 'true'})
        node.text = self.to or WSA_ANONYMOUS
        #From
        if self.from_:
            self.from_.asEtreeSubNode(rootNode)
        # ReplyTo (OPTIONAL), defaults to anonymous
        if self.replyTo:
            self.replyTo.asEtreeSubNode(rootNode)
        # FaultTo (OPTIONAL)
        if self.faultTo:
            self.faultTo.asEtreeSubNode(rootNode)
        # Action (REQUIRED)
        node = etree_.SubElement(rootNode,
                                 wsaTag('Action'),
                                 attrib={s12Tag('mustUnderstand'): 'true'})
        node.text = self.action
        # MessageID (OPTIONAL)
        if self.messageId:
            node = etree_.SubElement(rootNode, wsaTag('MessageID'))
            node.text = self.messageId
        # RelatesTo (OPTIONAL)
        if self.relatesTo:
            node = etree_.SubElement(rootNode, wsaTag('RelatesTo'))
            node.text = self.relatesTo
            if self.relationshipType is not None:
                node.set('RelationshipType', self.relationshipType)

        if self.referenceParametersNode:
            rootNode.append(copy.copy(self.referenceParametersNode))
Пример #2
0
 def __init__(self, requestEnvelope, fault_action, code, reason, subCode,
              details):
     super(_SoapFaultBase, self).__init__(
         Prefix.partialMap(Prefix.S12, Prefix.WSA, Prefix.WSE))
     replyAddress = requestEnvelope.address.mkReplyAddress(fault_action)
     self.addHeaderObject(replyAddress)
     faultNode = etree_.Element(s12Tag('Fault'))
     codeNode = etree_.SubElement(faultNode, s12Tag('Code'))
     valueNode = etree_.SubElement(codeNode, s12Tag('Value'))
     valueNode.text = 's12:{}'.format(code)
     if subCode is not None:
         subcodeNode = etree_.SubElement(codeNode, s12Tag('Subcode'))
         valueNode = etree_.SubElement(subcodeNode, s12Tag('Value'))
         valueNode.text = docNameFromQName(subCode, nsmap)
     reasonNode = etree_.SubElement(faultNode, s12Tag('Reason'))
     reasontextNode = etree_.SubElement(reasonNode, s12Tag('Text'))
     reasontextNode.set(xmlTag('lang'), 'en-US')
     reasontextNode.text = reason
     if details is not None:
         _detailNode = etree_.SubElement(faultNode, s12Tag('Detail'))
         _detailNode.set(xmlTag('lang'), 'en-US')
         if isinstance(details, str):
             detNode = etree_.SubElement(_detailNode, 'data')
             detNode.text = details
         else:
             _detailNode.append(details)
     self.addBodyElement(faultNode)
    def test_invalid_GetStatus_Renew(self):
        ''' verify that a subscription response is 'Fault' response in case of invalid request'''
        notifyTo = 'http://localhost:123'
        endTo = 'http://localhost:124'
        hosted = sdc11073.pysoap.soapenvelope.DPWSHosted(
            endpointReferencesList=[sdc11073.pysoap.soapenvelope.WsaEndpointReferenceType('http://1.2.3.4:6000')],
            typesList=['Get'],
            serviceId=123)
        for sdcDevice in self._allDevices:
            clSubscr = sdc11073.sdcclient.subscription._ClSubscription(dpwsHosted=hosted,
                                                                       actions=[sdcDevice.mdib.sdc_definitions.Actions.EpisodicMetricReport],
                                                                       notification_url=notifyTo,
                                                                       endTo_url=endTo,
                                                                       ident='')
            subscrRequest = clSubscr._mkSubscribeEnvelope(subscribe_epr='http://otherdevice/bla:123', expire_minutes=59)
            subscrRequest.validateBody(sdcDevice.mdib.bicepsSchema.evtSchema)
            print (subscrRequest.as_xml(pretty=True))

            httpHeader = {}
            # avoid instantiation of new soap client by pretenting there is one already
            sdcDevice.subscriptionsManager.soapClients['localhost:123'] = 'dummy'
            response = sdcDevice.subscriptionsManager.onSubscribeRequest(httpHeader,
                                                                          AddressedSoap12Envelope.fromXMLString(subscrRequest.as_xml()),
                                                                          'http://abc.com:123/def')
            response.validateBody(sdcDevice.mdib.bicepsSchema.evtSchema)
            clSubscr._handleSubscribeResponse(AddressedSoap12Envelope.fromXMLString(response.as_xml()))
    
            # check renew
            clSubscr.dev_reference_param[0].text = 'bla'# make ident invalid
            renewRequest = clSubscr._mkRenewEnvelope(expire_minutes=59)
            renewRequest.validateBody(sdcDevice.mdib.bicepsSchema.evtSchema)
            print (renewRequest.as_xml(pretty=True))
    
            response = sdcDevice.subscriptionsManager.onRenewRequest(AddressedSoap12Envelope.fromXMLString(renewRequest.as_xml()))
            print (response.as_xml(pretty=True))
            self.assertEqual(response.bodyNode[0].tag, namespaces.s12Tag('Fault'))
            response.validateBody(sdcDevice.mdib.bicepsSchema.s12Schema)
    
            getStatusRequest = clSubscr._mkGetStatusEnvelope()
            getStatusRequest.validateBody(sdcDevice.mdib.bicepsSchema.evtSchema)
            print (getStatusRequest.as_xml(pretty=True))
    
            response = sdcDevice.subscriptionsManager.onRenewRequest(AddressedSoap12Envelope.fromXMLString(renewRequest.as_xml()))
            print (response.as_xml(pretty=True))
            self.assertEqual(response.bodyNode[0].tag, namespaces.s12Tag('Fault'))
            response.validateBody(sdcDevice.mdib.bicepsSchema.s12Schema)
Пример #4
0
    def buildDoc(self):
        if self._docRoot is not None:
            return self._docRoot

        root = etree_.Element(s12Tag('Envelope'), nsmap=self._nsmap)

        header = etree_.SubElement(root, s12Tag('Header'))
        if self.address:
            self.address.asEtreeSubNode(header)
        for h in self._headerObjects:
            h.asEtreeSubNode(header)
        body = etree_.SubElement(root, s12Tag('Body'))
        for b in self._bodyObjects:
            b.asEtreeSubNode(body)
        self._headerNode = header
        self._bodyNode = body
        self._docRoot = root
        return root