Changeset 5376
- Timestamp:
- 6 Aug 2010, 08:50:23 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.widgets.core/trunk/src/waeup/widgets/core/tests/test_dictwidget.py
r5371 r5376 156 156 sw = CustomWidgetFactory(DictWidget) 157 157 widget = sw(self.field, request) 158 assert widget.subwidget is None 158 assert widget.key_subwidget is None 159 assert widget.value_subwidget is None 159 160 assert widget.context.value_type is value_type 160 161 … … 162 163 class PollOption(object) : pass 163 164 ow = CustomWidgetFactory(ObjectWidget, PollOption) 164 sw = CustomWidgetFactory(DictWidget, subwidget=ow)165 sw = CustomWidgetFactory(DictWidget, key_subwidget=ow) 165 166 widget = sw(self.field, request) 166 assert widget. subwidget is ow167 assert widget.key_subwidget is ow 167 168 assert widget.context.value_type is value_type 168 169 assert widget.context.key_type is key_type … … 181 182 ow = CustomWidgetFactory(ObjectWidget, PollOption) 182 183 widget = DictWidget( 183 self.field, request, subwidget=ow) 184 assert widget.subwidget is ow 184 self.field, request, key_subwidget=ow, value_subwidget=ow) 185 assert widget.key_subwidget is ow 186 assert widget.value_subwidget is ow 185 187 assert widget() is not None 186 188 189 def test_renders_subwidgets(self): 190 self.field = Dict(__name__=u'foo', 191 key_type=TextLine(__name__=u'bar'), 192 value_type=TextLine(__name__=u'baz'), 193 ) 194 request = TestRequest(form={'field.foo.add': u'Add bar', 195 'field.foo.count': u'0'}) 196 197 # a text widget the outputs an additional silly header 198 class CustomTextWidget(TextWidget): 199 def __call__(self): 200 result = super(CustomTextWidget, self).__call__() 201 return 'CUSTOM WIDGET\n' + result 202 pass 203 ctw = CustomWidgetFactory(CustomTextWidget) 204 widget = DictWidget( 205 self.field, request, key_subwidget=ctw, value_subwidget=ctw) 206 assert widget.key_subwidget is ctw 207 assert widget.value_subwidget is ctw 208 209 check_list = ( 210 'checkbox', 'field.foo.remove_0', 211 'CUSTOM WIDGET', 212 'input', 'field.foo.key.0.bar', 213 'CUSTOM WIDGET', 214 'input', 'field.foo.value.0.baz', 215 'submit', 'submit', 'field.foo.add', 216 'field.foo.count" value="1"', 217 ) 218 self.verifyResult(widget(), check_list, inorder=True) 219 187 220 def test_dict(self): 188 221 self.field = Dict( … … 439 472 assert widget.applyChanges(foo_obj) is True 440 473 474 def test_missing_value(self): 475 self.field.missing_value = u'No Input' 476 request = TestRequest() 477 widget = DictWidget( 478 self.field, request) 479 # Passing a different string than the missing value will mean trouble 480 widget.setRenderedValue('Some string unequal to "No Input"') 481 self.assertRaises( 482 ValueError, widget._getRenderedValue,) 483 # Setting the content to the specified string, however, works: 484 widget.setRenderedValue(u'No Input') 485 assert isinstance(widget._getRenderedValue(), type({})) 486 assert widget._getRenderedValue() == {} 487 488 def test_default_value(self): 489 request = TestRequest() 490 self.field.default = {u'somekey': u'somevalue'} 491 widget = DictWidget( 492 self.field, request) 493 assert widget._getRenderedValue() == {u'somekey': u'somevalue'} 441 494 442 495 class SequenceDisplayWidgetTest( … … 490 543 self.verifyResult(self.widget(), check_list, inorder=True) 491 544 492 def test_honors_ subwidget(self):545 def test_honors_key_subwidget(self): 493 546 self.widget = self._WidgetFactory( 494 547 self.field, self.request, 495 subwidget=UppercaseDisplayWidget)548 key_subwidget=UppercaseDisplayWidget) 496 549 self.content.foo = {u'first value': u'second value'} 497 550 check_list = ['<ol', 'class=', 'testwidget', 498 '<li', 'FIRST VALUE: SECOND VALUE', '</li', 551 '<li', 'FIRST VALUE: second value', '</li', 552 '</ol'] 553 self.verifyResult(self.widget(), check_list, inorder=True) 554 555 def test_honors_value_subwidget(self): 556 self.widget = self._WidgetFactory( 557 self.field, self.request, 558 value_subwidget=UppercaseDisplayWidget) 559 self.content.foo = {u'first value': u'second value'} 560 check_list = ['<ol', 'class=', 'testwidget', 561 '<li', 'first value: SECOND VALUE', '</li', 499 562 '</ol'] 500 563 self.verifyResult(self.widget(), check_list, inorder=True)
Note: See TracChangeset for help on using the changeset viewer.