source: ralphm-patches/data_form_parse_type.patch @ 1:7fc86463b39f

Last change on this file since 1:7fc86463b39f was 1:7fc86463b39f, checked in by Ralph Meijer <ralphm@…>, 12 years ago

Add patches.

File size: 4.5 KB
RevLine 
[1]1* * *
2
3diff -r d6bbf24ef053 wokkel/data_form.py
4--- a/wokkel/data_form.py       Tue Jan 13 18:30:35 2009 +0000
5+++ b/wokkel/data_form.py       Sat Feb 14 21:17:05 2009 +0100
6@@ -295,10 +295,6 @@
7     @staticmethod
8     def _parse_value(field, element):
9         value = unicode(element)
10-        if field.fieldType == 'boolean':
11-            value = value.lower() in ('1', 'true')
12-        elif field.fieldType in ('jid-multi', 'jid-single'):
13-            value = JID(value)
14         field.values.append(value)
15 
16 
17diff -r d6bbf24ef053 wokkel/test/test_data_form.py
18--- a/wokkel/test/test_data_form.py     Tue Jan 13 18:30:35 2009 +0000
19+++ b/wokkel/test/test_data_form.py     Sat Feb 14 21:17:05 2009 +0100
20@@ -229,11 +229,50 @@
21         self.assertEquals(None, field.fieldType)
22 
23 
24-    def test_fromElementValue(self):
25+    def test_fromElementValueTextSingle(self):
26+        """
27+        Parsed text-single field values should be of type C{unicode}.
28+        """
29         element = domish.Element((NS_X_DATA, 'field'))
30-        element.addElement("value", content="text")
31+        element['type'] = 'text-single'
32+        element.addElement('value', content=u'text')
33         field = data_form.Field.fromElement(element)
34         self.assertEquals('text', field.value)
35+
36+
37+    def test_fromElementValueJID(self):
38+        """
39+        Parsed jid-single field values should be of type C{unicode}.
40+        """
41+        element = domish.Element((NS_X_DATA, 'field'))
42+        element['type'] = 'jid-single'
43+        element.addElement('value', content=u'user@example.org')
44+        field = data_form.Field.fromElement(element)
45+        self.assertEquals(u'user@example.org', field.value)
46+
47+    def test_fromElementValueJIDMalformed(self):
48+        """
49+        Parsed jid-single field values should be of type C{unicode}.
50+
51+        No validation should be done at this point, so invalid JIDs should
52+        also be passed as-is.
53+        """
54+        element = domish.Element((NS_X_DATA, 'field'))
55+        element['type'] = 'jid-single'
56+        element.addElement('value', content=u'@@')
57+        field = data_form.Field.fromElement(element)
58+        self.assertEquals(u'@@', field.value)
59+
60+
61+    def test_fromElementValueBoolean(self):
62+        """
63+        Parsed boolean field values should be of type C{unicode}.
64+        """
65+        element = domish.Element((NS_X_DATA, 'field'))
66+        element['type'] = 'boolean'
67+        element.addElement('value', content=u'false')
68+        field = data_form.Field.fromElement(element)
69+        self.assertEquals(u'false', field.value)
70 
71 
72 
73diff -r d6bbf24ef053 wokkel/test/test_pubsub.py
74--- a/wokkel/test/test_pubsub.py        Tue Jan 13 18:30:35 2009 +0000
75+++ b/wokkel/test/test_pubsub.py        Sat Feb 14 21:17:05 2009 +0100
76@@ -708,7 +708,10 @@
77                      "label": "Persist items to storage"},
78                 "pubsub#deliver_payloads":
79                     {"type": "boolean",
80-                     "label": "Deliver payloads with event notifications"}
81+                     "label": "Deliver payloads with event notifications"},
82+                "pubsub#owner":
83+                    {"type": "jid-single",
84+                     "label": "Owner of the node"}
85                 }
86 
87         def getConfiguration(requestor, service, nodeIdentifier):
88@@ -717,7 +720,8 @@
89             self.assertEqual('test', nodeIdentifier)
90 
91             return defer.succeed({'pubsub#deliver_payloads': '0',
92-                                  'pubsub#persist_items': '1'})
93+                                  'pubsub#persist_items': '1',
94+                                  'pubsub#owner': JID('user@example.org')})
95 
96         def cb(element):
97             self.assertEqual('pubsub', element.name)
98@@ -730,12 +734,20 @@
99             self.assertIn('pubsub#deliver_payloads', fields)
100             field = fields['pubsub#deliver_payloads']
101             self.assertEqual('boolean', field.fieldType)
102+            field.typeCheck()
103             self.assertEqual(False, field.value)
104 
105             self.assertIn('pubsub#persist_items', fields)
106             field = fields['pubsub#persist_items']
107             self.assertEqual('boolean', field.fieldType)
108+            field.typeCheck()
109             self.assertEqual(True, field.value)
110+
111+            self.assertIn('pubsub#owner', fields)
112+            field = fields['pubsub#owner']
113+            self.assertEqual('jid-single', field.fieldType)
114+            field.typeCheck()
115+            self.assertEqual(JID('user@example.org'), field.value)
116 
117         self.service.getConfigurationOptions = getConfigurationOptions
118         self.service.getConfiguration = getConfiguration
Note: See TracBrowser for help on using the repository browser.