Changeset 22:bb77a1005b63 in ralphm-patches


Ignore:
Timestamp:
Dec 31, 2009, 2:39:14 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Add bunch of missing tests.

Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • pubsub-forms.patch

    r21 r22  
    1 diff -r 2ad7e6f72b63 -r 438b64816faa wokkel/data_form.py
    2 --- a/wokkel/data_form.py       Wed Dec 30 21:16:04 2009 +0100
    3 +++ b/wokkel/data_form.py       Wed Dec 30 21:22:36 2009 +0100
     1diff -r 5ccaacff8028 wokkel/data_form.py
     2--- a/wokkel/data_form.py       Thu Dec 31 14:34:48 2009 +0100
     3+++ b/wokkel/data_form.py       Thu Dec 31 14:36:22 2009 +0100
    44@@ -76,6 +76,7 @@
    55             option['label'] = self.label
     
    5959             kwargs['options'] = options
    6060 
    61 @@ -343,7 +345,7 @@
    62      """
    63      Data Form.
    64  
    65 -    There are two similarly named properties of forms. The L{formType} is the
    66 +    There are two similarly named properties of forms. The C{formType} is the
    67      the so-called type of the form, and is set as the C{'type'} attribute
    68      on the form's root element.
    69  
    70 @@ -351,19 +353,25 @@
    71      provide a context for the field names used in this form, by setting a
    72      special hidden field named C{'FORM_TYPE'}, to put the names of all
    73      other fields in the namespace of the value of that field. This namespace
    74 -    is recorded in the L{formNamespace} instance variable.
    75 +    is recorded in the C{formNamespace} instance variable.
    76  
    77      @ivar formType: Type of form. One of C{'form'}, C{'submit'}, {'cancel'},
    78                      or {'result'}.
    79 -    @type formType: C{str}.
    80 +    @type formType: C{str}
    81 +
    82      @ivar formNamespace: The optional namespace of the field names for this
    83 -                         form. This goes in the special field named
    84 -                         C{'FORM_TYPE'}, if set.
    85 -    @type formNamespace: C{str}.
    86 -    @ivar fields: Dictionary of fields that have a name. Note that this is
    87 -                  meant to be used for reading, only. One should use
    88 -                  L{addField} for adding fields.
    89 +        form. This goes in the special field named C{'FORM_TYPE'}, if set.
    90 +    @type formNamespace: C{str}
    91 +
    92 +    @ivar fields: Dictionary of named fields. Note that this is meant to be
    93 +        used for reading, only. One should use L{addField} or L{makeFields} and
    94 +        L{removeField} for adding and removing fields.
    95      @type fields: C{dict}
    96 +
    97 +    @ivar fieldList: List of all fields, in the order they are added. Like
    98 +        C{fields}, this is meant to be used for reading, only.
    99 +    @type fieldList: C{list}
    100 +
    101      """
    102  
    103      def __init__(self, formType, title=None, instructions=None,
    104 @@ -403,7 +411,7 @@
     61@@ -415,7 +417,7 @@
    10562         """
    10663         Add a field to this form.
     
    11168         adding new fields. Multiple fields with the same name are disallowed.
    11269         """
    113 @@ -416,7 +424,71 @@
     70@@ -428,7 +430,71 @@
    11471         self.fieldList.append(field)
    11572 
     
    183140         form['type'] = self.formType
    184141 
    185 @@ -477,7 +549,17 @@
     142@@ -489,7 +555,17 @@
    186143 
    187144         return form
     
    201158 
    202159         for name, field in self.fields.iteritems():
    203 @@ -489,3 +571,48 @@
     160@@ -501,3 +577,48 @@
    204161             values[name] = value
    205162 
     
    250207+        for field in filtered:
    251208+            self.removeField(field)
    252 diff -r 2ad7e6f72b63 -r 438b64816faa wokkel/pubsub.py
    253 --- a/wokkel/pubsub.py  Wed Dec 30 21:16:04 2009 +0100
    254 +++ b/wokkel/pubsub.py  Wed Dec 30 21:22:36 2009 +0100
     209diff -r 5ccaacff8028 wokkel/pubsub.py
     210--- a/wokkel/pubsub.py  Thu Dec 31 14:34:48 2009 +0100
     211+++ b/wokkel/pubsub.py  Thu Dec 31 14:36:22 2009 +0100
    255212@@ -1012,29 +1012,11 @@
    256213             return None
     
    286243 
    287244 
     245diff -r 5ccaacff8028 wokkel/test/test_data_form.py
     246--- a/wokkel/test/test_data_form.py     Thu Dec 31 14:34:48 2009 +0100
     247+++ b/wokkel/test/test_data_form.py     Thu Dec 31 14:36:22 2009 +0100
     248@@ -544,3 +544,42 @@
     249         field2 = data_form.Field(var='test', value='value2')
     250         form.addField(field1)
     251         self.assertRaises(data_form.Error, form.addField, field2)
     252+
     253+
     254+    def test_removeField(self):
     255+        """
     256+        A removed field should not occur in fieldList.
     257+        """
     258+        form = data_form.Form('result')
     259+        field = data_form.Field('fixed', value='Section 1')
     260+        form.addField(field)
     261+        form.removeField(field)
     262+        self.assertNotIn(field, form.fieldList)
     263+
     264+
     265+    def test_removeFieldNamed(self):
     266+        """
     267+        A removed named field should not occur in fields.
     268+        """
     269+        form = data_form.Form('result')
     270+        field = data_form.Field(var='test', value='test1')
     271+        form.addField(field)
     272+        form.removeField(field)
     273+        self.assertNotIn('test', form.fields)
     274+
     275+
     276+    def test_makeFieldsJID(self):
     277+        values = {'pubsub#creator': jid.JID('user@example.org')}
     278+        form = data_form.Form('result')
     279+        form.makeFields(values)
     280+        field = form.fields['pubsub#creator']
     281+        self.assertEqual('jid-single', field.fieldType)
     282+
     283+
     284+    def test_makeFieldsJIDMulti(self):
     285+        values = {'pubsub#contact': [jid.JID('user@example.org'),
     286+                                     jid.JID('other@example.org')]}
     287+        form = data_form.Form('result')
     288+        form.makeFields(values)
     289+        field = form.fields['pubsub#contact']
     290+        self.assertEqual('jid-multi', field.fieldType)
  • series

    r21 r22  
     1form-missing-tests.patch
    12pubsub-forms.patch
    23pubsub-request-options-form.patch
Note: See TracChangeset for help on using the changeset viewer.