From 0724f623bb613007f9acd6540efd4f256c8b6503 Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Mon, 14 Sep 2015 14:31:17 -0600 Subject: Force forms and fields to use plugin resolution Instead of using the interface/subinterface code that was currently being implemented for the plugin. (cherry picked from commit 1467ec7) --- tests/test_stanza_xep_0004.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/test_stanza_xep_0004.py') diff --git a/tests/test_stanza_xep_0004.py b/tests/test_stanza_xep_0004.py index 9056c663..e8bc6593 100644 --- a/tests/test_stanza_xep_0004.py +++ b/tests/test_stanza_xep_0004.py @@ -11,8 +11,8 @@ 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) + register_stanza_plugin(xep_0004.Form, xep_0004.FormField, iterable=True) + register_stanza_plugin(xep_0004.FormField, xep_0004.FieldOption, iterable=True) def testMultipleInstructions(self): """Testing using multiple instructions elements in a data form.""" @@ -68,7 +68,7 @@ class TestDataForms(SleekTest): 'value': 'cool'}, {'label': 'Urgh!', 'value': 'urgh'}]} - form['fields'] = fields + form.set_fields(fields) self.check(msg, """ @@ -141,13 +141,13 @@ class TestDataForms(SleekTest): 'value': 'cool'}, {'label': 'Urgh!', 'value': 'urgh'}]} - form['fields'] = fields + form.set_fields(fields) form['type'] = 'submit' - form['values'] = {'f1': 'username', + form.set_values({'f1': 'username', 'f2': 'hunter2', 'f3': 'A long\nmultiline\nmessage', - 'f4': 'cool'} + 'f4': 'cool'}) self.check(form, """ @@ -189,7 +189,7 @@ class TestDataForms(SleekTest): 'value': 'cool'}, {'label': 'Urgh!', 'value': 'urgh'}]} - form['fields'] = fields + form.set_fields(fields) form['type'] = 'cancel' -- cgit v1.2.3 From 0b14ef82d4058925e7e9db22038777d4654e8199 Mon Sep 17 00:00:00 2001 From: Robert Robinson Date: Tue, 15 Sep 2015 10:05:53 -0600 Subject: Add test case for reported and items Previous stanza test cases didn't have test cases for reported and item field types in forms. This fixes that issue. Modified stanzabase to use an ordered dict so that can guarentee the that 'items' in a form are added after reported. Also updated the set of interfaces that are stored in Form to be a ordered set. Used the order set implementation from: https://code.activestate.com/recipes/576694/ The OrderedSet implementation is licensed under the MIT license and is developed by the same developer of the ordereddict. --- tests/test_stanza_xep_0004.py | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests/test_stanza_xep_0004.py') 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): """) + 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, """ + + + + + + + + username@example.org + + + + + """) + + 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, """ + + + + + + + + """) + suite = unittest.TestLoader().loadTestsFromTestCase(TestDataForms) -- cgit v1.2.3