Esempio n. 1
0
    def __init__(self, filter_, bicepsSchema):
        notifyRefNode = etree_.Element(namespaces.wseTag('References'))
        identNode = etree_.SubElement(notifyRefNode,
                                      namespaces.wseTag('Identifier'))
        identNode.text = self.notifyRef
        base_urls = [
            urllib.parse.SplitResult('https',
                                     'www.example.com:222',
                                     'no_uuid',
                                     query=None,
                                     fragment=None)
        ]

        super(TestDevSubscription,
              self).__init__(mode=self.mode,
                             notifyToAddress=self.notifyTo,
                             notifyRefNode=notifyRefNode,
                             endToAddress=None,
                             endToRefNode=None,
                             expires=self.expires,
                             max_subscription_duration=42,
                             filter_=filter_,
                             sslContext=None,
                             bicepsSchema=bicepsSchema,
                             acceptedEncodings=None,
                             base_urls=base_urls)
        self.reports = []
        self.bmmSchema = bicepsSchema.bmmSchema
 def test_episodicMetricReportEvent(self):
     ''' verify that an event message is sent to subscriber and that message is valid'''
     # directly inject a subscription event, this test is not about starting subscriptions
     for sdcDevice in self._allDevices:
         testSubscr = mockstuff.TestDevSubscription(sdcDevice.mdib.sdc_definitions.Actions.EpisodicMetricReport, sdcDevice.mdib.bicepsSchema)
         sdcDevice.subscriptionsManager._subscriptions.addObject(testSubscr)
         
         descriptorHandle = '0x34F00100'#'0x34F04380'
         firstValue = 12
         with sdcDevice.mdib.mdibUpdateTransaction() as mgr:
             st = mgr.getMetricState(descriptorHandle)
             if st.metricValue is None:
                 st.mkMetricValue()
             st.metricValue.Value = firstValue
             st.Validity = 'Vld'
         self.assertEqual(len(testSubscr.reports), 1)
         response = testSubscr.reports[0]
         print (response.as_xml(pretty=True))
         response.validateBody(sdcDevice.mdib.bicepsSchema.bmmSchema)
         
         # verify that header contains the identifier of client subscription
         env  = AddressedSoap12Envelope.fromXMLString(response.as_xml())
         idents = env.headerNode.findall(namespaces.wseTag('Identifier'))
         self.assertEqual(len(idents), 1)
         self.assertEqual(idents[0].text, mockstuff.TestDevSubscription.notifyRef)
Esempio n. 3
0
    def asEtreeSubNode(self, rootNode):
        # To (OPTIONAL), defaults to anonymous
        subscribe = etree_.SubElement(rootNode,
                                      wseTag('Subscribe'),
                                      nsmap=Prefix.partialMap(
                                          Prefix.WSE, Prefix.WSA))
        if self.endTo is not None:
            endToNode = etree_.SubElement(subscribe, wseTag('EndTo'))
            self.endTo.asEtreeSubNode(endToNode)
        delivery = etree_.SubElement(subscribe, wseTag('Delivery'))
        delivery.set('Mode', self.delivery_mode)

        notifyToNode = etree_.SubElement(delivery, wseTag('NotifyTo'))
        self.notifyTo.asEtreeSubNode(notifyToNode)

        exp = etree_.SubElement(subscribe, wseTag('Expires'))
        exp.text = isoduration.durationString(self.expires)
        fil = etree_.SubElement(subscribe, wseTag('Filter'))
        fil.set('Dialect', DIALECT_ACTION)  # Is this always this string?
        fil.text = self.filter