Ignore:
Timestamp:
20 Dec 2011, 12:34:26 (13 years ago)
Author:
uli
Message:

Add regression test for phonewidget not requiring input.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/widgets/tests/test_phonewidget.py

    r7354 r7410  
    4949        required = True)
    5050
     51    bar = schema.TextLine(
     52        title = u'Phone',
     53        description = u'Phone number (not required)',
     54        required = False)
     55
    5156class SampleContent:
    5257    implements(ISampleContent)
     
    7176        self.field = ISampleContent['foo']
    7277        self.field = self.field.bind(self.content)
     78        self.field_nonreq = ISampleContent['bar']
     79        self.field_nonreq = self.field_nonreq.bind(self.content)
    7380
    7481        # create an empty request. We need one to create a widget
    7582        self.request = TestRequest()
    7683        self.widget = PhoneWidget(self.field, self.request)
     84        self.widget_nonreq = PhoneWidget(self.field_nonreq, self.request)
    7785        return
    7886
     
    96104        self.assertEqual(self.widget.visible, True)
    97105        self.assertEqual(self.widget.required, True)
     106        self.assertEqual(self.widget_nonreq.required, False)
    98107        return
    99108
     
    422431        self.assertTrue('value="3333"' in widget())
    423432        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.