Пример #1
0
 def test_date_required(self):
     field = pg_forms.DateRangeField(required=True)
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(['', ''])
     self.assertEqual(cm.exception.messages[0], 'This field is required.')
     value = field.clean(['1976-04-16', ''])
     self.assertEqual(value, DateRange(datetime.date(1976, 4, 16), None))
Пример #2
0
 def test_date_lower_bound_higher(self):
     field = pg_forms.DateRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(['2013-04-09', '1976-04-16'])
     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')
Пример #3
0
 def test_has_changed(self):
     for field, value in (
         (pg_forms.DateRangeField(), ['2010-01-01', '2020-12-12']),
         (pg_forms.DateTimeRangeField(), ['2010-01-01 11:13', '2020-12-12 14:52']),
         (pg_forms.IntegerRangeField(), [1, 2]),
         (pg_forms.DecimalRangeField(), ['1.12345', '2.001']),
     ):
         with self.subTest(field=field.__class__.__name__):
             self.assertTrue(field.has_changed(None, value))
             self.assertTrue(field.has_changed([value[0], ''], value))
             self.assertTrue(field.has_changed(['', value[1]], value))
             self.assertFalse(field.has_changed(value, value))
Пример #4
0
 def test_has_changed(self):
     for field, value in (
         (pg_forms.DateRangeField(), ["2010-01-01", "2020-12-12"]),
         (pg_forms.DateTimeRangeField(),
          ["2010-01-01 11:13", "2020-12-12 14:52"]),
         (pg_forms.IntegerRangeField(), [1, 2]),
         (pg_forms.DecimalRangeField(), ["1.12345", "2.001"]),
     ):
         with self.subTest(field=field.__class__.__name__):
             self.assertTrue(field.has_changed(None, value))
             self.assertTrue(field.has_changed([value[0], ""], value))
             self.assertTrue(field.has_changed(["", value[1]], value))
             self.assertFalse(field.has_changed(value, value))
Пример #5
0
 def test_date_invalid_upper(self):
     field = pg_forms.DateRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(['2013-04-09', 'b'])
     self.assertEqual(cm.exception.messages[0], 'Enter a valid date.')
Пример #6
0
 def test_date_incorrect_data_type(self):
     field = pg_forms.DateRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('1')
     self.assertEqual(cm.exception.messages[0], 'Enter two valid dates.')
     self.assertEqual(cm.exception.code, 'invalid')
Пример #7
0
 def test_date_open(self):
     field = pg_forms.DateRangeField()
     value = field.clean(['', '2013-04-09'])
     self.assertEqual(value, DateRange(None, datetime.date(2013, 4, 9)))
Пример #8
0
 def test_valid_dates(self):
     field = pg_forms.DateRangeField()
     value = field.clean(['01/01/2014', '02/02/2014'])
     lower = datetime.date(2014, 1, 1)
     upper = datetime.date(2014, 2, 2)
     self.assertEqual(value, DateRange(lower, upper))
Пример #9
0
 def test_date_has_changed_last(self):
     self.assertTrue(pg_forms.DateRangeField().has_changed(
         ['2010-01-01', '2020-12-12'],
         ['2010-01-01', '2020-12-31'],
     ))
Пример #10
0
 def test_date_has_changed_last(self):
     self.assertTrue(pg_forms.DateRangeField().has_changed(
         ["2010-01-01", "2020-12-12"],
         ["2010-01-01", "2020-12-31"],
     ))
Пример #11
0
 def test_date_invalid_lower(self):
     field = pg_forms.DateRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(["a", "2013-04-09"])
     self.assertEqual(cm.exception.messages[0], "Enter a valid date.")