def test_required(self): f = DateUnitField(required=False) self.assertEqual(None, f.clean(None)) f = DateUnitField() with self.assertRaises(ValidationError): f.clean(None)
def test_empty_value_validators(self): # By default django skips run_validators methods, if value is in empty_values # It's not correct for REST, as empty value is not equal to None value now f = DateUnitField(validators=[TestErrorValidator(0)]) with self.assertRaises(ValidationError): f.clean('day')
def test_initial(self): f = DateUnitField(required=False, initial='day') self.assertEqual('day', f.clean(None))
def test_invalid(self): f = DateUnitField() with self.assertRaises(ValidationError): f.clean('something')
def test_week(self): f = DateUnitField() self.assertEqual('week', f.clean('week'))
def test_hour(self): f = DateUnitField() self.assertEqual('hour', f.clean('hour'))
def test_day(self): f = DateUnitField() self.assertEqual('day', f.clean('day'))