from sleekxmpp.test import * import sleekxmpp.plugins.xep_0004 as xep_0004 class TestDataForms(SleekTest): def setUp(self): register_stanza_plugin(Message, xep_0004.Form) register_stanza_plugin(xep_0004.Form, xep_0004.FormField) register_stanza_plugin(xep_0004.FormField, xep_0004.FieldOption) def testMultipleInstructions(self): """Testing using multiple instructions elements in a data form.""" msg = self.Message() msg['form']['instructions'] = "Instructions\nSecond batch" self.check(msg, """ Instructions Second batch """) def testAddField(self): """Testing adding fields to a data form.""" msg = self.Message() form = msg['form'] form.addField(var='f1', ftype='text-single', label='Text', desc='A text field', required=True, value='Some text!') self.check(msg, """ A text field Some text! """) 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.check(msg, """ Enter message. A long one even. """) 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.check(msg, """ Foo! a b """) suite = unittest.TestLoader().loadTestsFromTestCase(TestDataForms)