summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-13 01:28:18 -0700
committerLance Stout <lancestout@gmail.com>2011-08-13 01:28:18 -0700
commit017d7ec62bf02c72729be668d1f8ef3b144222fb (patch)
tree03454418bbffc30e2a41a1de557155e4b7e3328d /tests
parent76826b5495bc64d92ad4ffae3abca738c7b5e134 (diff)
downloadslixmpp-017d7ec62bf02c72729be668d1f8ef3b144222fb.tar.gz
slixmpp-017d7ec62bf02c72729be668d1f8ef3b144222fb.tar.bz2
slixmpp-017d7ec62bf02c72729be668d1f8ef3b144222fb.tar.xz
slixmpp-017d7ec62bf02c72729be668d1f8ef3b144222fb.zip
Add tests for setting a form's type to 'submit' or 'cancel'.
Form fields now remember their current type if the type is deleted. This allows for fields to properly format their values if set after the form has been changed to the 'submit' type.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_stanza_xep_0004.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/test_stanza_xep_0004.py b/tests/test_stanza_xep_0004.py
index 22f8b77d..e183e5e9 100644
--- a/tests/test_stanza_xep_0004.py
+++ b/tests/test_stanza_xep_0004.py
@@ -117,4 +117,82 @@ class TestDataForms(SleekTest):
</x>
</message>""")
+ def testSubmitType(self):
+ """Test that setting type to 'submit' clears extra details"""
+ msg = self.Message()
+ form = msg['form']
+
+ fields = OrderedDict()
+ fields['f1'] = {'type': 'text-single',
+ 'label': 'Username',
+ 'required': True}
+ fields['f2'] = {'type': 'text-private',
+ 'label': 'Password',
+ 'required': True}
+ fields['f3'] = {'type': 'text-multi',
+ 'label': 'Message',
+ 'value': 'Enter message.\nA long one even.'}
+ fields['f4'] = {'type': 'list-single',
+ 'label': 'Message Type',
+ 'options': [{'label': 'Cool!',
+ 'value': 'cool'},
+ {'label': 'Urgh!',
+ 'value': 'urgh'}]}
+ form['fields'] = fields
+
+ form['type'] = 'submit'
+ form['values'] = {'f1': 'username',
+ 'f2': 'hunter2',
+ 'f3': 'A long\nmultiline\nmessage',
+ 'f4': 'cool'}
+
+ self.check(form, """
+ <x xmlns="jabber:x:data" type="submit">
+ <field var="f1">
+ <value>username</value>
+ </field>
+ <field var="f2">
+ <value>hunter2</value>
+ </field>
+ <field var="f3">
+ <value>A long</value>
+ <value>multiline</value>
+ <value>message</value>
+ </field>
+ <field var="f4">
+ <value>cool</value>
+ </field>
+ </x>
+ """, use_values=False)
+
+ def testCancelType(self):
+ """Test that setting type to 'cancel' clears all fields"""
+ msg = self.Message()
+ form = msg['form']
+
+ fields = OrderedDict()
+ fields['f1'] = {'type': 'text-single',
+ 'label': 'Username',
+ 'required': True}
+ fields['f2'] = {'type': 'text-private',
+ 'label': 'Password',
+ 'required': True}
+ fields['f3'] = {'type': 'text-multi',
+ 'label': 'Message',
+ 'value': 'Enter message.\nA long one even.'}
+ fields['f4'] = {'type': 'list-single',
+ 'label': 'Message Type',
+ 'options': [{'label': 'Cool!',
+ 'value': 'cool'},
+ {'label': 'Urgh!',
+ 'value': 'urgh'}]}
+ form['fields'] = fields
+
+ form['type'] = 'cancel'
+
+ self.check(form, """
+ <x xmlns="jabber:x:data" type="cancel" />
+ """)
+
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestDataForms)