1 # -*- coding: utf-8 -*-
3 Slixmpp: The Slick XMPP Library
4 Implementation of xeps for Internet of Things
5 http://wiki.xmpp.org/web/Tech_pages/IoT_systems
6 Copyright (C) 2013 Sustainable Innovation, Joachim.lindborg@sust.se, bjorn.westrom@consoden.se
7 This file is part of Slixmpp.
9 See the file LICENSE for copying permission.
12 from slixmpp
.test
import *
13 import slixmpp
.plugins
.xep_0325
as xep_0325
17 class TestControlStanzas(SlixTest
):
23 def testSetRequest(self
):
25 test of set request stanza
29 iq
['from'] = 'master@clayster.com/amr'
30 iq
['to'] = 'device@clayster.com'
32 iq
['set'].add_node("Device02", "Source02", "MyCacheType");
33 iq
['set'].add_node("Device15");
34 iq
['set'].add_data("Tjohej", "boolean", "true")
38 from='master@clayster.com/amr'
39 to='device@clayster.com'
41 <set xmlns='urn:xmpp:iot:control'>
42 <node nodeId='Device02' sourceId='Source02' cacheType='MyCacheType'/>
43 <node nodeId='Device15'/>
44 <boolean name='Tjohej' value='true'/>
50 iq
['set'].del_node("Device02");
54 from='master@clayster.com/amr'
55 to='device@clayster.com'
57 <set xmlns='urn:xmpp:iot:control'>
58 <node nodeId='Device15'/>
59 <boolean name='Tjohej' value='true'/>
65 iq
['set'].del_nodes();
69 from='master@clayster.com/amr'
70 to='device@clayster.com'
72 <set xmlns='urn:xmpp:iot:control'>
73 <boolean name='Tjohej' value='true'/>
80 def testDirectSet(self
):
82 test of direct set stanza
85 msg
['from'] = 'master@clayster.com/amr'
86 msg
['to'] = 'device@clayster.com'
87 msg
['set'].add_node("Device02");
88 msg
['set'].add_node("Device15");
89 msg
['set'].add_data("Tjohej", "boolean", "true")
93 from='master@clayster.com/amr'
94 to='device@clayster.com'>
95 <set xmlns='urn:xmpp:iot:control'>
96 <node nodeId='Device02'/>
97 <node nodeId='Device15'/>
98 <boolean name='Tjohej' value='true'/>
105 def testSetResponse(self
):
107 test of set response stanza
110 iq
['type'] = 'result'
111 iq
['from'] = 'master@clayster.com/amr'
112 iq
['to'] = 'device@clayster.com'
114 iq
['setResponse']['responseCode'] = "OK";
118 from='master@clayster.com/amr'
119 to='device@clayster.com'
121 <setResponse xmlns='urn:xmpp:iot:control' responseCode='OK' />
128 iq
['from'] = 'master@clayster.com/amr'
129 iq
['to'] = 'device@clayster.com'
131 iq
['setResponse']['responseCode'] = "OtherError";
132 iq
['setResponse']['error']['var'] = "Output";
133 iq
['setResponse']['error']['text'] = "Test of other error.!";
138 from='master@clayster.com/amr'
139 to='device@clayster.com'
141 <setResponse xmlns='urn:xmpp:iot:control' responseCode='OtherError'>
142 <error var='Output'>Test of other error.!</error>
150 iq
['from'] = 'master@clayster.com/amr'
151 iq
['to'] = 'device@clayster.com'
153 iq
['setResponse']['responseCode'] = "NotFound";
154 iq
['setResponse'].add_node("Device17", "Source09");
155 iq
['setResponse'].add_node("Device18", "Source09");
156 iq
['setResponse'].add_data("Tjohopp");
161 from='master@clayster.com/amr'
162 to='device@clayster.com'
164 <setResponse xmlns='urn:xmpp:iot:control' responseCode='NotFound'>
165 <node nodeId='Device17' sourceId='Source09'/>
166 <node nodeId='Device18' sourceId='Source09'/>
167 <parameter name='Tjohopp' />
173 def testSetRequestDatas(self
):
175 test of set request data stanzas
179 iq
['from'] = 'master@clayster.com/amr'
180 iq
['to'] = 'device@clayster.com'
182 iq
['set'].add_node("Device02", "Source02", "MyCacheType");
183 iq
['set'].add_node("Device15");
185 iq
['set'].add_data("Tjohej", "boolean", "true");
186 iq
['set'].add_data("Tjohej2", "boolean", "false");
188 iq
['set'].add_data("TjohejC", "color", "FF00FF");
189 iq
['set'].add_data("TjohejC2", "color", "00FF00");
191 iq
['set'].add_data("TjohejS", "string", "String1");
192 iq
['set'].add_data("TjohejS2", "string", "String2");
194 iq
['set'].add_data("TjohejDate", "date", "2012-01-01");
195 iq
['set'].add_data("TjohejDate2", "date", "1900-12-03");
197 iq
['set'].add_data("TjohejDateT4", "dateTime", "1900-12-03 12:30");
198 iq
['set'].add_data("TjohejDateT2", "dateTime", "1900-12-03 11:22");
200 iq
['set'].add_data("TjohejDouble2", "double", "200.22");
201 iq
['set'].add_data("TjohejDouble3", "double", "-12232131.3333");
203 iq
['set'].add_data("TjohejDur", "duration", "P5Y");
204 iq
['set'].add_data("TjohejDur2", "duration", "PT2M1S");
206 iq
['set'].add_data("TjohejInt", "int", "1");
207 iq
['set'].add_data("TjohejInt2", "int", "-42");
209 iq
['set'].add_data("TjohejLong", "long", "123456789098");
210 iq
['set'].add_data("TjohejLong2", "long", "-90983243827489374");
212 iq
['set'].add_data("TjohejTime", "time", "23:59");
213 iq
['set'].add_data("TjohejTime2", "time", "12:00");
217 from='master@clayster.com/amr'
218 to='device@clayster.com'
220 <set xmlns='urn:xmpp:iot:control'>
221 <node nodeId='Device02' sourceId='Source02' cacheType='MyCacheType'/>
222 <node nodeId='Device15'/>
223 <boolean name='Tjohej' value='true'/>
224 <boolean name='Tjohej2' value='false'/>
225 <color name='TjohejC' value='FF00FF'/>
226 <color name='TjohejC2' value='00FF00'/>
227 <string name='TjohejS' value='String1'/>
228 <string name='TjohejS2' value='String2'/>
229 <date name='TjohejDate' value='2012-01-01'/>
230 <date name='TjohejDate2' value='1900-12-03'/>
231 <dateTime name='TjohejDateT4' value='1900-12-03 12:30'/>
232 <dateTime name='TjohejDateT2' value='1900-12-03 11:22'/>
233 <double name='TjohejDouble2' value='200.22'/>
234 <double name='TjohejDouble3' value='-12232131.3333'/>
235 <duration name='TjohejDur' value='P5Y'/>
236 <duration name='TjohejDur2' value='PT2M1S'/>
237 <int name='TjohejInt' value='1'/>
238 <int name='TjohejInt2' value='-42'/>
239 <long name='TjohejLong' value='123456789098'/>
240 <long name='TjohejLong2' value='-90983243827489374'/>
241 <time name='TjohejTime' value='23:59'/>
242 <time name='TjohejTime2' value='12:00'/>
248 suite
= unittest
.TestLoader().loadTestsFromTestCase(TestControlStanzas
)