From 0fffbb82000a1a6c3c23d62fedcbd8e8141f8994 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 7 Oct 2010 10:58:13 -0400 Subject: Unit test reorganization. Moved SleekTest to sleekxmpp.test. Organized test suites by their focus. - Suites focused on testing stanza objects are named test_stanza_X.py - Suites focused on testing stream behavior are name test_stream_X.py --- tests/test_stanza_xep_0004.py | 115 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 tests/test_stanza_xep_0004.py (limited to 'tests/test_stanza_xep_0004.py') diff --git a/tests/test_stanza_xep_0004.py b/tests/test_stanza_xep_0004.py new file mode 100644 index 00000000..835f0dd6 --- /dev/null +++ b/tests/test_stanza_xep_0004.py @@ -0,0 +1,115 @@ +from sleekxmpp.test import * +import sleekxmpp.plugins.xep_0004 as xep_0004 + + +class TestDataForms(SleekTest): + + def setUp(self): + registerStanzaPlugin(Message, xep_0004.Form) + registerStanzaPlugin(xep_0004.Form, xep_0004.FormField) + registerStanzaPlugin(xep_0004.FormField, xep_0004.FieldOption) + + def testMultipleInstructions(self): + """Testing using multiple instructions elements in a data form.""" + msg = self.Message() + msg['form']['instructions'] = "Instructions\nSecond batch" + + self.check_message(msg, """ + + + Instructions + Second batch + + + """) + + def testAddField(self): + """Testing adding fields to a data form.""" + + msg = self.Message() + form = msg['form'] + form.addField(var='f1', + ftype='text-single', + label='Text', + desc='A text field', + required=True, + value='Some text!') + + self.check_message(msg, """ + + + + A text field + + Some text! + + + + """) + + form['fields'] = [('f1', {'type': 'text-single', + 'label': 'Username', + 'required': True}), + ('f2', {'type': 'text-private', + 'label': 'Password', + 'required': True}), + ('f3', {'type': 'text-multi', + 'label': 'Message', + 'value': 'Enter message.\nA long one even.'}), + ('f4', {'type': 'list-single', + 'label': 'Message Type', + 'options': [{'label': 'Cool!', + 'value': 'cool'}, + {'label': 'Urgh!', + 'value': 'urgh'}]})] + self.check_message(msg, """ + + + + + + + + + + Enter message. + A long one even. + + + + + + + + """) + + def testSetValues(self): + """Testing setting form values""" + + msg = self.Message() + form = msg['form'] + form.setFields([ + ('foo', {'type': 'text-single'}), + ('bar', {'type': 'list-multi'})]) + + form.setValues({'foo': 'Foo!', + 'bar': ['a', 'b']}) + + self.check_message(msg, """ + + + + Foo! + + + a + b + + + """) + +suite = unittest.TestLoader().loadTestsFromTestCase(TestDataForms) -- cgit v1.2.3