Add test case Reported->Data Form Validation
Add a test case that will verify that reported fields can contain data form validation data.
This commit is contained in:
parent
7059400020
commit
2a127a57a7
1 changed files with 36 additions and 4 deletions
|
@ -16,7 +16,7 @@ class TestDataForms(SleekTest):
|
||||||
register_stanza_plugin(xep_0004.FormField, xep_0122.FormValidation)
|
register_stanza_plugin(xep_0004.FormField, xep_0122.FormValidation)
|
||||||
|
|
||||||
def test_basic_validation(self):
|
def test_basic_validation(self):
|
||||||
"""Testing using multiple instructions elements in a data form."""
|
"""Testing basic validation setting and getting."""
|
||||||
msg = self.Message()
|
msg = self.Message()
|
||||||
form = msg['form']
|
form = msg['form']
|
||||||
field = form.addField(var='f1',
|
field = form.addField(var='f1',
|
||||||
|
@ -51,7 +51,7 @@ class TestDataForms(SleekTest):
|
||||||
self.assertFalse(validation.get_regex())
|
self.assertFalse(validation.get_regex())
|
||||||
|
|
||||||
def test_open_validation(self):
|
def test_open_validation(self):
|
||||||
"""Testing using multiple instructions elements in a data form."""
|
"""Testing open validation setting and getting."""
|
||||||
msg = self.Message()
|
msg = self.Message()
|
||||||
form = msg['form']
|
form = msg['form']
|
||||||
field = form.addField(var='f1',
|
field = form.addField(var='f1',
|
||||||
|
@ -85,7 +85,7 @@ class TestDataForms(SleekTest):
|
||||||
self.assertFalse(validation.get_regex())
|
self.assertFalse(validation.get_regex())
|
||||||
|
|
||||||
def test_regex_validation(self):
|
def test_regex_validation(self):
|
||||||
"""Testing using multiple instructions elements in a data form."""
|
"""Testing regex validation setting and getting."""
|
||||||
msg = self.Message()
|
msg = self.Message()
|
||||||
form = msg['form']
|
form = msg['form']
|
||||||
field = form.addField(var='f1',
|
field = form.addField(var='f1',
|
||||||
|
@ -123,7 +123,7 @@ class TestDataForms(SleekTest):
|
||||||
self.assertEqual(regex_value, validation.get_regex())
|
self.assertEqual(regex_value, validation.get_regex())
|
||||||
|
|
||||||
def test_range_validation(self):
|
def test_range_validation(self):
|
||||||
"""Testing using multiple instructions elements in a data form."""
|
"""Testing range validation setting and getting."""
|
||||||
msg = self.Message()
|
msg = self.Message()
|
||||||
form = msg['form']
|
form = msg['form']
|
||||||
field = form.addField(var='f1',
|
field = form.addField(var='f1',
|
||||||
|
@ -153,5 +153,37 @@ class TestDataForms(SleekTest):
|
||||||
|
|
||||||
self.assertDictEqual(dict(minimum=str(0), maximum=str(10)), validation.get_range())
|
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)
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestDataForms)
|
||||||
|
|
Loading…
Reference in a new issue