コード例 #1
0
 def test_decimal_required(self):
     field = pg_forms.DecimalRangeField(required=True)
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(['', ''])
     self.assertEqual(cm.exception.messages[0], 'This field is required.')
     value = field.clean(['1.61803399', ''])
     self.assertEqual(value, NumericRange(Decimal('1.61803399'), None))
コード例 #2
0
 def test_decimal_lower_bound_higher(self):
     field = pg_forms.DecimalRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(['1.8', '1.6'])
     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
ファイル: test_ranges.py プロジェクト: zhengyy58/django
 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_decimal_invalid_upper(self):
     field = pg_forms.DecimalRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(['1.61803399', 'b'])
     self.assertEqual(cm.exception.messages[0], 'Enter a number.')
コード例 #6
0
 def test_decimal_incorrect_data_type(self):
     field = pg_forms.DecimalRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('1.6')
     self.assertEqual(cm.exception.messages[0], 'Enter two numbers.')
     self.assertEqual(cm.exception.code, 'invalid')
コード例 #7
0
 def test_decimal_open(self):
     field = pg_forms.DecimalRangeField()
     value = field.clean(['', '3.1415926'])
     self.assertEqual(value, NumericRange(None, Decimal('3.1415926')))
コード例 #8
0
 def test_valid_decimal(self):
     field = pg_forms.DecimalRangeField()
     value = field.clean(['1.12345', '2.001'])
     self.assertEqual(value,
                      NumericRange(Decimal('1.12345'), Decimal('2.001')))
コード例 #9
0
 def test_decimal_invalid_lower(self):
     field = pg_forms.DecimalRangeField()
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean(["a", "3.1415926"])
     self.assertEqual(cm.exception.messages[0], "Enter a number.")
コード例 #10
0
 def test_valid_decimal(self):
     field = pg_forms.DecimalRangeField()
     value = field.clean(["1.12345", "2.001"])
     self.assertEqual(value,
                      NumericRange(Decimal("1.12345"), Decimal("2.001")))