Esempio n. 1
0
def test_integer_field_range_success():
    f = Integer()
    assert f._validate_range((1, 10), 1) == 1
    assert f._validate_range((1, 10), 5) == 5
    assert f._validate_range((1, 10), 10) == 10
Esempio n. 2
0
def test_integer_field_range_fail():
    f = Integer()
    for fail_val in (100, 0, -5):
        with pytest.raises(FieldSet.Error):
            f._validate_range((1, 10), fail_val)
Esempio n. 3
0
def test_integer_field_validate_numberic_str():
    f = Integer()
    assert f._validate_field('10') == 10
Esempio n. 4
0
def test_integer_field_validate_non_acceptable_value():
    f = Integer()
    for fail_val in ('should not work', None, '10.10'):
        with pytest.raises(FieldSet.Error) as e:
            f._validate_field(fail_val)
        assert 'Field "{}" is not a number'.format(f._name) in str(e)
Esempio n. 5
0
def test_integer_field_validate():
    f = Integer()
    assert f._validate_field(1000) == 1000
Esempio n. 6
0
def test_integer_field_validate_decimal():
    f = Integer()
    assert f._validate_field(10.10) == 10
Esempio n. 7
0
def test_integer_field_range_success():
    f = Integer()
    assert f._validate_range((1, 10), 1) == 1
    assert f._validate_range((1, 10), 5) == 5
    assert f._validate_range((1, 10), 10) == 10
Esempio n. 8
0
def test_integer_field_range_fail():
    f = Integer()
    for fail_val in (100, 0, -5):
        with pytest.raises(FieldSet.Error):
            f._validate_range((1, 10), fail_val)
Esempio n. 9
0
def test_integer_field_validate_non_acceptable_value():
    f = Integer()
    for fail_val in ('should not work', None, '10.10'):
        with pytest.raises(FieldSet.Error) as e:
            f._validate_field(fail_val)
        assert 'Field "{}" is not a number'.format(f._name) in str(e)
Esempio n. 10
0
def test_integer_field_validate_numberic_str():
    f = Integer()
    assert f._validate_field('10') == 10
Esempio n. 11
0
def test_integer_field_validate_decimal():
    f = Integer()
    assert f._validate_field(10.10) == 10
Esempio n. 12
0
def test_integer_field_validate():
    f = Integer()
    assert f._validate_field(1000) == 1000
Esempio n. 13
0
def test_integer_field_range_success():
    f = Integer()
    assert f._validate_range(1, (1, 10)) == 1
    assert f._validate_range(5, (1, 10)) == 5
    assert f._validate_range(10, (1, 10)) == 10