Ignore:
Timestamp:
4 Aug 2010, 19:15:31 (14 years ago)
Author:
uli
Message:

Add tests to increase test coverage. This revealed two errors in code
yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.widgets.core/trunk/src/waeup/widgets/core/tests/test_dictwidget.py

    r5366 r5369  
    3636from zope.formlib.widgets import SequenceWidget
    3737from zope.formlib.interfaces import IDisplayWidget
    38 from zope.formlib.interfaces import IInputWidget, MissingInputError
     38from zope.formlib.interfaces import (
     39    IInputWidget, MissingInputError, WidgetInputError)
    3940from zope.formlib.interfaces import IWidgetInputError, WidgetInputError
    4041from zope.formlib.interfaces import IWidgetInputErrorView
     
    106107                       IWidgetInputErrorView, '')
    107108
     109    def test_brokenTypeFields(self):
     110        """Artificially construct the case, that value_type or key_type of the
     111           field are not set. This is merely to keep test coverage
     112           happy.
     113        """
     114        request = TestRequest(form={'field.foo.key.0.bar': u'Hello',
     115                                    'field.foo.value.0.baz': u'world!',
     116                                    'field.foo.count': u'1'})
     117        broken_field =self.field
     118        broken_field.key_type = None
     119        widget = DictWidget(
     120            self.field, request)
     121        assert widget._getRenderedValue() == {}
     122
     123        broken_field.value_type = None
     124        widget = DictWidget(
     125            self.field, request)
     126        assert widget._getRenderedValue() == {}
     127
     128    def test_invalidCount(self):
     129        # If we get a count which is not a number, fail...
     130        request = TestRequest(form={'field.foo.key.0.bar': u'Hello',
     131                                    'field.foo.value.0.baz': u'world!',
     132                                    'field.foo.count': u'a'})
     133        widget = DictWidget(
     134            self.field, request)
     135        self.assertRaises(WidgetInputError, widget.getInputValue)
     136       
    108137    def test_haveNoData(self):
    109138        self.failIf(self._widget.hasInput())
     
    154183            self.field, request, subwidget=ow)
    155184        assert widget.subwidget is ow
     185        assert widget() is not None
    156186
    157187    def test_dict(self):
Note: See TracChangeset for help on using the changeset viewer.