Changeset 56:01740c205934


Ignore:
Timestamp:
Apr 22, 2009, 4:53:43 PM (12 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@168
Message:

Don't do type interpretation on parsing Data Forms fields.

Location:
wokkel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wokkel/data_form.py

    r51 r56  
    296296    def _parse_value(field, element):
    297297        value = unicode(element)
    298         if field.fieldType == 'boolean':
    299             value = value.lower() in ('1', 'true')
    300         elif field.fieldType in ('jid-multi', 'jid-single'):
    301             value = JID(value)
    302298        field.values.append(value)
    303299
  • wokkel/test/test_data_form.py

    r51 r56  
    230230
    231231
    232     def test_fromElementValue(self):
    233         element = domish.Element((NS_X_DATA, 'field'))
    234         element.addElement("value", content="text")
     232    def test_fromElementValueTextSingle(self):
     233        """
     234        Parsed text-single field values should be of type C{unicode}.
     235        """
     236        element = domish.Element((NS_X_DATA, 'field'))
     237        element['type'] = 'text-single'
     238        element.addElement('value', content=u'text')
    235239        field = data_form.Field.fromElement(element)
    236240        self.assertEquals('text', field.value)
     241
     242
     243    def test_fromElementValueJID(self):
     244        """
     245        Parsed jid-single field values should be of type C{unicode}.
     246        """
     247        element = domish.Element((NS_X_DATA, 'field'))
     248        element['type'] = 'jid-single'
     249        element.addElement('value', content=u'user@example.org')
     250        field = data_form.Field.fromElement(element)
     251        self.assertEquals(u'user@example.org', field.value)
     252
     253    def test_fromElementValueJIDMalformed(self):
     254        """
     255        Parsed jid-single field values should be of type C{unicode}.
     256
     257        No validation should be done at this point, so invalid JIDs should
     258        also be passed as-is.
     259        """
     260        element = domish.Element((NS_X_DATA, 'field'))
     261        element['type'] = 'jid-single'
     262        element.addElement('value', content=u'@@')
     263        field = data_form.Field.fromElement(element)
     264        self.assertEquals(u'@@', field.value)
     265
     266
     267    def test_fromElementValueBoolean(self):
     268        """
     269        Parsed boolean field values should be of type C{unicode}.
     270        """
     271        element = domish.Element((NS_X_DATA, 'field'))
     272        element['type'] = 'boolean'
     273        element.addElement('value', content=u'false')
     274        field = data_form.Field.fromElement(element)
     275        self.assertEquals(u'false', field.value)
    237276
    238277
  • wokkel/test/test_pubsub.py

    r53 r56  
    754754                "pubsub#deliver_payloads":
    755755                    {"type": "boolean",
    756                      "label": "Deliver payloads with event notifications"}
     756                     "label": "Deliver payloads with event notifications"},
     757                "pubsub#owner":
     758                    {"type": "jid-single",
     759                     "label": "Owner of the node"}
    757760                }
    758761
     
    763766
    764767            return defer.succeed({'pubsub#deliver_payloads': '0',
    765                                   'pubsub#persist_items': '1'})
     768                                  'pubsub#persist_items': '1',
     769                                  'pubsub#owner': JID('user@example.org')})
    766770
    767771        def cb(element):
     
    776780            field = fields['pubsub#deliver_payloads']
    777781            self.assertEqual('boolean', field.fieldType)
     782            field.typeCheck()
    778783            self.assertEqual(False, field.value)
    779784
     
    781786            field = fields['pubsub#persist_items']
    782787            self.assertEqual('boolean', field.fieldType)
     788            field.typeCheck()
    783789            self.assertEqual(True, field.value)
     790
     791            self.assertIn('pubsub#owner', fields)
     792            field = fields['pubsub#owner']
     793            self.assertEqual('jid-single', field.fieldType)
     794            field.typeCheck()
     795            self.assertEqual(JID('user@example.org'), field.value)
    784796
    785797        self.service.getConfigurationOptions = getConfigurationOptions
Note: See TracChangeset for help on using the changeset viewer.