Exemplo n.º 1
0
    def testDelayedRequest(self):
        self.stream_start(mode='component', plugins=['xep_0030', 'xep_0323'])

        myDevice = Device("Device22")
        myDevice._add_field(name="Temperature", typename="numeric", unit="°C")
        myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
        myDevice._add_field_momentary_data("Temperature",
                                           "23.4",
                                           flags={"automaticReadout": "true"})

        self.xmpp['xep_0323'].register_node(nodeId="Device22",
                                            device=myDevice,
                                            commTimeout=0.5)

        dtnow = datetime.datetime.now()
        ts_2sec = datetime.timedelta(0, 2)
        dtnow_plus_2sec = dtnow + ts_2sec
        when_flag = dtnow_plus_2sec.replace(microsecond=0).isoformat()

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true' when='"""
                  + when_flag + """'/>
            </iq>
        """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1' queued='true' />
            </iq>
            """)

        time.sleep(1)

        self.send("""
            <message from='*****@*****.**'
                     to='[email protected]/amr'>
                <started xmlns='urn:xmpp:iot:sensordata' seqnr='1' />
            </message>
            """)

        self.send("""
            <message from='*****@*****.**'
                     to='[email protected]/amr'>
                <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1' done='true'>
                    <node nodeId='Device22'>
                        <timestamp value='2013-03-07T16:24:30'>
                            <numeric name='Temperature' momentary='true' automaticReadout='true' value='23.4' unit='°C'/>
                        </timestamp>
                    </node>
                </fields>
            </message>
            """)
Exemplo n.º 2
0
    def testDelayedRequest(self):
        self.stream_start(mode='component',
                          plugins=['xep_0030',
                                   'xep_0323'])

        myDevice = Device("Device22");
        myDevice._add_field(name="Temperature", typename="numeric", unit="°C");
        myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
        myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});

        self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5);

        dtnow = datetime.datetime.now()
        ts_2sec = datetime.timedelta(0,2)
        dtnow_plus_2sec = dtnow + ts_2sec
        when_flag = dtnow_plus_2sec.replace(microsecond=0).isoformat()

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true' when='""" + when_flag + """'/>
            </iq>
        """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1' queued='true' />
            </iq>
            """)

        time.sleep(1)

        self.send("""
            <message from='*****@*****.**'
                     to='[email protected]/amr'>
                <started xmlns='urn:xmpp:iot:sensordata' seqnr='1' />
            </message>
            """)

        self.send("""
            <message from='*****@*****.**'
                     to='[email protected]/amr'>
                <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1' done='true'>
                    <node nodeId='Device22'>
                        <timestamp value='2013-03-07T16:24:30'>
                            <numeric name='Temperature' momentary='true' automaticReadout='true' value='23.4' unit='°C'/>
                        </timestamp>
                    </node>
                </fields>
            </message>
            """)
Exemplo n.º 3
0
    def testDelayedRequestFail(self):
        self.stream_start(mode='component', plugins=['xep_0030', 'xep_0323'])

        myDevice = Device("Device22")
        myDevice._add_field(name="Temperature", typename="numeric", unit="°C")
        myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
        myDevice._add_field_momentary_data("Temperature",
                                           "23.4",
                                           flags={"automaticReadout": "true"})

        self.xmpp['xep_0323'].register_node(nodeId="Device22",
                                            device=myDevice,
                                            commTimeout=0.5)

        dtnow = datetime.datetime.now()
        ts_2sec = datetime.timedelta(0, 2)
        dtnow_minus_2sec = dtnow - ts_2sec
        when_flag = dtnow_minus_2sec.replace(microsecond=0).isoformat()

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true' when='"""
                  + when_flag + """'/>
            </iq>
        """)

        # Remove the returned datetime to allow predictable test
        xml_stanza = self._filtered_stanza_prepare()
        error_text = xml_stanza['rejected']['error']  #['text']
        error_text = re.sub(
            r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-]\d{2}:\d{2})?',
            '…', error_text)
        xml_stanza['rejected']['error'] = error_text

        self._filtered_stanza_check(
            """
            <iq type='error'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <rejected xmlns='urn:xmpp:iot:sensordata' seqnr='1'>
                    <error>Invalid datetime in 'when' flag, cannot set a time in the past (…). Current time: …</error>
                </rejected>
            </iq>
            """, xml_stanza)
Exemplo n.º 4
0
    def testRequestAccept(self):
        self.stream_start(mode='component', plugins=['xep_0030', 'xep_0323'])

        myDevice = Device("Device22")
        myDevice._add_field(name="Temperature", typename="numeric", unit="°C")
        myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
        myDevice._add_field_momentary_data("Temperature",
                                           "23.4",
                                           flags={"automaticReadout": "true"})

        self.xmpp['xep_0323'].register_node(nodeId="Device22",
                                            device=myDevice,
                                            commTimeout=0.5)

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true'/>
            </iq>
        """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1'/>
            </iq>
            """)

        self.send("""
            <message from='*****@*****.**'
                     to='[email protected]/amr'>
                <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1' done='true'>
                    <node nodeId='Device22'>
                        <timestamp value='2013-03-07T16:24:30'>
                            <numeric name='Temperature' momentary='true' automaticReadout='true' value='23.4' unit='°C'/>
                        </timestamp>
                    </node>
                </fields>
            </message>
            """)
Exemplo n.º 5
0
    def testDelayedRequestFail(self):
        self.stream_start(mode='component',
                          plugins=['xep_0030',
                                   'xep_0323'])

        myDevice = Device("Device22");
        myDevice._add_field(name="Temperature", typename="numeric", unit="°C");
        myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
        myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});

        self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5);

        dtnow = datetime.datetime.now()
        ts_2sec = datetime.timedelta(0,2)
        dtnow_minus_2sec = dtnow - ts_2sec
        when_flag = dtnow_minus_2sec.replace(microsecond=0).isoformat()

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true' when='""" + when_flag + """'/>
            </iq>
        """)

        # Remove the returned datetime to allow predictable test
        xml_stanza = self._filtered_stanza_prepare()
        error_text = xml_stanza['rejected']['error'] #['text']
        error_text = error_text[:error_text.find(':')]
        xml_stanza['rejected']['error'] = error_text

        self._filtered_stanza_check("""
            <iq type='error'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <rejected xmlns='urn:xmpp:iot:sensordata' seqnr='1'>
                    <error>Invalid datetime in 'when' flag, cannot set a time in the past. Current time</error>
                </rejected>
            </iq>
            """, xml_stanza)
Exemplo n.º 6
0
    def testRequestAccept(self):
        self.stream_start(mode='component',
                          plugins=['xep_0030',
                                   'xep_0323'])

        myDevice = Device("Device22");
        myDevice._add_field(name="Temperature", typename="numeric", unit="°C");
        myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
        myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});

        self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5);

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true'/>
            </iq>
        """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1'/>
            </iq>
            """)

        self.send("""
            <message from='*****@*****.**'
                     to='[email protected]/amr'>
                <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1' done='true'>
                    <node nodeId='Device22'>
                        <timestamp value='2013-03-07T16:24:30'>
                            <numeric name='Temperature' momentary='true' automaticReadout='true' value='23.4' unit='°C'/>
                        </timestamp>
                    </node>
                </fields>
            </message>
            """)
Exemplo n.º 7
0
    def testDelayedRequestCancel(self):
        self.stream_start(mode='component', plugins=['xep_0030', 'xep_0323'])

        myDevice = Device("Device22")
        myDevice._add_field(name="Temperature", typename="numeric", unit="°C")
        myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
        myDevice._add_field_momentary_data("Temperature",
                                           "23.4",
                                           flags={"automaticReadout": "true"})

        self.xmpp['xep_0323'].register_node(nodeId="Device22",
                                            device=myDevice,
                                            commTimeout=0.5)

        dtnow = datetime.datetime.now()
        ts_2sec = datetime.timedelta(0, 2)
        dtnow_plus_2sec = dtnow + ts_2sec
        when_flag = dtnow_plus_2sec.replace(microsecond=0).isoformat()

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true' when='"""
                  + when_flag + """'/>
            </iq>
        """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1' queued='true' />
            </iq>
            """)

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <cancel xmlns='urn:xmpp:iot:sensordata' seqnr='1' />
            </iq>
            """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <cancelled xmlns='urn:xmpp:iot:sensordata' seqnr='1' />
            </iq>
            """)

        # Test cancel of non-existing request
        self.recv("""
            <iq type='get'
                from='tester@localhost'
                to='*****@*****.**'
                id='1'>
                <cancel xmlns='urn:xmpp:iot:sensordata' seqnr='1' />
            </iq>
            """)

        self.send("""
            <iq type='error'
                from='*****@*****.**'
                to='tester@localhost'
                id='1'>
                <rejected xmlns='urn:xmpp:iot:sensordata' seqnr='1'>
                    <error>Cancel request received, no matching request is active.</error>
                </rejected>
            </iq>
            """)

        # Ensure we don't get anything after cancellation
        self.send(None)
Exemplo n.º 8
0
    def testDelayedRequestCancel(self):
        self.stream_start(mode='component',
                          plugins=['xep_0030',
                                   'xep_0323'])

        myDevice = Device("Device22");
        myDevice._add_field(name="Temperature", typename="numeric", unit="°C");
        myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
        myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});

        self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5);

        dtnow = datetime.datetime.now()
        ts_2sec = datetime.timedelta(0,2)
        dtnow_plus_2sec = dtnow + ts_2sec
        when_flag = dtnow_plus_2sec.replace(microsecond=0).isoformat()

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true' when='""" + when_flag + """'/>
            </iq>
        """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1' queued='true' />
            </iq>
            """)

        self.recv("""
            <iq type='get'
                from='[email protected]/amr'
                to='*****@*****.**'
                id='1'>
                <cancel xmlns='urn:xmpp:iot:sensordata' seqnr='1' />
            </iq>
            """)

        self.send("""
            <iq type='result'
                from='*****@*****.**'
                to='[email protected]/amr'
                id='1'>
                <cancelled xmlns='urn:xmpp:iot:sensordata' seqnr='1' />
            </iq>
            """)

        # Test cancel of non-existing request
        self.recv("""
            <iq type='get'
                from='tester@localhost'
                to='*****@*****.**'
                id='1'>
                <cancel xmlns='urn:xmpp:iot:sensordata' seqnr='1' />
            </iq>
            """)

        self.send("""
            <iq type='error'
                from='*****@*****.**'
                to='tester@localhost'
                id='1'>
                <rejected xmlns='urn:xmpp:iot:sensordata' seqnr='1'>
                    <error>Cancel request received, no matching request is active.</error>
                </rejected>
            </iq>
            """)

        # Ensure we don't get anything after cancellation
        self.send(None)