summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-07-20 12:16:57 -0400
committerLance Stout <lancestout@gmail.com>2010-07-20 12:16:57 -0400
commitde24e9ed458cea4bccb9962b69e5fb4271841b3d (patch)
tree4aaa117c1d3dad92d82e22a7d9595fcee1c01543 /tests
parent9724efa123c2727e7617236a0c55238e286f6b00 (diff)
downloadslixmpp-de24e9ed458cea4bccb9962b69e5fb4271841b3d.tar.gz
slixmpp-de24e9ed458cea4bccb9962b69e5fb4271841b3d.tar.bz2
slixmpp-de24e9ed458cea4bccb9962b69e5fb4271841b3d.tar.xz
slixmpp-de24e9ed458cea4bccb9962b69e5fb4271841b3d.zip
Lots of XEP-0004 bug fixes.
Forms have default type of 'form' setFields now uses a list of tuples instead of a dictionary because ordering is important. getFields defaults to returning a list of tuples, but the use_dict parameter can change that
Diffstat (limited to 'tests')
-rw-r--r--tests/test_forms.py71
1 files changed, 48 insertions, 23 deletions
diff --git a/tests/test_forms.py b/tests/test_forms.py
index 16160249..7d37506d 100644
--- a/tests/test_forms.py
+++ b/tests/test_forms.py
@@ -1,5 +1,5 @@
from sleektest import *
-import sleekxmpp.plugins.alt_0004 as xep_0004
+import sleekxmpp.plugins.xep_0004 as xep_0004
class TestDataForms(SleekTest):
@@ -16,19 +16,19 @@ class TestDataForms(SleekTest):
self.checkMessage(msg, """
<message>
- <x xmlns="jabber:x:data">
+ <x xmlns="jabber:x:data" type="form">
<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',
+ form.addField(var='f1',
ftype='text-single',
label='Text',
desc='A text field',
@@ -37,7 +37,7 @@ class TestDataForms(SleekTest):
self.checkMessage(msg, """
<message>
- <x xmlns="jabber:x:data">
+ <x xmlns="jabber:x:data" type="form">
<field var="f1" type="text-single" label="Text">
<desc>A text field</desc>
<required />
@@ -45,26 +45,26 @@ class TestDataForms(SleekTest):
</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'}]}}
+ 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">
+ <x xmlns="jabber:x:data" type="form">
<field var="f1" type="text-single" label="Username">
<required />
</field>
@@ -85,6 +85,31 @@ class TestDataForms(SleekTest):
</field>
</x>
</message>
- """, use_values=False)
+ """)
+
+ 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.checkMessage(msg, """
+ <message>
+ <x xmlns="jabber:x:data" type="form">
+ <field var="foo" type="text-single">
+ <value>Foo!</value>
+ </field>
+ <field var="bar" type="list-multi">
+ <value>a</value>
+ <value>b</value>
+ </field>
+ </x>
+ </message>""")
suite = unittest.TestLoader().loadTestsFromTestCase(TestDataForms)