1+ from django .core .exceptions import ValidationError
12from django .db import IntegrityError
23from django .test import TestCase
34
@@ -30,9 +31,22 @@ def test_unique_min_value(self):
3031 with self .assertRaises (IntegrityError ):
3132 UniqueIntegers .objects .create (small = self .min_value )
3233
34+ def test_validate_max_value (self ):
35+ UniqueIntegers (small = self .max_value ).full_clean () # no error
36+ msg = "{'small': ['Ensure this value is less than or equal to 2147483647.']"
37+ with self .assertRaisesMessage (ValidationError , msg ):
38+ UniqueIntegers (small = self .max_value + 1 ).full_clean ()
39+
40+ def test_validate_min_value (self ):
41+ UniqueIntegers (small = self .min_value ).full_clean () # no error
42+ msg = "{'small': ['Ensure this value is greater than or equal to -2147483648.']"
43+ with self .assertRaisesMessage (ValidationError , msg ):
44+ UniqueIntegers (small = self .min_value - 1 ).full_clean ()
45+
3346
3447class PositiveSmallIntegerFieldTests (TestCase ):
3548 max_value = 2 ** 31 - 1
49+ min_value = 0
3650
3751 def test_unique_max_value (self ):
3852 """
@@ -47,3 +61,15 @@ def test_unique_max_value(self):
4761
4862 # test_unique_min_value isn't needed since PositiveSmallIntegerField has a
4963 # limit of zero (enforced only in forms and model validation).
64+
65+ def test_validate_max_value (self ):
66+ UniqueIntegers (positive_small = self .max_value ).full_clean () # no error
67+ msg = "{'positive_small': ['Ensure this value is less than or equal to 2147483647.']"
68+ with self .assertRaisesMessage (ValidationError , msg ):
69+ UniqueIntegers (positive_small = self .max_value + 1 ).full_clean ()
70+
71+ def test_validate_min_value (self ):
72+ UniqueIntegers (positive_small = self .min_value ).full_clean () # no error
73+ msg = "{'positive_small': ['Ensure this value is greater than or equal to 0.']"
74+ with self .assertRaisesMessage (ValidationError , msg ):
75+ UniqueIntegers (positive_small = self .min_value - 1 ).full_clean ()
0 commit comments