Exemplo n.º 1
0
def test_validate_empty_with_default():
    field = BooleanField('name', default=True)
    assert field.validate({}) is True
    assert field.validate('') is True
Exemplo n.º 2
0
def test_validate_none_with_default():
    field = BooleanField('name', default=True)
    assert field.validate(None) is True
    field = BooleanField('name', default=False)
    assert field.validate(None) is None
Exemplo n.º 3
0
def test_validation_none_not_required():
    field = BooleanField('name', required=False)
    assert field.validate(None) is None
Exemplo n.º 4
0
def test_validate_none_required():
    field = BooleanField('name', required=True)
    with pytest.raises(ValidationError):
        field.validate(None)
Exemplo n.º 5
0
 def test_required_with_false(self):
     field = BooleanField('', required=True)
     with self.assertRaises(ValidationError) as cm:
         field.validate(False)
     self.assertEqual(cm.exception.code, 'required')
Exemplo n.º 6
0
 def test_required_with_true(self):
     field = BooleanField('', required=True)
     try:
         field.validate(True)
     except ValidationError:
         self.fail('Unexpected ValidationError')