예제 #1
0
 def test_cleaned_data_false(self):
     field = BooleanField('', required=False)
     for value in [0, False, 'no', 'false', 'FALSE', 'False', '0', 'null']:
         field.value = value
         self.assertIsNone(
             field.cleaned_value,
             "invalid value for %r" % (value,)
         )
예제 #2
0
 def test_cleaned_data_true(self):
     field = BooleanField('', required=False)
     for value in [1, True, 'yes', 'true', 'TRUE', 'True', 'LOL', '1',
                   object(), type('', (), {})]:
         field.value = value
         self.assertTrue(
             field.cleaned_value,
             "invalid value for %s" % value
         )
예제 #3
0
 def test_is_valid(self):
     field = BooleanField('', required=False)
     field.value = True
     self.assertTrue(field.is_valid)
     field.value = "yes"
     self.assertTrue(field.is_valid)
     field.value = 0
     self.assertTrue(field.is_valid)
     field.value = False
     self.assertTrue(field.is_valid)
예제 #4
0
def test_validate_empty_with_default():
    field = BooleanField('name', default=True)
    assert field.validate({}) is True
    assert field.validate('') is True
예제 #5
0
def default_field():
    return BooleanField('name')
예제 #6
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
예제 #7
0
def test_validation_none_not_required():
    field = BooleanField('name', required=False)
    assert field.validate(None) is None
예제 #8
0
def test_validate_none_required():
    field = BooleanField('name', required=True)
    with pytest.raises(ValidationError):
        field.validate(None)
예제 #9
0
 def test_required_false_default(self):
     with self.assertRaises(RuntimeError):
         # value cannot be required and false
         BooleanField('', required=True, default=False)
예제 #10
0
 def test_required_default_true(self):
     field = BooleanField('', required=True, default=True)
     self.assertTrue(field.is_valid)
예제 #11
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')
예제 #12
0
 def test_required_with_true(self):
     field = BooleanField('', required=True)
     try:
         field.validate(True)
     except ValidationError:
         self.fail('Unexpected ValidationError')
예제 #13
0
 def test_cleaned_data_none(self):
     field = BooleanField('', required=False)
     field.value = None
     self.assertIsNone(field.cleaned_value)