def test_waveformSubscription(self):
        for sdcDevice in self._allDevices:
            testSubscr = mockstuff.TestDevSubscription(
                sdcDevice.mdib.sdc_definitions.Actions.Waveform,
                sdcDevice.mdib.bicepsSchema)
            sdcDevice.subscriptionsManager._subscriptions.addObject(testSubscr)

            tr = waveforms.TriangleGenerator(min_value=0,
                                             max_value=10,
                                             waveformperiod=2.0,
                                             sampleperiod=0.01)
            st = waveforms.SawtoothGenerator(min_value=0,
                                             max_value=10,
                                             waveformperiod=2.0,
                                             sampleperiod=0.01)
            si = waveforms.SinusGenerator(min_value=-8.0,
                                          max_value=10.0,
                                          waveformperiod=5.0,
                                          sampleperiod=0.01)

            sdcDevice.mdib.registerWaveformGenerator(HANDLES[0], tr)
            sdcDevice.mdib.registerWaveformGenerator(HANDLES[1], st)
            sdcDevice.mdib.registerWaveformGenerator(HANDLES[2], si)

            time.sleep(3)
            self.assertGreater(len(testSubscr.reports), 20)
            report = testSubscr.reports[-1]  # a
            in_report = AddressedSoap12Envelope.fromXMLString(report.as_xml())
            expected_action = sdcDevice.mdib.sdc_definitions.Actions.Waveform
            self.assertEqual(in_report.address.action, expected_action)
    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)
    def test_waveformSubscription(self):
        self._model = sdc11073.pysoap.soapenvelope.DPWSThisModel(
            manufacturer='Chinakracher GmbH',
            manufacturerUrl='www.chinakracher.com',
            modelName='BummHuba',
            modelNumber='1.0',
            modelUrl='www.chinakracher.com/bummhuba/model',
            presentationUrl='www.chinakracher.com/bummhuba/presentation')
        self._device = sdc11073.pysoap.soapenvelope.DPWSThisDevice(
            friendlyName='Big Bang Practice',
            firmwareVersion='0.99',
            serialNumber='87kabuuum889')

        tr = waveforms.TriangleGenerator(min_value=0,
                                         max_value=10,
                                         waveformperiod=2.0,
                                         sampleperiod=0.02)
        st = waveforms.SawtoothGenerator(min_value=0,
                                         max_value=10,
                                         waveformperiod=2.0,
                                         sampleperiod=0.02)
        si = waveforms.SinusGenerator(min_value=-8.0,
                                      max_value=10.0,
                                      waveformperiod=5.0,
                                      sampleperiod=0.02)

        self.mdib.registerWaveformGenerator(HANDLES[0], tr)
        self.mdib.registerWaveformGenerator(HANDLES[1], st)
        self.mdib.registerWaveformGenerator(HANDLES[2], si)

        annotation = pmtypes.Annotation(pmtypes.CodedValue('a', 'b'))
        self.mdib.registerAnnotationGenerator(annotation,
                                              triggerHandle=HANDLES[2],
                                              annotatedHandles=(HANDLES[0],
                                                                HANDLES[1],
                                                                HANDLES[2]))

        self.wsDiscovery = mockstuff.MockWsDiscovery(['5.6.7.8'])
        uuid = None  # let device create one
        self.sdcDevice = sdc11073.sdcdevice.SdcDevice(self.wsDiscovery,
                                                      uuid,
                                                      self._model,
                                                      self._device,
                                                      self.mdib,
                                                      logLevel=logging.DEBUG)
        self.sdcDevice.startAll()
        testSubscr = mockstuff.TestDevSubscription(
            self.sdcDevice.mdib.sdc_definitions.Actions.Waveform,
            self.sdcDevice.mdib.bicepsSchema)
        self.sdcDevice.subscriptionsManager._subscriptions.addObject(
            testSubscr)

        time.sleep(3)
        print(testSubscr.reports[-2].as_xml(pretty=True))
        print(testSubscr.reports[-1].as_xml(pretty=True))
        self.assertGreater(len(testSubscr.reports), 20)
 def test_notifyOperation(self):
     for sdcDevice in self._allDevices:
         testSubscr = mockstuff.TestDevSubscription(sdcDevice.mdib.sdc_definitions.Actions.OperationInvokedReport, sdcDevice.mdib.bicepsSchema)
         sdcDevice.subscriptionsManager._subscriptions.addObject(testSubscr)
         sdcDevice.subscriptionsManager.notifyOperation('urn:uuid:abc', 1234,
                                                         transactionId=123, 
                                                         operationHandleRef='something', 
                                                         operationState='Fin', 
                                                         error='Unspec', 
                                                         errorMessage='')
         self.assertEqual(len(testSubscr.reports), 1)
 def test_episodicContextReportEvent(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.EpisodicContextReport, sdcDevice.mdib.bicepsSchema)
         sdcDevice.subscriptionsManager._subscriptions.addObject(testSubscr)
         patientContextDescriptor = sdcDevice.mdib.descriptions.NODETYPE.getOne(namespaces.domTag('PatientContextDescriptor'))
         descriptorHandle = patientContextDescriptor.handle
         with sdcDevice.mdib.mdibUpdateTransaction() as mgr:
             st = mgr.getContextState(descriptorHandle)
             st.PatientType = pmtypes.PatientType.ADULT
         self.assertEqual(len(testSubscr.reports), 1)
         response = testSubscr.reports[0]
         response.validateBody(sdcDevice.mdib.bicepsSchema.bmmSchema)