diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_stanza_element.py | 4 | ||||
-rw-r--r-- | tests/test_stanza_xep_0323.py | 135 | ||||
-rw-r--r-- | tests/test_stanza_xep_0325.py | 80 | ||||
-rw-r--r-- | tests/test_stream_xep_0323.py | 424 | ||||
-rw-r--r-- | tests/test_stream_xep_0325.py | 110 |
5 files changed, 379 insertions, 374 deletions
diff --git a/tests/test_stanza_element.py b/tests/test_stanza_element.py index e678b56e..2b9676cf 100644 --- a/tests/test_stanza_element.py +++ b/tests/test_stanza_element.py @@ -385,7 +385,7 @@ class TestElementBase(SleekTest): interfaces = set(('bar', 'baz')) def setBar(self, value): - self._set_sub_text("path/to/only/bar", value) + self._set_sub_text("path/to/only/bar", value); def getBar(self): return self._get_sub_text("path/to/only/bar") @@ -394,7 +394,7 @@ class TestElementBase(SleekTest): self._del_sub("path/to/only/bar") def setBaz(self, value): - self._set_sub_text("path/to/just/baz", value) + self._set_sub_text("path/to/just/baz", value); def getBaz(self): return self._get_sub_text("path/to/just/baz") diff --git a/tests/test_stanza_xep_0323.py b/tests/test_stanza_xep_0323.py index 7b1dfe42..67e0daf0 100644 --- a/tests/test_stanza_xep_0323.py +++ b/tests/test_stanza_xep_0323.py @@ -6,7 +6,7 @@ import sleekxmpp.plugins.xep_0323 as xep_0323 namespace='sn' class TestSensorDataStanzas(SleekTest): - + def setUp(self): pass @@ -59,8 +59,8 @@ class TestSensorDataStanzas(SleekTest): iq['req']['momentary'] = 'true' - iq['req'].add_node("Device02", "Source02", "CacheType") - iq['req'].add_node("Device44") + iq['req'].add_node("Device02", "Source02", "CacheType"); + iq['req'].add_node("Device44"); self.check(iq,""" <iq type='get' @@ -75,7 +75,7 @@ class TestSensorDataStanzas(SleekTest): """ ) - iq['req'].del_node("Device02") + iq['req'].del_node("Device02"); self.check(iq,""" <iq type='get' @@ -89,7 +89,7 @@ class TestSensorDataStanzas(SleekTest): """ ) - iq['req'].del_nodes() + iq['req'].del_nodes(); self.check(iq,""" <iq type='get' @@ -115,8 +115,8 @@ class TestSensorDataStanzas(SleekTest): iq['req']['momentary'] = 'true' - iq['req'].add_field("Top temperature") - iq['req'].add_field("Bottom temperature") + iq['req'].add_field("Top temperature"); + iq['req'].add_field("Bottom temperature"); self.check(iq,""" <iq type='get' @@ -171,7 +171,7 @@ class TestSensorDataStanzas(SleekTest): iq['accepted']['seqnr'] = '2' self.check(iq,""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='2'> @@ -193,7 +193,7 @@ class TestSensorDataStanzas(SleekTest): iq['rejected']['error'] = 'Access denied.' self.check(iq,""" - <iq type='error' + <iq type='error' from='device@clayster.com' to='master@clayster.com/amr' id='4'> @@ -237,12 +237,12 @@ class TestSensorDataStanzas(SleekTest): msg['to'] = 'master@clayster.com/amr' msg['fields']['seqnr'] = '1' - node = msg['fields'].add_node("Device02") - ts = node.add_timestamp("2013-03-07T16:24:30") + node = msg['fields'].add_node("Device02"); + ts = node.add_timestamp("2013-03-07T16:24:30"); - data = ts.add_data(typename="numeric", name="Temperature", value="-12.42", unit='K') - data['momentary'] = 'true' - data['automaticReadout'] = 'true' + data = ts.add_data(typename="numeric", name="Temperature", value="-12.42", unit='K'); + data['momentary'] = 'true'; + data['automaticReadout'] = 'true'; self.check(msg,""" <message from='device@clayster.com' @@ -250,7 +250,7 @@ class TestSensorDataStanzas(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1'> <node nodeId='Device02'> <timestamp value='2013-03-07T16:24:30'> - <numeric name='Temperature' momentary='true' automaticReadout='true' value='-12.42' unit='K'/> + <numeric name='Temperature' momentary='true' automaticReadout='true' value='-12.42' unit='K'/> </timestamp> </node> </fields> @@ -258,9 +258,10 @@ class TestSensorDataStanzas(SleekTest): """ ) - node = msg['fields'].add_node("EmptyDevice") - node = msg['fields'].add_node("Device04") - ts = node.add_timestamp("EmptyTimestamp") + node = msg['fields'].add_node("EmptyDevice"); + node = msg['fields'].add_node("Device04"); + ts = node.add_timestamp("EmptyTimestamp"); + self.check(msg,""" <message from='device@clayster.com' @@ -268,7 +269,7 @@ class TestSensorDataStanzas(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1'> <node nodeId='Device02'> <timestamp value='2013-03-07T16:24:30'> - <numeric name='Temperature' momentary='true' automaticReadout='true' value='-12.42' unit='K'/> + <numeric name='Temperature' momentary='true' automaticReadout='true' value='-12.42' unit='K'/> </timestamp> </node> <node nodeId='EmptyDevice'/> @@ -280,32 +281,32 @@ class TestSensorDataStanzas(SleekTest): """ ) - node = msg['fields'].add_node("Device77") - ts = node.add_timestamp("2013-05-03T12:00:01") - data = ts.add_data(typename="numeric", name="Temperature", value="-12.42", unit='K') - data['historicalDay'] = 'true' - data = ts.add_data(typename="numeric", name="Speed", value="312.42", unit='km/h') - data['historicalWeek'] = 'false' - data = ts.add_data(typename="string", name="Temperature name", value="Bottom oil") - data['historicalMonth'] = 'true' - data = ts.add_data(typename="string", name="Speed name", value="Top speed") - data['historicalQuarter'] = 'false' - data = ts.add_data(typename="dateTime", name="T1", value="1979-01-01T00:00:00") - data['historicalYear'] = 'true' - data = ts.add_data(typename="dateTime", name="T2", value="2000-01-01T01:02:03") - data['historicalOther'] = 'false' - data = ts.add_data(typename="timeSpan", name="TS1", value="P5Y") - data['missing'] = 'true' - data = ts.add_data(typename="timeSpan", name="TS2", value="PT2M1S") - data['manualEstimate'] = 'false' - data = ts.add_data(typename="enum", name="top color", value="red", dataType="string") - data['invoiced'] = 'true' - data = ts.add_data(typename="enum", name="bottom color", value="black", dataType="string") - data['powerFailure'] = 'false' - data = ts.add_data(typename="boolean", name="Temperature real", value="false") - data['historicalDay'] = 'true' - data = ts.add_data(typename="boolean", name="Speed real", value="true") - data['historicalWeek'] = 'false' + node = msg['fields'].add_node("Device77"); + ts = node.add_timestamp("2013-05-03T12:00:01"); + data = ts.add_data(typename="numeric", name="Temperature", value="-12.42", unit='K'); + data['historicalDay'] = 'true'; + data = ts.add_data(typename="numeric", name="Speed", value="312.42", unit='km/h'); + data['historicalWeek'] = 'false'; + data = ts.add_data(typename="string", name="Temperature name", value="Bottom oil"); + data['historicalMonth'] = 'true'; + data = ts.add_data(typename="string", name="Speed name", value="Top speed"); + data['historicalQuarter'] = 'false'; + data = ts.add_data(typename="dateTime", name="T1", value="1979-01-01T00:00:00"); + data['historicalYear'] = 'true'; + data = ts.add_data(typename="dateTime", name="T2", value="2000-01-01T01:02:03"); + data['historicalOther'] = 'false'; + data = ts.add_data(typename="timeSpan", name="TS1", value="P5Y"); + data['missing'] = 'true'; + data = ts.add_data(typename="timeSpan", name="TS2", value="PT2M1S"); + data['manualEstimate'] = 'false'; + data = ts.add_data(typename="enum", name="top color", value="red", dataType="string"); + data['invoiced'] = 'true'; + data = ts.add_data(typename="enum", name="bottom color", value="black", dataType="string"); + data['powerFailure'] = 'false'; + data = ts.add_data(typename="boolean", name="Temperature real", value="false"); + data['historicalDay'] = 'true'; + data = ts.add_data(typename="boolean", name="Speed real", value="true"); + data['historicalWeek'] = 'false'; self.check(msg,""" <message from='device@clayster.com' @@ -313,7 +314,7 @@ class TestSensorDataStanzas(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1'> <node nodeId='Device02'> <timestamp value='2013-03-07T16:24:30'> - <numeric name='Temperature' momentary='true' automaticReadout='true' value='-12.42' unit='K'/> + <numeric name='Temperature' momentary='true' automaticReadout='true' value='-12.42' unit='K'/> </timestamp> </node> <node nodeId='EmptyDevice'/> @@ -322,18 +323,18 @@ class TestSensorDataStanzas(SleekTest): </node> <node nodeId='Device77'> <timestamp value='2013-05-03T12:00:01'> - <numeric name='Temperature' historicalDay='true' value='-12.42' unit='K'/> - <numeric name='Speed' historicalWeek='false' value='312.42' unit='km/h'/> - <string name='Temperature name' historicalMonth='true' value='Bottom oil'/> - <string name='Speed name' historicalQuarter='false' value='Top speed'/> - <dateTime name='T1' historicalYear='true' value='1979-01-01T00:00:00'/> - <dateTime name='T2' historicalOther='false' value='2000-01-01T01:02:03'/> - <timeSpan name='TS1' missing='true' value='P5Y'/> - <timeSpan name='TS2' manualEstimate='false' value='PT2M1S'/> - <enum name='top color' invoiced='true' value='red' dataType='string'/> - <enum name='bottom color' powerFailure='false' value='black' dataType='string'/> - <boolean name='Temperature real' historicalDay='true' value='false'/> - <boolean name='Speed real' historicalWeek='false' value='true'/> + <numeric name='Temperature' historicalDay='true' value='-12.42' unit='K'/> + <numeric name='Speed' historicalWeek='false' value='312.42' unit='km/h'/> + <string name='Temperature name' historicalMonth='true' value='Bottom oil'/> + <string name='Speed name' historicalQuarter='false' value='Top speed'/> + <dateTime name='T1' historicalYear='true' value='1979-01-01T00:00:00'/> + <dateTime name='T2' historicalOther='false' value='2000-01-01T01:02:03'/> + <timeSpan name='TS1' missing='true' value='P5Y'/> + <timeSpan name='TS2' manualEstimate='false' value='PT2M1S'/> + <enum name='top color' invoiced='true' value='red' dataType='string'/> + <enum name='bottom color' powerFailure='false' value='black' dataType='string'/> + <boolean name='Temperature real' historicalDay='true' value='false'/> + <boolean name='Speed real' historicalWeek='false' value='true'/> </timestamp> </node> </fields> @@ -341,19 +342,21 @@ class TestSensorDataStanzas(SleekTest): """ ) - + def testTimestamp(self): - msg = self.Message() + msg = self.Message(); msg['from'] = 'device@clayster.com' msg['to'] = 'master@clayster.com/amr' msg['fields']['seqnr'] = '1' - node = msg['fields'].add_node("Device02") - node = msg['fields'].add_node("Device03") + node = msg['fields'].add_node("Device02"); + node = msg['fields'].add_node("Device03"); + + ts = node.add_timestamp("2013-03-07T16:24:30"); + ts = node.add_timestamp("2013-03-07T16:24:31"); + - ts = node.add_timestamp("2013-03-07T16:24:30") - ts = node.add_timestamp("2013-03-07T16:24:31") self.check(msg,""" <message from='device@clayster.com' @@ -383,8 +386,8 @@ class TestSensorDataStanzas(SleekTest): self.check(msg,emptyStringIdXML) msg['fields']['stringIds'] = "1" self.check(msg,emptyStringIdXML) + - - + suite = unittest.TestLoader().loadTestsFromTestCase(TestSensorDataStanzas) diff --git a/tests/test_stanza_xep_0325.py b/tests/test_stanza_xep_0325.py index dc2e8efe..b15b764c 100644 --- a/tests/test_stanza_xep_0325.py +++ b/tests/test_stanza_xep_0325.py @@ -15,7 +15,7 @@ import sleekxmpp.plugins.xep_0325 as xep_0325 namespace='sn' class TestControlStanzas(SleekTest): - + def setUp(self): pass @@ -29,8 +29,8 @@ class TestControlStanzas(SleekTest): iq['from'] = 'master@clayster.com/amr' iq['to'] = 'device@clayster.com' iq['id'] = '1' - iq['set'].add_node("Device02", "Source02", "MyCacheType") - iq['set'].add_node("Device15") + iq['set'].add_node("Device02", "Source02", "MyCacheType"); + iq['set'].add_node("Device15"); iq['set'].add_data("Tjohej", "boolean", "true") self.check(iq,""" @@ -47,7 +47,7 @@ class TestControlStanzas(SleekTest): """ ) - iq['set'].del_node("Device02") + iq['set'].del_node("Device02"); self.check(iq,""" <iq type='set' @@ -62,7 +62,7 @@ class TestControlStanzas(SleekTest): """ ) - iq['set'].del_nodes() + iq['set'].del_nodes(); self.check(iq,""" <iq type='set' @@ -84,12 +84,12 @@ class TestControlStanzas(SleekTest): msg = self.Message() msg['from'] = 'master@clayster.com/amr' msg['to'] = 'device@clayster.com' - msg['set'].add_node("Device02") - msg['set'].add_node("Device15") + msg['set'].add_node("Device02"); + msg['set'].add_node("Device15"); msg['set'].add_data("Tjohej", "boolean", "true") self.check(msg,""" - <message + <message from='master@clayster.com/amr' to='device@clayster.com'> <set xmlns='urn:xmpp:iot:control'> @@ -111,7 +111,7 @@ class TestControlStanzas(SleekTest): iq['from'] = 'master@clayster.com/amr' iq['to'] = 'device@clayster.com' iq['id'] = '8' - iq['setResponse']['responseCode'] = "OK" + iq['setResponse']['responseCode'] = "OK"; self.check(iq,""" <iq type='result' @@ -128,9 +128,10 @@ class TestControlStanzas(SleekTest): iq['from'] = 'master@clayster.com/amr' iq['to'] = 'device@clayster.com' iq['id'] = '9' - iq['setResponse']['responseCode'] = "OtherError" - iq['setResponse']['error']['var'] = "Output" - iq['setResponse']['error']['text'] = "Test of other error.!" + iq['setResponse']['responseCode'] = "OtherError"; + iq['setResponse']['error']['var'] = "Output"; + iq['setResponse']['error']['text'] = "Test of other error.!"; + self.check(iq,""" <iq type='error' @@ -149,10 +150,11 @@ class TestControlStanzas(SleekTest): iq['from'] = 'master@clayster.com/amr' iq['to'] = 'device@clayster.com' iq['id'] = '9' - iq['setResponse']['responseCode'] = "NotFound" - iq['setResponse'].add_node("Device17", "Source09") - iq['setResponse'].add_node("Device18", "Source09") - iq['setResponse'].add_data("Tjohopp") + iq['setResponse']['responseCode'] = "NotFound"; + iq['setResponse'].add_node("Device17", "Source09"); + iq['setResponse'].add_node("Device18", "Source09"); + iq['setResponse'].add_data("Tjohopp"); + self.check(iq,""" <iq type='error' @@ -177,38 +179,38 @@ class TestControlStanzas(SleekTest): iq['from'] = 'master@clayster.com/amr' iq['to'] = 'device@clayster.com' iq['id'] = '1' - iq['set'].add_node("Device02", "Source02", "MyCacheType") - iq['set'].add_node("Device15") + iq['set'].add_node("Device02", "Source02", "MyCacheType"); + iq['set'].add_node("Device15"); - iq['set'].add_data("Tjohej", "boolean", "true") - iq['set'].add_data("Tjohej2", "boolean", "false") + iq['set'].add_data("Tjohej", "boolean", "true"); + iq['set'].add_data("Tjohej2", "boolean", "false"); - iq['set'].add_data("TjohejC", "color", "FF00FF") - iq['set'].add_data("TjohejC2", "color", "00FF00") + iq['set'].add_data("TjohejC", "color", "FF00FF"); + iq['set'].add_data("TjohejC2", "color", "00FF00"); - iq['set'].add_data("TjohejS", "string", "String1") - iq['set'].add_data("TjohejS2", "string", "String2") + iq['set'].add_data("TjohejS", "string", "String1"); + iq['set'].add_data("TjohejS2", "string", "String2"); - iq['set'].add_data("TjohejDate", "date", "2012-01-01") - iq['set'].add_data("TjohejDate2", "date", "1900-12-03") + iq['set'].add_data("TjohejDate", "date", "2012-01-01"); + iq['set'].add_data("TjohejDate2", "date", "1900-12-03"); - iq['set'].add_data("TjohejDateT4", "dateTime", "1900-12-03 12:30") - iq['set'].add_data("TjohejDateT2", "dateTime", "1900-12-03 11:22") + iq['set'].add_data("TjohejDateT4", "dateTime", "1900-12-03 12:30"); + iq['set'].add_data("TjohejDateT2", "dateTime", "1900-12-03 11:22"); - iq['set'].add_data("TjohejDouble2", "double", "200.22") - iq['set'].add_data("TjohejDouble3", "double", "-12232131.3333") + iq['set'].add_data("TjohejDouble2", "double", "200.22"); + iq['set'].add_data("TjohejDouble3", "double", "-12232131.3333"); - iq['set'].add_data("TjohejDur", "duration", "P5Y") - iq['set'].add_data("TjohejDur2", "duration", "PT2M1S") + iq['set'].add_data("TjohejDur", "duration", "P5Y"); + iq['set'].add_data("TjohejDur2", "duration", "PT2M1S"); - iq['set'].add_data("TjohejInt", "int", "1") - iq['set'].add_data("TjohejInt2", "int", "-42") + iq['set'].add_data("TjohejInt", "int", "1"); + iq['set'].add_data("TjohejInt2", "int", "-42"); - iq['set'].add_data("TjohejLong", "long", "123456789098") - iq['set'].add_data("TjohejLong2", "long", "-90983243827489374") + iq['set'].add_data("TjohejLong", "long", "123456789098"); + iq['set'].add_data("TjohejLong2", "long", "-90983243827489374"); - iq['set'].add_data("TjohejTime", "time", "23:59") - iq['set'].add_data("TjohejTime2", "time", "12:00") + iq['set'].add_data("TjohejTime", "time", "23:59"); + iq['set'].add_data("TjohejTime2", "time", "12:00"); self.check(iq,""" <iq type='set' @@ -242,5 +244,5 @@ class TestControlStanzas(SleekTest): </iq> """ ) - + suite = unittest.TestLoader().loadTestsFromTestCase(TestControlStanzas) diff --git a/tests/test_stream_xep_0323.py b/tests/test_stream_xep_0323.py index 94f1d638..fd2ad225 100644 --- a/tests/test_stream_xep_0323.py +++ b/tests/test_stream_xep_0323.py @@ -19,7 +19,7 @@ class TestStreamSensorData(SleekTest): pass def _time_now(self): - return datetime.datetime.now().replace(microsecond=0).isoformat() + return datetime.datetime.now().replace(microsecond=0).isoformat(); def tearDown(self): self.stream_close() @@ -29,12 +29,12 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device22") - myDevice._add_field(name="Temperature", typename="numeric", unit="°C") + 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"}) + 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.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); self.recv(""" <iq type='get' @@ -46,7 +46,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='1'> @@ -60,11 +60,11 @@ class TestStreamSensorData(SleekTest): <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'/> + <numeric name='Temperature' momentary='true' automaticReadout='true' value='23.4' unit='°C'/> </timestamp> </node> </fields> - </message> + </message> """) def testRequestRejectAuth(self): @@ -73,7 +73,7 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - self.xmpp['xep_0323']._set_authenticated("darth@deathstar.com") + self.xmpp['xep_0323']._set_authenticated("darth@deathstar.com"); self.recv(""" <iq type='get' @@ -85,7 +85,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='error' + <iq type='error' from='device@clayster.com' to='master@clayster.com/amr' id='4'> @@ -101,8 +101,8 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44") - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) + myDevice = Device("Device44"); + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); print("."), @@ -118,7 +118,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='error' + <iq type='error' from='device@clayster.com' to='master@clayster.com/amr' id='77'> @@ -142,7 +142,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='8'> @@ -157,11 +157,11 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44") - myDevice._add_field(name='Voltage', typename="numeric", unit="V") - myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) + myDevice = Device("Device44"); + myDevice._add_field(name='Voltage', typename="numeric", unit="V"); + myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); print("."), @@ -177,7 +177,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='error' + <iq type='error' from='device@clayster.com' to='master@clayster.com/amr' id='7'> @@ -201,7 +201,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='8'> @@ -215,11 +215,11 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='7'> <node nodeId='Device44'> <timestamp value='2000-01-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> + <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -227,7 +227,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> <fields xmlns='urn:xmpp:iot:sensordata' seqnr='7' done='true'> </fields> - </message> + </message> """) def testRequestMultiTimestampSingleField(self): @@ -236,15 +236,15 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44") - myDevice._add_field(name='Voltage', typename="numeric", unit="V") - myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) - myDevice._add_field(name='Current', typename="numeric", unit="A") - myDevice._add_field(name='Height', typename="string") - myDevice._add_field_timestamp_data(name="Voltage", value="230.6", timestamp="2000-01-01T01:01:02") - myDevice._add_field_timestamp_data(name="Height", value="115 m", timestamp="2000-01-01T01:01:02", flags={"invoiced": "true"}) + myDevice = Device("Device44"); + myDevice._add_field(name='Voltage', typename="numeric", unit="V"); + myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); + myDevice._add_field(name='Current', typename="numeric", unit="A"); + myDevice._add_field(name='Height', typename="string"); + myDevice._add_field_timestamp_data(name="Voltage", value="230.6", timestamp="2000-01-01T01:01:02"); + myDevice._add_field_timestamp_data(name="Height", value="115 m", timestamp="2000-01-01T01:01:02", flags={"invoiced": "true"}); - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); print("."), @@ -260,7 +260,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='8'> @@ -274,11 +274,11 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='7'> <node nodeId='Device44'> <timestamp value='2000-01-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> + <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -287,11 +287,11 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='7'> <node nodeId='Device44'> <timestamp value='2000-01-01T01:01:02'> - <numeric name='Voltage' value='230.6' unit='V'/> + <numeric name='Voltage' value='230.6' unit='V'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -299,7 +299,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> <fields xmlns='urn:xmpp:iot:sensordata' seqnr='7' done='true'> </fields> - </message> + </message> """) def testRequestMultiTimestampAllFields(self): @@ -308,15 +308,15 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44") - myDevice._add_field(name='Voltage', typename="numeric", unit="V") - myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) - myDevice._add_field(name='Current', typename="numeric", unit="A") - myDevice._add_field(name='Height', typename="string") - myDevice._add_field_timestamp_data(name="Voltage", value="230.6", timestamp="2000-01-01T01:01:02") - myDevice._add_field_timestamp_data(name="Height", value="115 m", timestamp="2000-01-01T01:01:02", flags={"invoiced": "true"}) + myDevice = Device("Device44"); + myDevice._add_field(name='Voltage', typename="numeric", unit="V"); + myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); + myDevice._add_field(name='Current', typename="numeric", unit="A"); + myDevice._add_field(name='Height', typename="string"); + myDevice._add_field_timestamp_data(name="Voltage", value="230.6", timestamp="2000-01-01T01:01:02"); + myDevice._add_field_timestamp_data(name="Height", value="115 m", timestamp="2000-01-01T01:01:02", flags={"invoiced": "true"}); - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); print("."), @@ -330,7 +330,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='8'> @@ -344,11 +344,11 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='7'> <node nodeId='Device44'> <timestamp value='2000-01-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> + <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -357,12 +357,12 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='7'> <node nodeId='Device44'> <timestamp value='2000-01-01T01:01:02'> - <numeric name='Voltage' value='230.6' unit='V'/> - <string name='Height' invoiced='true' value='115 m'/> + <numeric name='Voltage' value='230.6' unit='V'/> + <string name='Height' invoiced='true' value='115 m'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -370,7 +370,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> <fields xmlns='urn:xmpp:iot:sensordata' seqnr='7' done='true'> </fields> - </message> + </message> """) def testRequestAPI(self): @@ -379,7 +379,7 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", callback=None) + self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", callback=None); self.send(""" <iq type='get' @@ -390,7 +390,7 @@ class TestStreamSensorData(SleekTest): </iq> """) - self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=None) + self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=None); self.send(""" <iq type='get' @@ -404,7 +404,7 @@ class TestStreamSensorData(SleekTest): </iq> """) - self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", fields=['Temperature', 'Voltage'], callback=None) + self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", fields=['Temperature', 'Voltage'], callback=None); self.send(""" <iq type='get' @@ -424,13 +424,13 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = [] + results = []; def my_callback(from_jid, result, nodeId=None, timestamp=None, fields=None, error_msg=None): if (result == "rejected") and (error_msg == "Invalid device Device22"): - results.append("rejected") + results.append("rejected"); - self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=my_callback) + self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=my_callback); self.send(""" <iq type='get' @@ -445,20 +445,20 @@ class TestStreamSensorData(SleekTest): """) self.recv(""" - <iq type='error' + <iq type='error' from='you@google.com' to='tester@localhost' id='1'> <rejected xmlns='urn:xmpp:iot:sensordata' seqnr='1'> <error>Invalid device Device22</error> </rejected> - </iq> + </iq> """) time.sleep(.1) - self.failUnless(results == ["rejected"], - "Rejected callback was not properly executed") + self.failUnless(results == ["rejected"], + "Rejected callback was not properly executed"); def testRequestAcceptedAPI(self): @@ -466,12 +466,12 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = [] + results = []; def my_callback(from_jid, result, nodeId=None, timestamp=None, fields=None, error_msg=None): - results.append(result) + results.append(result); - self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=my_callback) + self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=my_callback); self.send(""" <iq type='get' @@ -486,18 +486,18 @@ class TestStreamSensorData(SleekTest): """) self.recv(""" - <iq type='result' + <iq type='result' from='you@google.com' to='tester@localhost' id='1'> <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1'/> - </iq> + </iq> """) time.sleep(.1) - self.failUnless(results == ["accepted"], - "Accepted callback was not properly executed") + self.failUnless(results == ["accepted"], + "Accepted callback was not properly executed"); def testRequestFieldsAPI(self): @@ -505,25 +505,25 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = [] - callback_data = {} + results = []; + callback_data = {}; def my_callback(from_jid, result, nodeId=None, timestamp=None, fields=None, error_msg=None): - results.append(result) + results.append(result); if result == "fields": - callback_data["nodeId"] = nodeId - callback_data["timestamp"] = timestamp - callback_data["error_msg"] = error_msg + callback_data["nodeId"] = nodeId; + callback_data["timestamp"] = timestamp; + callback_data["error_msg"] = error_msg; for f in fields: - callback_data["field_" + f['name']] = f + callback_data["field_" + f['name']] = f; t1= threading.Thread(name="request_data", target=self.xmpp['xep_0323'].request_data, - kwargs={"from_jid": "tester@localhost", - "to_jid": "you@google.com", - "nodeIds": ['Device33'], - "callback": my_callback}) - t1.start() + kwargs={"from_jid": "tester@localhost", + "to_jid": "you@google.com", + "nodeIds": ['Device33'], + "callback": my_callback}); + t1.start(); #self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback); self.send(""" @@ -538,12 +538,12 @@ class TestStreamSensorData(SleekTest): """) self.recv(""" - <iq type='result' + <iq type='result' from='you@google.com' to='tester@localhost' id='1'> <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1'/> - </iq> + </iq> """) self.recv(""" @@ -552,42 +552,42 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1'> <node nodeId='Device33'> <timestamp value='2000-01-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> - <boolean name='TestBool' value='true'/> + <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> + <boolean name='TestBool' value='true'/> </timestamp> </node> </fields> - </message> + </message> """) self.recv(""" <message from='you@google.com' to='tester@localhost'> <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1' done='true'/> - </message> + </message> """) - t1.join() + t1.join(); time.sleep(.5) - self.failUnlessEqual(results, ["accepted","fields","done"]) + self.failUnlessEqual(results, ["accepted","fields","done"]); # self.assertIn("nodeId", callback_data); self.assertTrue("nodeId" in callback_data) - self.failUnlessEqual(callback_data["nodeId"], "Device33") + self.failUnlessEqual(callback_data["nodeId"], "Device33"); # self.assertIn("timestamp", callback_data); - self.assertTrue("timestamp" in callback_data) - self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02") + self.assertTrue("timestamp" in callback_data); + self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02"); #self.assertIn("field_Voltage", callback_data); - self.assertTrue("field_Voltage" in callback_data) - self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}) + self.assertTrue("field_Voltage" in callback_data); + self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}); #self.assertIn("field_TestBool", callback_data); - self.assertTrue("field_TestBool" in callback_data) - self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }) + self.assertTrue("field_TestBool" in callback_data); + self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }); def testServiceDiscoveryClient(self): self.stream_start(mode='client', plugins=['xep_0030', - 'xep_0323']) + 'xep_0323']); self.recv(""" <iq type='get' @@ -605,14 +605,14 @@ class TestStreamSensorData(SleekTest): <query xmlns='http://jabber.org/protocol/disco#info'> <identity category='client' type='bot'/> <feature var='urn:xmpp:iot:sensordata'/> - </query> - </iq> + </query> + </iq> """) def testServiceDiscoveryComponent(self): self.stream_start(mode='component', plugins=['xep_0030', - 'xep_0323']) + 'xep_0323']); self.recv(""" <iq type='get' @@ -631,8 +631,8 @@ class TestStreamSensorData(SleekTest): <query xmlns='http://jabber.org/protocol/disco#info'> <identity category='component' type='generic'/> <feature var='urn:xmpp:iot:sensordata'/> - </query> - </iq> + </query> + </iq> """) def testRequestTimeout(self): @@ -641,23 +641,23 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = [] - callback_data = {} + results = []; + callback_data = {}; def my_callback(from_jid, result, nodeId=None, timestamp=None, error_msg=None): - results.append(result) + results.append(result); if result == "failure": - callback_data["nodeId"] = nodeId - callback_data["timestamp"] = timestamp - callback_data["error_msg"] = error_msg + callback_data["nodeId"] = nodeId; + callback_data["timestamp"] = timestamp; + callback_data["error_msg"] = error_msg; t1= threading.Thread(name="request_data", target=self.xmpp['xep_0323'].request_data, - kwargs={"from_jid": "tester@localhost", - "to_jid": "you@google.com", - "nodeIds": ['Device33'], - "callback": my_callback}) - t1.start() + kwargs={"from_jid": "tester@localhost", + "to_jid": "you@google.com", + "nodeIds": ['Device33'], + "callback": my_callback}); + t1.start(); self.send(""" <iq type='get' @@ -671,12 +671,12 @@ class TestStreamSensorData(SleekTest): """) self.recv(""" - <iq type='result' + <iq type='result' from='you@google.com' to='tester@localhost' id='1'> <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1'/> - </iq> + </iq> """) self.recv(""" @@ -688,31 +688,31 @@ class TestStreamSensorData(SleekTest): </message> """) - t1.join() + t1.join(); time.sleep(.5) - self.failUnlessEqual(results, ["accepted","failure"]) + self.failUnlessEqual(results, ["accepted","failure"]); # self.assertIn("nodeId", callback_data); - self.assertTrue("nodeId" in callback_data) - self.failUnlessEqual(callback_data["nodeId"], "Device33") + self.assertTrue("nodeId" in callback_data); + self.failUnlessEqual(callback_data["nodeId"], "Device33"); # self.assertIn("timestamp", callback_data); - self.assertTrue("timestamp" in callback_data) - self.failUnlessEqual(callback_data["timestamp"], "2013-03-07T17:13:30") + self.assertTrue("timestamp" in callback_data); + self.failUnlessEqual(callback_data["timestamp"], "2013-03-07T17:13:30"); # self.assertIn("error_msg", callback_data); - self.assertTrue("error_msg" in callback_data) - self.failUnlessEqual(callback_data["error_msg"], "Timeout.") + self.assertTrue("error_msg" in callback_data); + self.failUnlessEqual(callback_data["error_msg"], "Timeout."); 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 = 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"}) + 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.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); dtnow = datetime.datetime.now() ts_2sec = datetime.timedelta(0,2) @@ -729,7 +729,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='1'> @@ -743,7 +743,7 @@ class TestStreamSensorData(SleekTest): <message from='device@clayster.com' to='master@clayster.com/amr'> <started xmlns='urn:xmpp:iot:sensordata' seqnr='1' /> - </message> + </message> """) self.send(""" @@ -752,11 +752,11 @@ class TestStreamSensorData(SleekTest): <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'/> + <numeric name='Temperature' momentary='true' automaticReadout='true' value='23.4' unit='°C'/> </timestamp> </node> </fields> - </message> + </message> """) def testDelayedRequestFail(self): @@ -764,12 +764,12 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device22") - myDevice._add_field(name="Temperature", typename="numeric", unit="°C") + 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"}) + 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.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); dtnow = datetime.datetime.now() ts_2sec = datetime.timedelta(0,2) @@ -792,7 +792,7 @@ class TestStreamSensorData(SleekTest): xml_stanza['rejected']['error'] = error_text self._filtered_stanza_check(""" - <iq type='error' + <iq type='error' from='device@clayster.com' to='master@clayster.com/amr' id='1'> @@ -825,13 +825,13 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44") - myDevice._add_field(name='Voltage', typename="numeric", unit="V") - myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) - myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}) - myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}) + myDevice = Device("Device44"); + myDevice._add_field(name='Voltage', typename="numeric", unit="V"); + myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); + myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}); + myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}); - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); print("."), @@ -847,7 +847,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='6'> @@ -861,11 +861,11 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='6'> <node nodeId='Device44'> <timestamp value='2000-02-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.2' unit='V'/> + <numeric name='Voltage' invoiced='true' value='230.2' unit='V'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -874,11 +874,11 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='6'> <node nodeId='Device44'> <timestamp value='2000-03-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.3' unit='V'/> + <numeric name='Voltage' invoiced='true' value='230.3' unit='V'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -886,7 +886,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> <fields xmlns='urn:xmpp:iot:sensordata' seqnr='6' done='true'> </fields> - </message> + </message> """) def testRequestFieldTo(self): @@ -895,13 +895,13 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44") - myDevice._add_field(name='Voltage', typename="numeric", unit="V") - myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) - myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}) - myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}) + myDevice = Device("Device44"); + myDevice._add_field(name='Voltage', typename="numeric", unit="V"); + myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); + myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}); + myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}); - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); print("."), @@ -917,7 +917,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='6'> @@ -931,11 +931,11 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='6'> <node nodeId='Device44'> <timestamp value='2000-01-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.1' unit='V'/> + <numeric name='Voltage' invoiced='true' value='230.1' unit='V'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -944,11 +944,11 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='6'> <node nodeId='Device44'> <timestamp value='2000-02-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.2' unit='V'/> + <numeric name='Voltage' invoiced='true' value='230.2' unit='V'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -956,7 +956,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> <fields xmlns='urn:xmpp:iot:sensordata' seqnr='6' done='true'> </fields> - </message> + </message> """) def testRequestFieldFromTo(self): @@ -965,13 +965,13 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44") - myDevice._add_field(name='Voltage', typename="numeric", unit="V") - myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) - myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}) - myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}) + myDevice = Device("Device44"); + myDevice._add_field(name='Voltage', typename="numeric", unit="V"); + myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); + myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}); + myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}); - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); print("."), @@ -987,7 +987,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='6'> @@ -1001,11 +1001,11 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='6'> <node nodeId='Device44'> <timestamp value='2000-02-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.2' unit='V'/> + <numeric name='Voltage' invoiced='true' value='230.2' unit='V'/> </timestamp> </node> </fields> - </message> + </message> """) self.send(""" @@ -1013,7 +1013,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> <fields xmlns='urn:xmpp:iot:sensordata' seqnr='6' done='true'> </fields> - </message> + </message> """) def testDelayedRequestClient(self): @@ -1021,25 +1021,25 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = [] - callback_data = {} + results = []; + callback_data = {}; def my_callback(from_jid, result, nodeId=None, timestamp=None, fields=None, error_msg=None): - results.append(result) + results.append(result); if result == "fields": - callback_data["nodeId"] = nodeId - callback_data["timestamp"] = timestamp - callback_data["error_msg"] = error_msg + callback_data["nodeId"] = nodeId; + callback_data["timestamp"] = timestamp; + callback_data["error_msg"] = error_msg; for f in fields: - callback_data["field_" + f['name']] = f + callback_data["field_" + f['name']] = f; t1= threading.Thread(name="request_data", target=self.xmpp['xep_0323'].request_data, - kwargs={"from_jid": "tester@localhost", - "to_jid": "you@google.com", - "nodeIds": ['Device33'], - "callback": my_callback}) - t1.start() + kwargs={"from_jid": "tester@localhost", + "to_jid": "you@google.com", + "nodeIds": ['Device33'], + "callback": my_callback}); + t1.start(); #self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback); self.send(""" @@ -1054,20 +1054,20 @@ class TestStreamSensorData(SleekTest): """) self.recv(""" - <iq type='result' + <iq type='result' from='you@google.com' to='tester@localhost' id='1'> <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1' queued='true'/> - </iq> + </iq> """) self.recv(""" <message from='device@clayster.com' to='master@clayster.com/amr'> <started xmlns='urn:xmpp:iot:sensordata' seqnr='1' /> - </message> - """) + </message> + """) self.recv(""" <message from='you@google.com' @@ -1075,37 +1075,37 @@ class TestStreamSensorData(SleekTest): <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1'> <node nodeId='Device33'> <timestamp value='2000-01-01T00:01:02'> - <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> - <boolean name='TestBool' value='true'/> + <numeric name='Voltage' invoiced='true' value='230.4' unit='V'/> + <boolean name='TestBool' value='true'/> </timestamp> </node> </fields> - </message> + </message> """) self.recv(""" <message from='you@google.com' to='tester@localhost'> <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1' done='true'/> - </message> + </message> """) - t1.join() + t1.join(); time.sleep(.5) - self.failUnlessEqual(results, ["queued","started","fields","done"]) + self.failUnlessEqual(results, ["queued","started","fields","done"]); # self.assertIn("nodeId", callback_data); - self.assertTrue("nodeId" in callback_data) - self.failUnlessEqual(callback_data["nodeId"], "Device33") + self.assertTrue("nodeId" in callback_data); + self.failUnlessEqual(callback_data["nodeId"], "Device33"); # self.assertIn("timestamp", callback_data); - self.assertTrue("timestamp" in callback_data) - self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02") + self.assertTrue("timestamp" in callback_data); + self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02"); # self.assertIn("field_Voltage", callback_data); - self.assertTrue("field_Voltage" in callback_data) - self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}) + self.assertTrue("field_Voltage" in callback_data); + self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}); # self.assertIn("field_TestBool", callback_data); - self.assertTrue("field_TestBool" in callback_data) - self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }) + self.assertTrue("field_TestBool" in callback_data); + self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }); def testRequestFieldsCancelAPI(self): @@ -1114,12 +1114,12 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = [] + results = []; def my_callback(from_jid, result, nodeId=None, timestamp=None, fields=None, error_msg=None): - results.append(result) + results.append(result); - session = self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback) + session = self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback); self.send(""" <iq type='get' @@ -1133,15 +1133,15 @@ class TestStreamSensorData(SleekTest): """) self.recv(""" - <iq type='result' + <iq type='result' from='you@google.com' to='tester@localhost' id='1'> <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='1'/> - </iq> + </iq> """) - self.xmpp['xep_0323'].cancel_request(session=session) + self.xmpp['xep_0323'].cancel_request(session=session); self.send(""" <iq type='get' @@ -1163,19 +1163,19 @@ class TestStreamSensorData(SleekTest): time.sleep(.5) - self.failUnlessEqual(results, ["accepted","cancelled"]) + self.failUnlessEqual(results, ["accepted","cancelled"]); 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 = 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"}) + 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.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); dtnow = datetime.datetime.now() ts_2sec = datetime.timedelta(0,2) @@ -1192,7 +1192,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - <iq type='result' + <iq type='result' from='device@clayster.com' to='master@clayster.com/amr' id='1'> diff --git a/tests/test_stream_xep_0325.py b/tests/test_stream_xep_0325.py index 2ebdd121..4b3250fc 100644 --- a/tests/test_stream_xep_0325.py +++ b/tests/test_stream_xep_0325.py @@ -28,7 +28,7 @@ class TestStreamControl(SleekTest): pass def _time_now(self): - return datetime.datetime.now().replace(microsecond=0).isoformat() + return datetime.datetime.now().replace(microsecond=0).isoformat(); def tearDown(self): self.stream_close() @@ -38,10 +38,10 @@ class TestStreamControl(SleekTest): plugins=['xep_0030', 'xep_0325']) - myDevice = Device("Device22") - myDevice._add_control_field(name="Temperature", typename="int", value="15") + 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.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); self.recv(""" <iq type='set' @@ -60,26 +60,26 @@ class TestStreamControl(SleekTest): to='master@clayster.com/amr' id='1'> <setResponse xmlns='urn:xmpp:iot:control' responseCode="OK" /> - </iq> + </iq> """) - self.assertEqual(myDevice._get_field_value("Temperature"), "17") + self.assertEqual(myDevice._get_field_value("Temperature"), "17"); 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") + 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") + 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.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' @@ -99,11 +99,11 @@ class TestStreamControl(SleekTest): to='master@clayster.com/amr' id='1'> <setResponse xmlns='urn:xmpp:iot:control' responseCode="OK" /> - </iq> + </iq> """) - self.assertEqual(myDevice._get_field_value("Temperature"), "17") - self.assertEqual(myDevice2._get_field_value("Temperature"), "19") + self.assertEqual(myDevice._get_field_value("Temperature"), "17"); + self.assertEqual(myDevice2._get_field_value("Temperature"), "19"); self.recv(""" <iq type='set' @@ -125,23 +125,23 @@ class TestStreamControl(SleekTest): to='master@clayster.com/amr' id='2'> <setResponse xmlns='urn:xmpp:iot:control' responseCode="OK" /> - </iq> + </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") + 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"); 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") + 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.xmpp['xep_0325'].register_node(nodeId="Device23", device=myDevice, commTimeout=0.5); self.recv(""" <iq type='set' @@ -163,24 +163,24 @@ class TestStreamControl(SleekTest): <parameter name='Voltage' /> <error var='Output'>Invalid field Voltage</error> </setResponse> - </iq> + </iq> """) - self.assertEqual(myDevice._get_field_value("Temperature"), "15") - self.assertFalse(myDevice.has_control_field("Voltage", "int")) + self.assertEqual(myDevice._get_field_value("Temperature"), "15"); + self.assertFalse(myDevice.has_control_field("Voltage", "int")); def testDirectSetOk(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 = 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.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); self.recv(""" - <message + <message from='master@clayster.com/amr' to='device@clayster.com'> <set xmlns='urn:xmpp:iot:control'> @@ -191,20 +191,20 @@ class TestStreamControl(SleekTest): time.sleep(.5) - self.assertEqual(myDevice._get_field_value("Temperature"), "17") + self.assertEqual(myDevice._get_field_value("Temperature"), "17"); 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") + 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.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); self.recv(""" - <message + <message from='master@clayster.com/amr' to='device@clayster.com'> <set xmlns='urn:xmpp:iot:control'> @@ -215,8 +215,8 @@ class TestStreamControl(SleekTest): time.sleep(.5) - self.assertEqual(myDevice._get_field_value("Temperature"), "15") - self.assertFalse(myDevice.has_control_field("Voltage", "int")) + self.assertEqual(myDevice._get_field_value("Temperature"), "15"); + self.assertFalse(myDevice.has_control_field("Voltage", "int")); def testRequestSetOkAPI(self): @@ -225,16 +225,16 @@ class TestStreamControl(SleekTest): plugins=['xep_0030', 'xep_0325']) - results = [] + results = []; def my_callback(from_jid, result, nodeIds=None, fields=None, error_msg=None): - results.append(result) + results.append(result); fields = [] fields.append(("Temperature", "double", "20.5")) fields.append(("TemperatureAlarmSetting", "string", "High")) - self.xmpp['xep_0325'].set_request(from_jid="tester@localhost", to_jid="you@google.com", fields=fields, nodeIds=['Device33', 'Device22'], callback=my_callback) + self.xmpp['xep_0325'].set_request(from_jid="tester@localhost", to_jid="you@google.com", fields=fields, nodeIds=['Device33', 'Device22'], callback=my_callback); self.send(""" <iq type='set' @@ -256,12 +256,12 @@ class TestStreamControl(SleekTest): to='tester@localhost' id='1'> <setResponse xmlns='urn:xmpp:iot:control' responseCode="OK" /> - </iq> + </iq> """) time.sleep(.5) - self.assertEqual(results, ["OK"]) + self.assertEqual(results, ["OK"]); def testRequestSetErrorAPI(self): @@ -269,16 +269,16 @@ class TestStreamControl(SleekTest): plugins=['xep_0030', 'xep_0325']) - results = [] + results = []; def my_callback(from_jid, result, nodeIds=None, fields=None, error_msg=None): - results.append(result) + results.append(result); fields = [] fields.append(("Temperature", "double", "20.5")) fields.append(("TemperatureAlarmSetting", "string", "High")) - self.xmpp['xep_0325'].set_request(from_jid="tester@localhost", to_jid="you@google.com", fields=fields, nodeIds=['Device33', 'Device22'], callback=my_callback) + self.xmpp['xep_0325'].set_request(from_jid="tester@localhost", to_jid="you@google.com", fields=fields, nodeIds=['Device33', 'Device22'], callback=my_callback); self.send(""" <iq type='set' @@ -302,17 +302,17 @@ class TestStreamControl(SleekTest): <setResponse xmlns='urn:xmpp:iot:control' responseCode="OtherError" > <error var='Temperature'>Sensor error</error> </setResponse> - </iq> + </iq> """) time.sleep(.5) - self.assertEqual(results, ["OtherError"]) + self.assertEqual(results, ["OtherError"]); def testServiceDiscoveryClient(self): self.stream_start(mode='client', plugins=['xep_0030', - 'xep_0325']) + 'xep_0325']); self.recv(""" <iq type='get' @@ -330,14 +330,14 @@ class TestStreamControl(SleekTest): <query xmlns='http://jabber.org/protocol/disco#info'> <identity category='client' type='bot'/> <feature var='urn:xmpp:iot:control'/> - </query> - </iq> + </query> + </iq> """) def testServiceDiscoveryComponent(self): self.stream_start(mode='component', plugins=['xep_0030', - 'xep_0325']) + 'xep_0325']); self.recv(""" <iq type='get' @@ -356,8 +356,8 @@ class TestStreamControl(SleekTest): <query xmlns='http://jabber.org/protocol/disco#info'> <identity category='component' type='generic'/> <feature var='urn:xmpp:iot:control'/> - </query> - </iq> + </query> + </iq> """) |