summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-07-14 11:59:58 -0400
committerLance Stout <lancestout@gmail.com>2010-07-14 11:59:58 -0400
commit48f0843ace5a8d383abe493b999e7bd4699598d7 (patch)
tree5f382d38ded836bad5c80e26d33334023f248987 /tests
parentb1c997be1d7d7d456cad06ef436c01527e04df5d (diff)
downloadslixmpp-48f0843ace5a8d383abe493b999e7bd4699598d7.tar.gz
slixmpp-48f0843ace5a8d383abe493b999e7bd4699598d7.tar.bz2
slixmpp-48f0843ace5a8d383abe493b999e7bd4699598d7.tar.xz
slixmpp-48f0843ace5a8d383abe493b999e7bd4699598d7.zip
Added initial stanza object version of the xep_0004 plugin. Items/reported elements still need to be unit tested
Diffstat (limited to 'tests')
-rw-r--r--tests/test_forms.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/test_forms.py b/tests/test_forms.py
new file mode 100644
index 00000000..981d8870
--- /dev/null
+++ b/tests/test_forms.py
@@ -0,0 +1,90 @@
+from sleektest import *
+import sleekxmpp.plugins.alt_0004 as xep_0004
+
+
+class TestDataForms(SleekTest):
+
+ def setUp(self):
+ self.stanzaPlugin(Message, xep_0004.Form)
+ self.stanzaPlugin(xep_0004.Form, xep_0004.FormField)
+ self.stanzaPlugin(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.checkMessage(msg, """
+ <message>
+ <x xmlns="jabber:x:data">
+ <instructions>Instructions</instructions>
+ <instructions>Second batch</instructions>
+ </x>
+ </message>
+ """, use_values=False)
+
+ def testAddField(self):
+ """Testing adding fields to a data form."""
+
+ msg = self.Message()
+ form = msg['form']
+ form.addField('f1',
+ ftype='text-single',
+ label='Text',
+ desc='A text field',
+ required=True,
+ value='Some text!')
+
+ self.checkMessage(msg, """
+ <message>
+ <x xmlns="jabber:x:data">
+ <field var="f1" type="text-single" label="Text">
+ <desc>A text field</desc>
+ <required />
+ <value>Some text!</value>
+ </field>
+ </x>
+ </message>
+ """, use_values=False)
+
+ 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.checkMessage(msg, """
+ <message>
+ <x xmlns="jabber:x:data">
+ <field var="f1" type="text-single" label="Username">
+ <required />
+ </field>
+ <field var="f2" type="text-private" label="Password">
+ <required />
+ </field>
+ <field var="f3" type="text-multi" label="Message">
+ <value>Enter message.</value>
+ <value>A long one even.</value>
+ </field>
+ <field var="f4" type="list-single" label="Message Type">
+ <option label="Cool!">
+ <value>cool</value>
+ </option>
+ <option label="Urgh!">
+ <value>urgh</value>
+ </option>
+ </field>
+ </x>
+ </message>
+ """, use_values=False)
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestDataForms)