Beispiel #1
0
    def integer_marshalling(self, fixture):
        field = IntegerField()
        obj = EmptyStub()
        field.bind('integer_value', obj)

        # From input
        field.from_input('5')
        vassert( obj.integer_value is 5 )

        # As input
        obj.integer_value = 6
        vassert( field.as_input() == '6' )

        # As input - corner case
        obj.integer_value = 0
        vassert( field.as_input() == '0' )
Beispiel #2
0
def test_integer_marshalling(fixture):

    field = IntegerField()
    obj = EmptyStub()
    field.bind('integer_value', obj)

    # From input
    field.from_input('5')
    assert obj.integer_value is 5

    # As input
    obj.integer_value = 6
    assert field.as_input() == '6'

    # As input - corner case
    obj.integer_value = 0
    assert field.as_input() == '0'
Beispiel #3
0
def test_checkbox_input_restricted_to_use_with_boolean(web_fixture):
    """CheckboxInput is for toggling a true or false answer."""
    model_object = web_fixture
    form = Form(web_fixture.view, 'test')

    # case: with BooleanField
    boolean_field = BooleanField(label='Boolean')
    boolean_field.bind('a_choice', model_object)
    with expected(NoException):
        CheckboxInput(form, boolean_field)

    # case: with disallowed field
    not_a_boolean_field = IntegerField(label='Other')
    not_a_boolean_field.bind('not_a_boolean', model_object)

    with expected(IsInstance):
        CheckboxInput(form, not_a_boolean_field)