Ignore:
Timestamp:
Jan 5, 2010, 11:46:50 AM (12 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Add missing tests for Data Forms and correct some minor issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/data_form.py

    r56 r78  
    11# -*- test-case-name: wokkel.test.test_data_form -*-
    22#
    3 # Copyright (c) 2003-2009 Ralph Meijer
     3# Copyright (c) 2003-2010 Ralph Meijer
    44# See LICENSE for details.
    55
     
    252252
    253253        for value in self.values:
    254             if self.fieldType == 'boolean':
     254            if isinstance(value, bool):
    255255                value = unicode(value).lower()
    256             elif self.fieldType in ('jid-single', 'jid-multi'):
    257                 value = value.full()
     256            else:
     257                value = unicode(value)
    258258
    259259            field.addElement('value', content=value)
     
    344344    Data Form.
    345345
    346     There are two similarly named properties of forms. The L{formType} is the
     346    There are two similarly named properties of forms. The C{formType} is the
    347347    the so-called type of the form, and is set as the C{'type'} attribute
    348348    on the form's root element.
     
    352352    special hidden field named C{'FORM_TYPE'}, to put the names of all
    353353    other fields in the namespace of the value of that field. This namespace
    354     is recorded in the L{formNamespace} instance variable.
     354    is recorded in the C{formNamespace} instance variable.
    355355
    356356    @ivar formType: Type of form. One of C{'form'}, C{'submit'}, {'cancel'},
    357357                    or {'result'}.
    358     @type formType: C{str}.
     358    @type formType: C{str}
     359
     360    @ivar title: Natural language title of the form.
     361    @type title: C{unicode}
     362
     363    @ivar instructions: Natural language instructions as a list of C{unicode}
     364        strings without line breaks.
     365    @type instructions: C{list}
     366
    359367    @ivar formNamespace: The optional namespace of the field names for this
    360                          form. This goes in the special field named
    361                          C{'FORM_TYPE'}, if set.
     368        form. This goes in the special field named C{'FORM_TYPE'}, if set.
    362369    @type formNamespace: C{str}.
    363     @ivar fields: Dictionary of fields that have a name. Note that this is
    364                   meant to be used for reading, only. One should use
    365                   L{addField} for adding fields.
     370
     371    @ivar fields: Dictionary of named fields. Note that this is meant to be
     372        used for reading, only. One should use L{addField} or L{makeFields} and
     373        L{removeField} for adding and removing fields.
    366374    @type fields: C{dict}
     375
     376    @ivar fieldList: List of all fields, in the order they are added. Like
     377        C{fields}, this is meant to be used for reading, only.
     378    @type fieldList: C{list}
    367379    """
    368380
     
    393405            r.append(", formNamespace=")
    394406            r.append(repr(self.formNamespace))
    395         if self.fields:
     407        if self.fieldList:
    396408            r.append(", fields=")
    397409            r.append(repr(self.fieldList))
     
    425437
    426438        for instruction in self.instructions:
    427             form.addElement('instruction', content=instruction)
     439            form.addElement('instructions', content=instruction)
    428440
    429441        if self.formNamespace is not None:
     
    478490        return form
    479491
     492
    480493    def getValues(self):
     494        """
     495        Extract values from the named form fields.
     496
     497        For all named fields, the corresponding value or values are
     498        returned in a dictionary keyed by the field name. For multi-value
     499        fields, the dictionary value is a list, otherwise a single value.
     500
     501        If a field has no type, and the field has multiple values, the value of
     502        the dictionary entry is the list of values. Otherwise, it will be a
     503        single value.
     504
     505        @rtype: C{dict}
     506        """
    481507        values = {}
    482508
    483509        for name, field in self.fields.iteritems():
    484             if len(field.values) > 1:
     510            if (field.fieldType in ('jid-multi', 'list-multi', 'text-multi') or
     511                (field.fieldType is None and len(field.values) > 1)):
    485512                value = field.values
    486513            else:
Note: See TracChangeset for help on using the changeset viewer.