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
  • wokkel/data_form.py

    * * *
    
    diff -r d6bbf24ef053 wokkel/data_form.py
    a b  
    295295    @staticmethod
    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
    304300
  • wokkel/test/test_data_form.py

    diff -r d6bbf24ef053 wokkel/test/test_data_form.py
    a b  
    229229        self.assertEquals(None, field.fieldType)
    230230
    231231
    232     def test_fromElementValue(self):
     232    def test_fromElementValueTextSingle(self):
     233        """
     234        Parsed text-single field values should be of type C{unicode}.
     235        """
    233236        element = domish.Element((NS_X_DATA, 'field'))
    234         element.addElement("value", content="text")
     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
    239278
  • wokkel/test/test_pubsub.py

    diff -r d6bbf24ef053 wokkel/test/test_pubsub.py
    a b  
    708708                     "label": "Persist items to storage"},
    709709                "pubsub#deliver_payloads":
    710710                    {"type": "boolean",
    711                      "label": "Deliver payloads with event notifications"}
     711                     "label": "Deliver payloads with event notifications"},
     712                "pubsub#owner":
     713                    {"type": "jid-single",
     714                     "label": "Owner of the node"}
    712715                }
    713716
    714717        def getConfiguration(requestor, service, nodeIdentifier):
     
    717720            self.assertEqual('test', nodeIdentifier)
    718721
    719722            return defer.succeed({'pubsub#deliver_payloads': '0',
    720                                   'pubsub#persist_items': '1'})
     723                                  'pubsub#persist_items': '1',
     724                                  'pubsub#owner': JID('user@example.org')})
    721725
    722726        def cb(element):
    723727            self.assertEqual('pubsub', element.name)
     
    730734            self.assertIn('pubsub#deliver_payloads', fields)
    731735            field = fields['pubsub#deliver_payloads']
    732736            self.assertEqual('boolean', field.fieldType)
     737            field.typeCheck()
    733738            self.assertEqual(False, field.value)
    734739
    735740            self.assertIn('pubsub#persist_items', fields)
    736741            field = fields['pubsub#persist_items']
    737742            self.assertEqual('boolean', field.fieldType)
     743            field.typeCheck()
    738744            self.assertEqual(True, field.value)
     745
     746            self.assertIn('pubsub#owner', fields)
     747            field = fields['pubsub#owner']
     748            self.assertEqual('jid-single', field.fieldType)
     749            field.typeCheck()
     750            self.assertEqual(JID('user@example.org'), field.value)
    739751
    740752        self.service.getConfigurationOptions = getConfigurationOptions
    741753        self.service.getConfiguration = getConfiguration
Note: See TracBrowser for help on using the repository browser.