summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_stanza_xep_0004.py47
-rw-r--r--tests/test_stanza_xep_0122.py40
2 files changed, 83 insertions, 4 deletions
diff --git a/tests/test_stanza_xep_0004.py b/tests/test_stanza_xep_0004.py
index e8bc6593..b87afb24 100644
--- a/tests/test_stanza_xep_0004.py
+++ b/tests/test_stanza_xep_0004.py
@@ -197,5 +197,52 @@ class TestDataForms(SleekTest):
<x xmlns="jabber:x:data" type="cancel" />
""")
+ def testReported(self):
+ msg = self.Message()
+ form = msg['form']
+ form['type'] = 'result'
+
+ form.add_reported(var='f1', ftype='text-single', label='Username')
+
+ form.add_item({'f1': 'username@example.org'})
+
+ self.check(msg, """
+ <message>
+ <x xmlns="jabber:x:data" type="result">
+ <reported>
+ <field var="f1" type="text-single" label="Username" />
+ </reported>
+ <item>
+ <field var="f1">
+ <value>username@example.org</value>
+ </field>
+ </item>
+ </x>
+ </message>
+ """)
+
+ def testSetReported(self):
+ msg = self.Message()
+ form = msg['form']
+ form['type'] = 'result'
+
+ reported = {'f1': {
+ 'var': 'f1',
+ 'type': 'text-single',
+ 'label': 'Username'
+ }}
+
+ form.set_reported(reported)
+
+ self.check(msg, """
+ <message>
+ <x xmlns="jabber:x:data" type="result">
+ <reported>
+ <field var="f1" type="text-single" label="Username" />
+ </reported>
+ </x>
+ </message>
+ """)
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestDataForms)
diff --git a/tests/test_stanza_xep_0122.py b/tests/test_stanza_xep_0122.py
index 5576c45f..fca49bbb 100644
--- a/tests/test_stanza_xep_0122.py
+++ b/tests/test_stanza_xep_0122.py
@@ -16,7 +16,7 @@ class TestDataForms(SleekTest):
register_stanza_plugin(xep_0004.FormField, xep_0122.FormValidation)
def test_basic_validation(self):
- """Testing using multiple instructions elements in a data form."""
+ """Testing basic validation setting and getting."""
msg = self.Message()
form = msg['form']
field = form.addField(var='f1',
@@ -51,7 +51,7 @@ class TestDataForms(SleekTest):
self.assertFalse(validation.get_regex())
def test_open_validation(self):
- """Testing using multiple instructions elements in a data form."""
+ """Testing open validation setting and getting."""
msg = self.Message()
form = msg['form']
field = form.addField(var='f1',
@@ -85,7 +85,7 @@ class TestDataForms(SleekTest):
self.assertFalse(validation.get_regex())
def test_regex_validation(self):
- """Testing using multiple instructions elements in a data form."""
+ """Testing regex validation setting and getting."""
msg = self.Message()
form = msg['form']
field = form.addField(var='f1',
@@ -123,7 +123,7 @@ class TestDataForms(SleekTest):
self.assertEqual(regex_value, validation.get_regex())
def test_range_validation(self):
- """Testing using multiple instructions elements in a data form."""
+ """Testing range validation setting and getting."""
msg = self.Message()
form = msg['form']
field = form.addField(var='f1',
@@ -153,5 +153,37 @@ class TestDataForms(SleekTest):
self.assertDictEqual(dict(minimum=str(0), maximum=str(10)), validation.get_range())
+ def test_reported_field_validation(self):
+ """
+ Testing adding validation to the field when it's stored in the reported.
+ :return:
+ """
+ msg = self.Message()
+ form = msg['form']
+ field = form.addReported(var='f1', ftype='text-single', label='Text')
+ validation = field['validate']
+ validation.set_basic(True)
+
+ form.addItem({'f1': 'Some text!'})
+
+ self.check(msg, """
+ <message>
+ <x xmlns="jabber:x:data" type="form">
+ <reported>
+ <field var="f1" type="text-single" label="Text">
+ <validate xmlns="http://jabber.org/protocol/xdata-validate">
+ <basic />
+ </validate>
+ </field>
+ </reported>
+ <item>
+ <field var="f1">
+ <value>Some text!</value>
+ </field>
+ </item>
+ </x>
+ </message>
+ """)
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestDataForms)