summaryrefslogtreecommitdiff
path: root/tests/test_forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_forms.py')
-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)