Changeset 7410 for main/waeup.sirp/trunk/src/waeup/sirp/widgets/tests
- Timestamp:
- 20 Dec 2011, 12:34:26 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/widgets/tests/test_phonewidget.py
r7354 r7410 49 49 required = True) 50 50 51 bar = schema.TextLine( 52 title = u'Phone', 53 description = u'Phone number (not required)', 54 required = False) 55 51 56 class SampleContent: 52 57 implements(ISampleContent) … … 71 76 self.field = ISampleContent['foo'] 72 77 self.field = self.field.bind(self.content) 78 self.field_nonreq = ISampleContent['bar'] 79 self.field_nonreq = self.field_nonreq.bind(self.content) 73 80 74 81 # create an empty request. We need one to create a widget 75 82 self.request = TestRequest() 76 83 self.widget = PhoneWidget(self.field, self.request) 84 self.widget_nonreq = PhoneWidget(self.field_nonreq, self.request) 77 85 return 78 86 … … 96 104 self.assertEqual(self.widget.visible, True) 97 105 self.assertEqual(self.widget.required, True) 106 self.assertEqual(self.widget_nonreq.required, False) 98 107 return 99 108 … … 422 431 self.assertTrue('value="3333"' in widget()) 423 432 return 433 434 def test_render_changed_prefix(self): 435 # when the prefix is changed, the subwidgets will reflect that 436 # properly. This tests a regression: if setPrefix was called 437 # on the phone widget, the subwidgets were already assuming 438 # that there is no data in the request 439 request = TestRequest(form={ 440 'field.foo.country': '11', 441 'field.foo.area': '222', 442 'field.foo.extension': '3333'}) 443 self.content.foo = u'22-333-4444' 444 widget = PhoneWidget(self.field, request) 445 # when setting a wrong prefix (not in the form), subwidgets 446 # will display the content values assuming (correctly) there 447 # is no data sent for them in the request. 448 widget.setPrefix('not-existent.') 449 self.assertTrue('value="4444"' in widget()) 450 # when setting the right prefix, subwidgets will display the 451 # sent form values and not the content values. 452 widget.setPrefix('field.') 453 self.assertTrue('value="3333"' in widget()) 454 return 455 456 def test_non_required_no_input(self): 457 # if the bound field requires no input phone widget will cope 458 # with that. 459 class Content(object): 460 field = None 461 462 content = Content() 463 request = TestRequest(form={ 464 'field.foo.country': '11', 465 'field.foo.area': '222', 466 'field.foo.extension': '3333'}) 467 widget = PhoneWidget(self.field_nonreq, request) 468 result1 = widget.applyChanges(content) 469 result2 = widget.getInputValue() 470 self.assertEqual(result1, True) 471 # without input we get the default value set 472 self.assertEqual(content.bar, u'') 473 self.assertEqual(result2, u'') 474 return
Note: See TracChangeset for help on using the changeset viewer.