1 # -*- coding: utf-8 -*-
3 from slixmpp
.test
import *
4 import slixmpp
.plugins
.xep_0323
as xep_0323
8 class TestSensorDataStanzas(SlixTest
):
13 #register_stanza_plugin(Iq, xep_0323.stanza.Request)
14 #register_stanza_plugin(Iq, xep_0323.stanza.Accepted)
15 #register_stanza_plugin(Message, xep_0323.stanza.Failure)
16 #register_stanza_plugin(xep_0323.stanza.Failure, xep_0323.stanza.Error)
17 #register_stanza_plugin(Iq, xep_0323.stanza.Rejected)
18 #register_stanza_plugin(Message, xep_0323.stanza.Fields)
19 #register_stanza_plugin(Message, xep_0323.stanza.Request)
20 #register_stanza_plugin(Message, xep_0323.stanza.Accepted)
21 #register_stanza_plugin(Message, xep_0323.stanza.Failure)
22 # register_stanza_plugin(Message, xep_0323.stanza.Result)
23 # register_stanza_plugin(Message, xep_0323.stanza.Gone)
24 # register_stanza_plugin(Message, xep_0323.stanza.Inactive)
25 # register_stanza_plugin(Message, xep_0323.stanza.Paused)
27 def testRequest(self
):
29 test of request stanza
33 iq
['from'] = 'master@clayster.com/amr'
34 iq
['to'] = 'device@clayster.com'
36 iq
['req']['seqnr'] = '1'
37 iq
['req']['momentary'] = 'true'
41 from='master@clayster.com/amr'
42 to='device@clayster.com'
44 <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true'/>
49 def testRequestNodes(self
):
51 test of request nodes stanza
55 iq
['from'] = 'master@clayster.com/amr'
56 iq
['to'] = 'device@clayster.com'
58 iq
['req']['seqnr'] = '1'
59 iq
['req']['momentary'] = 'true'
62 iq
['req'].add_node("Device02", "Source02", "CacheType");
63 iq
['req'].add_node("Device44");
67 from='master@clayster.com/amr'
68 to='device@clayster.com'
70 <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true'>
71 <node nodeId='Device02' sourceId='Source02' cacheType='CacheType'/>
72 <node nodeId='Device44'/>
78 iq
['req'].del_node("Device02");
82 from='master@clayster.com/amr'
83 to='device@clayster.com'
85 <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true'>
86 <node nodeId='Device44'/>
92 iq
['req'].del_nodes();
96 from='master@clayster.com/amr'
97 to='device@clayster.com'
99 <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true'>
105 def testRequestField(self
):
107 test of request field stanza
111 iq
['from'] = 'master@clayster.com/amr'
112 iq
['to'] = 'device@clayster.com'
114 iq
['req']['seqnr'] = '1'
115 iq
['req']['momentary'] = 'true'
118 iq
['req'].add_field("Top temperature");
119 iq
['req'].add_field("Bottom temperature");
123 from='master@clayster.com/amr'
124 to='device@clayster.com'
126 <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true'>
127 <field name='Top temperature'/>
128 <field name='Bottom temperature'/>
134 iq
['req'].del_field("Top temperature")
138 from='master@clayster.com/amr'
139 to='device@clayster.com'
141 <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true'>
142 <field name='Bottom temperature'/>
148 iq
['req'].del_fields()
152 from='master@clayster.com/amr'
153 to='device@clayster.com'
155 <req xmlns='urn:xmpp:iot:sensordata' seqnr='1' momentary='true'>
162 def testAccepted(self
):
164 test of request stanza
167 iq
['type'] = 'result'
168 iq
['from'] = 'device@clayster.com'
169 iq
['to'] = 'master@clayster.com/amr'
171 iq
['accepted']['seqnr'] = '2'
175 from='device@clayster.com'
176 to='master@clayster.com/amr'
178 <accepted xmlns='urn:xmpp:iot:sensordata' seqnr='2'/>
183 def testRejected(self
):
185 test of request stanza
189 iq
['from'] = 'device@clayster.com'
190 iq
['to'] = 'master@clayster.com/amr'
192 iq
['rejected']['seqnr'] = '4'
193 iq
['rejected']['error'] = 'Access denied.'
197 from='device@clayster.com'
198 to='master@clayster.com/amr'
200 <rejected xmlns='urn:xmpp:iot:sensordata' seqnr='4'>
201 <error>Access denied.</error>
207 def testFailure(self
):
209 test of failure stanza
212 msg
['from'] = 'device@clayster.com'
213 msg
['to'] = 'master@clayster.com/amr'
214 msg
['failure']['seqnr'] = '3'
215 msg
['failure']['done'] = 'true'
216 msg
['failure']['error']['nodeId'] = 'Device01'
217 msg
['failure']['error']['timestamp'] = '2013-03-07T17:13:30'
218 msg
['failure']['error']['text'] = 'Timeout.'
221 <message from='device@clayster.com'
222 to='master@clayster.com/amr'>
223 <failure xmlns='urn:xmpp:iot:sensordata' seqnr='3' done='true'>
224 <error nodeId='Device01' timestamp='2013-03-07T17:13:30'>
231 def testFields(self
):
233 test of fields stanza
236 msg
['from'] = 'device@clayster.com'
237 msg
['to'] = 'master@clayster.com/amr'
238 msg
['fields']['seqnr'] = '1'
240 node
= msg
['fields'].add_node("Device02");
241 ts
= node
.add_timestamp("2013-03-07T16:24:30");
243 data
= ts
.add_data(typename
="numeric", name
="Temperature", value
="-12.42", unit
='K');
244 data
['momentary'] = 'true';
245 data
['automaticReadout'] = 'true';
248 <message from='device@clayster.com'
249 to='master@clayster.com/amr'>
250 <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1'>
251 <node nodeId='Device02'>
252 <timestamp value='2013-03-07T16:24:30'>
253 <numeric name='Temperature' momentary='true' automaticReadout='true' value='-12.42' unit='K'/>
261 node
= msg
['fields'].add_node("EmptyDevice");
262 node
= msg
['fields'].add_node("Device04");
263 ts
= node
.add_timestamp("EmptyTimestamp");
267 <message from='device@clayster.com'
268 to='master@clayster.com/amr'>
269 <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1'>
270 <node nodeId='Device02'>
271 <timestamp value='2013-03-07T16:24:30'>
272 <numeric name='Temperature' momentary='true' automaticReadout='true' value='-12.42' unit='K'/>
275 <node nodeId='EmptyDevice'/>
276 <node nodeId='Device04'>
277 <timestamp value='EmptyTimestamp'/>
284 node
= msg
['fields'].add_node("Device77");
285 ts
= node
.add_timestamp("2013-05-03T12:00:01");
286 data
= ts
.add_data(typename
="numeric", name
="Temperature", value
="-12.42", unit
='K');
287 data
['historicalDay'] = 'true';
288 data
= ts
.add_data(typename
="numeric", name
="Speed", value
="312.42", unit
='km/h');
289 data
['historicalWeek'] = 'false';
290 data
= ts
.add_data(typename
="string", name
="Temperature name", value
="Bottom oil");
291 data
['historicalMonth'] = 'true';
292 data
= ts
.add_data(typename
="string", name
="Speed name", value
="Top speed");
293 data
['historicalQuarter'] = 'false';
294 data
= ts
.add_data(typename
="dateTime", name
="T1", value
="1979-01-01T00:00:00");
295 data
['historicalYear'] = 'true';
296 data
= ts
.add_data(typename
="dateTime", name
="T2", value
="2000-01-01T01:02:03");
297 data
['historicalOther'] = 'false';
298 data
= ts
.add_data(typename
="timeSpan", name
="TS1", value
="P5Y");
299 data
['missing'] = 'true';
300 data
= ts
.add_data(typename
="timeSpan", name
="TS2", value
="PT2M1S");
301 data
['manualEstimate'] = 'false';
302 data
= ts
.add_data(typename
="enum", name
="top color", value
="red", dataType
="string");
303 data
['invoiced'] = 'true';
304 data
= ts
.add_data(typename
="enum", name
="bottom color", value
="black", dataType
="string");
305 data
['powerFailure'] = 'false';
306 data
= ts
.add_data(typename
="boolean", name
="Temperature real", value
="false");
307 data
['historicalDay'] = 'true';
308 data
= ts
.add_data(typename
="boolean", name
="Speed real", value
="true");
309 data
['historicalWeek'] = 'false';
312 <message from='device@clayster.com'
313 to='master@clayster.com/amr'>
314 <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1'>
315 <node nodeId='Device02'>
316 <timestamp value='2013-03-07T16:24:30'>
317 <numeric name='Temperature' momentary='true' automaticReadout='true' value='-12.42' unit='K'/>
320 <node nodeId='EmptyDevice'/>
321 <node nodeId='Device04'>
322 <timestamp value='EmptyTimestamp'/>
324 <node nodeId='Device77'>
325 <timestamp value='2013-05-03T12:00:01'>
326 <numeric name='Temperature' historicalDay='true' value='-12.42' unit='K'/>
327 <numeric name='Speed' historicalWeek='false' value='312.42' unit='km/h'/>
328 <string name='Temperature name' historicalMonth='true' value='Bottom oil'/>
329 <string name='Speed name' historicalQuarter='false' value='Top speed'/>
330 <dateTime name='T1' historicalYear='true' value='1979-01-01T00:00:00'/>
331 <dateTime name='T2' historicalOther='false' value='2000-01-01T01:02:03'/>
332 <timeSpan name='TS1' missing='true' value='P5Y'/>
333 <timeSpan name='TS2' manualEstimate='false' value='PT2M1S'/>
334 <enum name='top color' invoiced='true' value='red' dataType='string'/>
335 <enum name='bottom color' powerFailure='false' value='black' dataType='string'/>
336 <boolean name='Temperature real' historicalDay='true' value='false'/>
337 <boolean name='Speed real' historicalWeek='false' value='true'/>
346 def testTimestamp(self
):
347 msg
= self
.Message();
349 msg
['from'] = 'device@clayster.com'
350 msg
['to'] = 'master@clayster.com/amr'
351 msg
['fields']['seqnr'] = '1'
353 node
= msg
['fields'].add_node("Device02");
354 node
= msg
['fields'].add_node("Device03");
356 ts
= node
.add_timestamp("2013-03-07T16:24:30");
357 ts
= node
.add_timestamp("2013-03-07T16:24:31");
362 <message from='device@clayster.com'
363 to='master@clayster.com/amr'>
364 <fields xmlns='urn:xmpp:iot:sensordata' seqnr='1'>
365 <node nodeId='Device02'/>
366 <node nodeId='Device03'>
367 <timestamp value='2013-03-07T16:24:30'/>
368 <timestamp value='2013-03-07T16:24:31'/>
376 def testStringIdsMatcher(self
):
378 test of StringIds follow spec
380 emptyStringIdXML
='<message xmlns="jabber:client"><fields xmlns="urn:xmpp:iot:sensordata" /></message>'
383 msg
['fields']['stringIds'] = "Nisse"
384 self
.check(msg
,emptyStringIdXML
)
385 msg
['fields']['stringIds'] = "Nisse___nje#"
386 self
.check(msg
,emptyStringIdXML
)
387 msg
['fields']['stringIds'] = "1"
388 self
.check(msg
,emptyStringIdXML
)
393 suite
= unittest
.TestLoader().loadTestsFromTestCase(TestSensorDataStanzas
)