def testRequestSetOk(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) myDevice = Device("Device22"); myDevice._add_control_field(name="Temperature", typename="int", value="15"); self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); self.recv(""" <iq type='set' from='[email protected]/amr' to='*****@*****.**' id='1'> <set xmlns='urn:xmpp:iot:control'> <int name="Temperature" value="17"/> </set> </iq> """) self.send(""" <iq type='result' from='*****@*****.**' to='[email protected]/amr' id='1'> <setResponse xmlns='urn:xmpp:iot:control' responseCode="OK" /> </iq> """) self.assertEqual(myDevice._get_field_value("Temperature"), "17");
def testRequestSetFail(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) myDevice = Device("Device23"); myDevice._add_control_field(name="Temperature", typename="int", value="15"); self.xmpp['xep_0325'].register_node(nodeId="Device23", device=myDevice, commTimeout=0.5); self.recv(""" <iq type='set' from='[email protected]/amr' to='*****@*****.**' id='9'> <set xmlns='urn:xmpp:iot:control'> <int name="Voltage" value="17"/> </set> </iq> """) self.send(""" <iq type='error' from='*****@*****.**' to='[email protected]/amr' id='9'> <setResponse xmlns='urn:xmpp:iot:control' responseCode='NotFound'> <parameter name='Voltage' /> <error var='Output'>Invalid field Voltage</error> </setResponse> </iq> """) self.assertEqual(myDevice._get_field_value("Temperature"), "15"); self.assertFalse(myDevice.has_control_field("Voltage", "int"));
def testDirectSetFail(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) myDevice = Device("Device22"); myDevice._add_control_field(name="Temperature", typename="int", value="15"); self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); self.recv(""" <message from='[email protected]/amr' to='*****@*****.**'> <set xmlns='urn:xmpp:iot:control'> <int name="Voltage" value="17"/> </set> </message> """) self.assertEqual(myDevice._get_field_value("Temperature"), "15"); self.assertFalse(myDevice.has_control_field("Voltage", "int"));
def testRequestSetFail(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) myDevice = Device("Device23") myDevice._add_control_field(name="Temperature", typename="int", value="15") self.xmpp['xep_0325'].register_node(nodeId="Device23", device=myDevice, commTimeout=0.5) self.recv(""" <iq type='set' from='[email protected]/amr' to='*****@*****.**' id='9'> <set xmlns='urn:xmpp:iot:control'> <int name="Voltage" value="17"/> </set> </iq> """) self.send(""" <iq type='error' from='*****@*****.**' to='[email protected]/amr' id='9'> <setResponse xmlns='urn:xmpp:iot:control' responseCode='NotFound'> <parameter name='Voltage' /> <error var='Output'>Invalid field Voltage</error> </setResponse> </iq> """) self.assertEqual(myDevice._get_field_value("Temperature"), "15") self.assertFalse(myDevice.has_control_field("Voltage", "int"))
def testDirectSetFail(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) myDevice = Device("Device22") myDevice._add_control_field(name="Temperature", typename="int", value="15") self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5) self.recv(""" <message from='[email protected]/amr' to='*****@*****.**'> <set xmlns='urn:xmpp:iot:control'> <int name="Voltage" value="17"/> </set> </message> """) self.assertEqual(myDevice._get_field_value("Temperature"), "15") self.assertFalse(myDevice.has_control_field("Voltage", "int"))
def testRequestSetMulti(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) myDevice = Device("Device22") myDevice._add_control_field(name="Temperature", typename="int", value="15") myDevice._add_control_field(name="Startup", typename="date", value="2013-01-03") myDevice2 = Device("Device23") myDevice2._add_control_field(name="Temperature", typename="int", value="19") myDevice2._add_control_field(name="Startup", typename="date", value="2013-01-09") self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5) self.xmpp['xep_0325'].register_node(nodeId="Device23", device=myDevice2, commTimeout=0.5) self.recv(""" <iq type='set' from='[email protected]/amr' to='*****@*****.**' id='1'> <set xmlns='urn:xmpp:iot:control'> <node nodeId='Device22' /> <int name="Temperature" value="17"/> </set> </iq> """) self.send(""" <iq type='result' from='*****@*****.**' to='[email protected]/amr' id='1'> <setResponse xmlns='urn:xmpp:iot:control' responseCode="OK" /> </iq> """) self.assertEqual(myDevice._get_field_value("Temperature"), "17") self.assertEqual(myDevice2._get_field_value("Temperature"), "19") self.recv(""" <iq type='set' from='[email protected]/amr' to='*****@*****.**' id='2'> <set xmlns='urn:xmpp:iot:control'> <node nodeId='Device23' /> <node nodeId='Device22' /> <date name="Startup" value="2013-02-01"/> <int name="Temperature" value="20"/> </set> </iq> """) self.send(""" <iq type='result' from='*****@*****.**' to='[email protected]/amr' id='2'> <setResponse xmlns='urn:xmpp:iot:control' responseCode="OK" /> </iq> """) self.assertEqual(myDevice._get_field_value("Temperature"), "20") self.assertEqual(myDevice2._get_field_value("Temperature"), "20") self.assertEqual(myDevice._get_field_value("Startup"), "2013-02-01") self.assertEqual(myDevice2._get_field_value("Startup"), "2013-02-01")