Ignore:
Timestamp:
Jan 12, 2009, 9:10:58 PM (14 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@158
Message:

Selectively render Data Forms fields depending on form type.

Author: ralphm.
Reviewer: tofu.
Fixes #40.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_data_form.py

    r29 r50  
    1 # Copyright (c) 2003-2008 Ralph Meijer
     1# Copyright (c) 2003-2009 Ralph Meijer
    22# See LICENSE for details.
    33
     
    3838
    3939    def test_basic(self):
     40        """
     41        Test basic field initialization.
     42        """
    4043        field = Field(var='test')
    4144        self.assertEqual('text-single', field.fieldType)
    4245        self.assertEqual('test', field.var)
    4346
     47
     48    def test_noFieldName(self):
     49        field = Field()
     50        self.assertRaises(FieldNameRequiredError, field.toElement)
     51
     52
     53    def test_toElement(self):
     54        """
     55        Test rendering to a DOM.
     56        """
     57        field = Field(var='test')
    4458        element = field.toElement()
    4559
     
    4761        self.assertEquals('field', element.name)
    4862        self.assertEquals(NS_X_DATA, element.uri)
    49         self.assertEquals('text-single', element['type'])
     63        self.assertEquals('text-single',
     64                          element.getAttribute('type', 'text-single'))
    5065        self.assertEquals('test', element['var'])
    5166        self.assertEquals([], element.children)
    5267
    5368
    54     def test_noFieldName(self):
    55         field = Field()
    56         self.assertRaises(FieldNameRequiredError, field.toElement)
     69    def test_toElementTypeNotListSingle(self):
     70        """
     71        Always render the field type, if different from list-single.
     72        """
     73        field = Field('hidden', var='test')
     74        element = field.toElement()
     75
     76        self.assertEquals('hidden', element.getAttribute('type'))
     77
     78
     79    def test_toElementAsForm(self):
     80        """
     81        Always render the field type, if asForm is True.
     82        """
     83        field = Field(var='test')
     84        element = field.toElement(True)
     85
     86        self.assertEquals('text-single', element.getAttribute('type'))
     87
     88
     89    def test_toElementOptions(self):
     90        """
     91        Test rendering to a DOM with options.
     92        """
     93        field = Field('list-single', var='test')
     94        field.options = [Option(u'option1'), Option(u'option2')]
     95        element = field.toElement(True)
     96
     97        self.assertEqual(2, len(element.children))
     98
     99
     100    def test_toElementLabel(self):
     101        """
     102        Test rendering to a DOM with a label.
     103        """
     104        field = Field(var='test', label=u'my label')
     105        element = field.toElement(True)
     106
     107        self.assertEqual(u'my label', element.getAttribute('label'))
     108
     109
     110    def test_toElementDescription(self):
     111        """
     112        Test rendering to a DOM with options.
     113        """
     114        field = Field(var='test', desc=u'My desc')
     115        element = field.toElement(True)
     116
     117        self.assertEqual(1, len(element.children))
     118        child = element.children[0]
     119        self.assertEqual('desc', child.name)
     120        self.assertEqual(NS_X_DATA, child.uri)
     121        self.assertEqual(u'My desc', unicode(child))
     122
     123
     124    def test_toElementRequired(self):
     125        """
     126        Test rendering to a DOM with options.
     127        """
     128        field = Field(var='test', required=True)
     129        element = field.toElement(True)
     130
     131        self.assertEqual(1, len(element.children))
     132        child = element.children[0]
     133        self.assertEqual('required', child.name)
     134        self.assertEqual(NS_X_DATA, child.uri)
    57135
    58136
Note: See TracChangeset for help on using the changeset viewer.