summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins
diff options
context:
space:
mode:
authorRobert Robinson <rerobins@gmail.com>2015-09-15 10:05:53 -0600
committerRobert Robinson <rerobins@gmail.com>2015-09-15 10:05:53 -0600
commit0b14ef82d4058925e7e9db22038777d4654e8199 (patch)
treefbbefac28f9b00c0c10f1e1d36e469b61a7ab35a /sleekxmpp/plugins
parent93c705fb3133b27388c0845f925b0615c88414b1 (diff)
downloadslixmpp-0b14ef82d4058925e7e9db22038777d4654e8199.tar.gz
slixmpp-0b14ef82d4058925e7e9db22038777d4654e8199.tar.bz2
slixmpp-0b14ef82d4058925e7e9db22038777d4654e8199.tar.xz
slixmpp-0b14ef82d4058925e7e9db22038777d4654e8199.zip
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.
Diffstat (limited to 'sleekxmpp/plugins')
-rw-r--r--sleekxmpp/plugins/xep_0004/stanza/form.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/sleekxmpp/plugins/xep_0004/stanza/form.py b/sleekxmpp/plugins/xep_0004/stanza/form.py
index f55e88a9..3dcc7821 100644
--- a/sleekxmpp/plugins/xep_0004/stanza/form.py
+++ b/sleekxmpp/plugins/xep_0004/stanza/form.py
@@ -9,7 +9,7 @@
import copy
import logging
-from sleekxmpp.thirdparty import OrderedDict
+from sleekxmpp.thirdparty import OrderedDict, OrderedSet
from sleekxmpp.xmlstream import ElementBase, ET
from sleekxmpp.plugins.xep_0004.stanza import FormField
@@ -22,7 +22,7 @@ class Form(ElementBase):
namespace = 'jabber:x:data'
name = 'x'
plugin_attrib = 'form'
- interfaces = set(('instructions', 'items', 'reported', 'title', 'type', ))
+ interfaces = OrderedSet(('instructions', 'reported', 'title', 'type', 'items', ))
sub_interfaces = set(('title',))
form_types = set(('cancel', 'form', 'result', 'submit'))
@@ -169,7 +169,7 @@ class Form(ElementBase):
def get_reported(self):
fields = OrderedDict()
xml = self.xml.findall('{%s}reported/{%s}field' % (self.namespace,
- FormField.namespace))
+ FormField.namespace))
for field in xml:
field = FormField(xml=field)
fields[field['var']] = field
@@ -219,10 +219,26 @@ class Form(ElementBase):
self.add_item(item)
def set_reported(self, reported):
+ """
+ This either needs a dictionary or dictionaries or a dictionary of form fields.
+ :param reported:
+ :return:
+ """
for var in reported:
field = reported[var]
- field['var'] = var
- self.add_reported(var, **field)
+
+ if isinstance(field, dict):
+ self.add_reported(**field)
+ else:
+ reported = self.xml.find('{%s}reported' % self.namespace)
+ if reported is None:
+ reported = ET.Element('{%s}reported' % self.namespace)
+ self.xml.append(reported)
+
+ fieldXML = ET.Element('{%s}field' % FormField.namespace)
+ reported.append(fieldXML)
+ new_field = FormField(xml=fieldXML)
+ new_field.values = field.values
def set_values(self, values):
fields = self.get_fields()