- Timestamp:
- 11 Mar 2012, 18:47:20 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_phonewidget.py
r7811 r7840 26 26 # XXX: could we possibly get rid of zope.app.testing? 27 27 from zope.app.testing.setup import placefulSetUp, placefulTearDown 28 from zope.component import provideAdapter 28 from zope.component import provideAdapter, getGlobalSiteManager 29 from zope.formlib import form 29 30 from zope.formlib.exception import WidgetInputErrorView 30 31 from zope.formlib.interfaces import ( … … 48 49 title = u'Phone', 49 50 description = u'Phone number (not required)', 50 required = False,) 51 required = False, 52 missing_value = u'') 51 53 52 54 baz = schema.TextLine( … … 54 56 description = u'Required phone with a default', 55 57 required = True, 56 default=u'234--') 58 #default=u'234--' 59 ) 57 60 58 61 class SampleContent: 59 62 implements(ISampleContent) 63 64 foo = None 65 bar = 'bar' 66 baz = None 60 67 61 68 class PhoneWidgetTests(unittest.TestCase): … … 497 504 u' value="" />\n')) 498 505 return 506 507 import zope.formlib 508 from zope import schema 509 from zope.formlib.tests.test_functional_objectwidget import ( 510 Test, PlacelessSetup, VerifyResults, traversingSetUp, xmlconfig, 511 PageTemplate, os, DefaultTraversable 512 ) 513 from zope.formlib.tests.test_functional_textwidget import( 514 FunctionalWidgetTestCase, patternExists) 515 from zope.formlib.widgets import TextWidget 516 from zope.component import adapts 517 from zope.interface import implements 518 from zope.traversing.interfaces import ITraversable 519 from waeup.kofa.widgets.phonewidget import PhoneWidget2, PhonePrefixes 520 521 class SampleForm(form.EditForm): 522 form_fields = form.fields(ISampleContent) 523 form_fields['foo'].custom_widget = PhoneWidget2 524 form_fields['bar'].custom_widget = PhoneWidget2 525 form_fields['baz'].custom_widget = PhoneWidget2 526 527 class PhoneWidget2Tests(FunctionalWidgetTestCase): 528 529 widgets = [ 530 (ITextLine, TextWidget), 531 ] 532 533 def setUp(self): 534 super(PhoneWidget2Tests, self).setUp() 535 self.gsm = getGlobalSiteManager() 536 self.reg_prefixes = PhonePrefixes() 537 self.gsm.registerUtility(self.reg_prefixes) 538 return 539 540 def tearDown(self): 541 self.gsm.unregisterUtility(self.reg_prefixes) 542 return 543 544 def test_display_editform(self): 545 content = SampleContent() 546 request = TestRequest() 547 html = SampleForm(content, request)() 548 # foo.country, foo.area and foo.ext exist 549 self.assert_(patternExists( 550 '<select .* name="form.foo.country".*>', html)) 551 self.assert_(patternExists( 552 '<input .* name="form.foo.area".* value="".*>', html)) 553 self.assert_(patternExists( 554 '<input .* name="form.foo.ext".* value="".*>', html)) 555 return 556 557 def test_submit_editform(self): 558 # we can submit an edit form 559 content = SampleContent() 560 request = TestRequest() 561 562 # submit edit view 563 request.form['form.foo.country'] = u'123' 564 request.form['form.foo.area'] = u'456' 565 request.form['form.foo.ext'] = u'7890' 566 request.form['form.actions.apply'] = u'' 567 SampleForm(content, request)() 568 569 # check new values in object 570 self.assertEqual(content.foo, u'123-456-7890') 571 return 572 573 def test_invalid_type(self): 574 # there is no invalid type for textline-based input 575 content = SampleContent() 576 request = TestRequest() 577 578 # submit invalid type for text line 579 request.form['form.foo.country'] = '123' 580 request.form['form.foo.area'] = '456' 581 request.form['form.foo.ext'] = '7890' 582 request.form['form.actions.apply'] = u'' 583 html = SampleForm(content, request)() 584 585 # We don't have a invalid field value 586 # since we convert the value to unicode 587 self.assert_('Object is of wrong type.' not in html) 588 return 589 590 def test_missing_value(self): 591 content = SampleContent() 592 request = TestRequest() 593 594 request.form['form.foo.country'] = u'123' 595 request.form['form.foo.area'] = u'456' 596 request.form['form.foo.ext'] = u'7890' 597 request.form['form.bar.country'] = u'' 598 request.form['form.bar.area'] = u'' 599 request.form['form.bar.ext'] = u'' 600 request.form['form.baz.country'] = u'' 601 request.form['form.baz.area'] = u'' 602 request.form['form.baz.ext'] = u'' 603 request.form['form.actions.apply'] = u'' 604 SampleForm(content, request)() 605 606 # check new values in object 607 self.assertEqual(content.foo, u'123-456-7890') 608 self.assertEqual(content.bar, u'--') # default missing value 609 self.assertEqual(content.baz, u'--') 610 return
Note: See TracChangeset for help on using the changeset viewer.