From 45689fd8799186fd6be0b308745aef428ab50dcc Mon Sep 17 00:00:00 2001 From: Joachim Lindborg Date: Fri, 30 Aug 2013 02:29:52 +0200 Subject: First implementation of the xep_0323 and xep_325 used in IoT systems. Tests are added for stanza and streams --- tests/test_stanza_xep_0325.py | 248 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 tests/test_stanza_xep_0325.py (limited to 'tests/test_stanza_xep_0325.py') diff --git a/tests/test_stanza_xep_0325.py b/tests/test_stanza_xep_0325.py new file mode 100644 index 00000000..b15b764c --- /dev/null +++ b/tests/test_stanza_xep_0325.py @@ -0,0 +1,248 @@ +# -*- coding: utf-8 -*- +""" + SleekXMPP: The Sleek XMPP Library + Implementation of xeps for Internet of Things + http://wiki.xmpp.org/web/Tech_pages/IoT_systems + Copyright (C) 2013 Sustainable Innovation, Joachim.lindborg@sust.se, bjorn.westrom@consoden.se + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.test import * +import sleekxmpp.plugins.xep_0325 as xep_0325 + +namespace='sn' + +class TestControlStanzas(SleekTest): + + + def setUp(self): + pass + + def testSetRequest(self): + """ + test of set request stanza + """ + iq = self.Iq() + iq['type'] = 'set' + 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_data("Tjohej", "boolean", "true") + + self.check(iq,""" + + + + + + + + """ + ) + + iq['set'].del_node("Device02"); + + self.check(iq,""" + + + + + + + """ + ) + + iq['set'].del_nodes(); + + self.check(iq,""" + + + + + + """ + ) + + + def testDirectSet(self): + """ + test of direct set stanza + """ + 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_data("Tjohej", "boolean", "true") + + self.check(msg,""" + + + + + + + + """ + ) + + + def testSetResponse(self): + """ + test of set response stanza + """ + iq = self.Iq() + iq['type'] = 'result' + iq['from'] = 'master@clayster.com/amr' + iq['to'] = 'device@clayster.com' + iq['id'] = '8' + iq['setResponse']['responseCode'] = "OK"; + + self.check(iq,""" + + + + """ + ) + + iq = self.Iq() + iq['type'] = 'error' + 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.!"; + + + self.check(iq,""" + + + Test of other error.! + + + """ + ) + + iq = self.Iq() + iq['type'] = 'error' + 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"); + + + self.check(iq,""" + + + + + + + + """ + ) + + def testSetRequestDatas(self): + """ + test of set request data stanzas + """ + iq = self.Iq() + iq['type'] = 'set' + 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_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("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("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("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("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"); + + self.check(iq,""" + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + +suite = unittest.TestLoader().loadTestsFromTestCase(TestControlStanzas) -- cgit v1.2.3