Exemplo n.º 1
0
 def test_durationfield_clean(self):
     f = DurationField()
     self.assertEqual(datetime.timedelta(seconds=30), f.clean('30'))
     self.assertEqual(datetime.timedelta(minutes=15, seconds=30), f.clean('15:30'))
     self.assertEqual(datetime.timedelta(hours=1, minutes=15, seconds=30), f.clean('1:15:30'))
     self.assertEqual(
         datetime.timedelta(days=1, hours=1, minutes=15, seconds=30, milliseconds=300),
         f.clean('1 1:15:30.3')
     )
 def test_durationfield_clean(self):
     f = DurationField()
     self.assertEqual(datetime.timedelta(seconds=30), f.clean('30'))
     self.assertEqual(datetime.timedelta(minutes=15, seconds=30), f.clean('15:30'))
     self.assertEqual(datetime.timedelta(hours=1, minutes=15, seconds=30), f.clean('1:15:30'))
     self.assertEqual(
         datetime.timedelta(days=1, hours=1, minutes=15, seconds=30, milliseconds=300),
         f.clean('1 1:15:30.3')
     )
 def test_overflow(self):
     msg = "The number of days must be between {min_days} and {max_days}.".format(
         min_days=datetime.timedelta.min.days,
         max_days=datetime.timedelta.max.days,
     )
     f = DurationField()
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean('1000000000 00:00:00')
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean('-1000000000 00:00:00')
Exemplo n.º 4
0
 def test_overflow(self):
     msg = "The number of days must be between {min_days} and {max_days}.".format(
         min_days=datetime.timedelta.min.days,
         max_days=datetime.timedelta.max.days,
     )
     f = DurationField()
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean('1000000000 00:00:00')
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean('-1000000000 00:00:00')
Exemplo n.º 5
0
 def test_durationfield_clean(self):
     f = DurationField()
     self.assertEqual(datetime.timedelta(seconds=30), f.clean("30"))
     self.assertEqual(datetime.timedelta(minutes=15, seconds=30),
                      f.clean("15:30"))
     self.assertEqual(datetime.timedelta(hours=1, minutes=15, seconds=30),
                      f.clean("1:15:30"))
     self.assertEqual(
         datetime.timedelta(days=1,
                            hours=1,
                            minutes=15,
                            seconds=30,
                            milliseconds=300),
         f.clean("1 1:15:30.3"),
     )
     self.assertEqual(
         datetime.timedelta(0, 10800),
         f.clean(datetime.timedelta(0, 10800)),
     )
     msg = "This field is required."
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean("")
     msg = "Enter a valid duration."
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean("not_a_time")
     with self.assertRaisesMessage(ValidationError, msg):
         DurationField().clean("P3(3D")
Exemplo n.º 6
0
 def test_durationfield_clean(self):
     f = DurationField()
     self.assertEqual(datetime.timedelta(seconds=30), f.clean('30'))
     self.assertEqual(datetime.timedelta(minutes=15, seconds=30),
                      f.clean('15:30'))
     self.assertEqual(datetime.timedelta(hours=1, minutes=15, seconds=30),
                      f.clean('1:15:30'))
     self.assertEqual(
         datetime.timedelta(days=1,
                            hours=1,
                            minutes=15,
                            seconds=30,
                            milliseconds=300), f.clean('1 1:15:30.3'))
     self.assertEqual(
         datetime.timedelta(0, 10800),
         f.clean(datetime.timedelta(0, 10800)),
     )
     msg = 'This field is required.'
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean('')
     msg = 'Enter a valid duration.'
     with self.assertRaisesMessage(ValidationError, msg):
         f.clean('not_a_time')
     with self.assertRaisesMessage(ValidationError, msg):
         DurationField().clean('P3(3D')
 def test_durationfield_integer_value(self):
     f = DurationField()
     self.assertEqual(datetime.timedelta(0, 10800), f.clean(10800))
Exemplo n.º 8
0
 def test_durationfield_integer_value(self):
     f = DurationField()
     self.assertEqual(datetime.timedelta(0, 10800), f.clean(10800))
Exemplo n.º 9
0
 def test_durationfield_clean_not_required(self):
     f = DurationField(required=False)
     self.assertIsNone(f.clean(''))