Ejemplo n.º 1
0
 def test_datetime_required(self):
     field = pg_forms.DateTimeRangeField(required=True)
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(['', ''])
     self.assertEqual(cm.exception.messages[0], 'This field is required.')
     value = field.clean(['2013-04-09 11:45', ''])
     self.assertEqual(value, DateTimeTZRange(datetime.datetime(2013, 4, 9, 11, 45), None))
Ejemplo n.º 2
0
 def test_datetime_prepare_value(self):
     field = pg_forms.DateTimeRangeField()
     value = field.prepare_value(
         DateTimeTZRange(datetime.datetime(2015, 5, 22, 16, 6, 33, tzinfo=timezone.utc), None)
     )
     self.assertEqual(value, [datetime.datetime(2015, 5, 22, 18, 6, 33), None])
Ejemplo n.º 3
0
 def test_datetime_invalid_upper(self):
     field = pg_forms.DateTimeRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(['2013-04-09 11:45', 'sweet pickles'])
     self.assertEqual(cm.exception.messages[0], 'Enter a valid date/time.')
Ejemplo n.º 4
0
 def test_datetime_incorrect_data_type(self):
     field = pg_forms.DateTimeRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('2013-04-09 11:45')
     self.assertEqual(cm.exception.messages[0], 'Enter two valid date/times.')
     self.assertEqual(cm.exception.code, 'invalid')
Ejemplo n.º 5
0
 def test_datetime_open(self):
     field = pg_forms.DateTimeRangeField()
     value = field.clean(['', '2013-04-09 11:45'])
     self.assertEqual(value, DateTimeTZRange(None, datetime.datetime(2013, 4, 9, 11, 45)))
Ejemplo n.º 6
0
 def test_datetime_lower_bound_higher(self):
     field = pg_forms.DateTimeRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(['2006-10-25 14:59', '2006-10-25 14:58'])
     self.assertEqual(cm.exception.messages[0], 'The start of the range must not exceed the end of the range.')
     self.assertEqual(cm.exception.code, 'bound_ordering')
Ejemplo n.º 7
0
 def test_valid_timestamps(self):
     field = pg_forms.DateTimeRangeField()
     value = field.clean(['01/01/2014 00:00:00', '02/02/2014 12:12:12'])
     lower = datetime.datetime(2014, 1, 1, 0, 0, 0)
     upper = datetime.datetime(2014, 2, 2, 12, 12, 12)
     self.assertEqual(value, DateTimeTZRange(lower, upper))