def test_to_representation_parse_time_into_iso8601_string(self): instance = fields.TimeField() self.assertEqual(instance.to_representation(datetime.time(10, 0)), '10:00:00')
def test_to_representation_raise_assertion_error(self): instance = fields.TimeField(format=settings.ISO_8601) with self.assertRaises(AssertionError): instance.to_representation(datetime.datetime(2000, 1, 1, 10, 00))
def test_to_representation_returns_none(self): instance = fields.TimeField() self.assertIsNone(instance.to_representation(None))
def test_to_representation_return_value(self): instance = fields.TimeField(format=None) timestamp = datetime.time(13, 0) self.assertEqual(instance.to_representation(timestamp), timestamp)
def test_to_representation(self): instance = fields.TimeField(format='%H:%M:%S') timestamp = datetime.time(3, 0) self.assertEqual(instance.to_representation(timestamp), '03:00:00')
def test_to_representation_returns_none_for_empty_string(self): instance = fields.TimeField() self.assertIsNone(instance.to_representation(''))
def test_to_internal_value_raises_error_for_none_value_and_format(self): instance = fields.TimeField(input_formats=('%H:%M', )) with self.assertRaises(ValidationError): instance.to_internal_value(None)
def test_to_internal_value_raises_validation_error_for_wrong_value(self): instance = fields.TimeField() with self.assertRaises(ValidationError): instance.to_internal_value('99:99')
def test_to_internal_value_raises_validation_error_with_empty_format(self): instance = fields.TimeField(input_formats=()) with self.assertRaises(ValidationError): instance.to_internal_value('99:99')
def test_to_internal_value_for_non_iso8601(self): instance = fields.TimeField(input_formats=('%H:%M', )) self.assertEqual(instance.to_internal_value('10:00'), datetime.time(10, 0))
def test_to_internal_value_time(self): instance = fields.TimeField() self.assertEqual(instance.to_internal_value(datetime.time(3, 0)), datetime.time(3, 0))
def test_to_internal_value_string(self): instance = fields.TimeField() self.assertEqual(instance.to_internal_value('03:00'), datetime.time(3, 0))
def test_run_validation_raise_validation_error(self): instance = fields.TimeField() with self.assertRaises(ValidationError): instance.run_validation('value')