示例#1
0
def test_multiple_valid_values():
    field = IntegerField('name', multiple=True)
    assert field.validate([1, 2, 4, 8]) == [1, 2, 4, 8]
    assert field.validate(['1', 4, '6']) == [1, 4, 6]
示例#2
0
def test_validate_none_required():
    field = IntegerField('name', required=True)
    with pytest.raises(ValidationError):
        field.validate(None)
示例#3
0
def test_validate_less_than_max():
    field = IntegerField('name', max=7)
    assert field.validate(6) == 6
示例#4
0
def test_validate_more_than_min():
    field = IntegerField('name', min=7)
    assert field.validate(8) == 8
示例#5
0
def default_field():
    return IntegerField('name')
示例#6
0
def test_validate_equal_to_max():
    field = IntegerField('name', max=7)
    assert field.validate(7) == 7
示例#7
0
def test_validate_less_than_min():
    field = IntegerField('name', min=7)
    with pytest.raises(ValidationError):
        field.validate(6)
示例#8
0
def test_validate_more_than_max():
    field = IntegerField('name', max=7)
    with pytest.raises(ValidationError):
        field.validate(8)
示例#9
0
def test_validate_invalid_value_with_default():
    field = IntegerField('name', default=4, max=8)
    with pytest.raises(ValidationError):
        field.validate(10)
示例#10
0
 def test_required(self):
     field = IntegerField('', required=True)
     with self.assertRaises(ValidationError) as cm:
         field.validate(None)
     self.assertEqual(cm.exception.code, 'required')
示例#11
0
def test_validate_empty_with_default():
    field = IntegerField('name,', default=3)
    assert field.validate('') == 3
    assert field.validate(()) == 3
示例#12
0
def test_validate_valid_value_with_default():
    field = IntegerField('name', default=4, max=8)
    assert field.validate(1) == 1
    assert field.validate(0) == 0
示例#13
0
def test_validate_none_with_default():
    field = IntegerField('name', default=5)
    assert field.validate(None) == 5
    field = IntegerField('name', default=0)
    assert field.validate(None) == 0
示例#14
0
def test_validate_none_not_required():
    field = IntegerField('name', required=False)
    assert field.validate(None) is None
示例#15
0
def test_validate_equal_to_min():
    field = IntegerField('name', min=7)
    assert field.validate(7)
示例#16
0
def test_multiple_invalid_value():
    field = IntegerField('name', multiple=True)
    with pytest.raises(ValidationError):
        field.validate([4, 5, 'a'])
示例#17
-1
 def test_cleaned_data(self):
     field = IntegerField('', default=4)
     self.assertEqual(field.cleaned_value, 4)
     field.value = "True"
     with self.assertRaises(ValidationError):
         # noinspection PyStatementEffect
         field.cleaned_value
     field.value = '10'
     self.assertEqual(field.cleaned_value, 10)
示例#18
-1
 def test_is_valid_int(self):
     field = IntegerField('')
     field.value = 10
     self.assertTrue(field.is_valid)
     field.value = "10"
     self.assertTrue(field.is_valid)
     field.value = "3.5"
     self.assertFalse(field.is_valid)
     field.value = "-4"
     self.assertTrue(field.is_valid)
示例#19
-1
 def test_is_valid_min(self):
     field = IntegerField('', minimum=-10)
     field.value = -10
     self.assertTrue(field.is_valid)
     field.value = -11
     self.assertFalse(field.is_valid)
示例#20
-1
 def test_is_valid_max(self):
     field = IntegerField('', maximum=20)
     field.value = 20
     self.assertTrue(field.is_valid)
     field.value = 21
     self.assertFalse(field.is_valid)