1
+ from django .core .exceptions import ValidationError
1
2
from django .db import IntegrityError
2
3
from django .test import TestCase
3
4
@@ -30,9 +31,22 @@ def test_unique_min_value(self):
30
31
with self .assertRaises (IntegrityError ):
31
32
UniqueIntegers .objects .create (small = self .min_value )
32
33
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
+
33
46
34
47
class PositiveSmallIntegerFieldTests (TestCase ):
35
48
max_value = 2 ** 31 - 1
49
+ min_value = 0
36
50
37
51
def test_unique_max_value (self ):
38
52
"""
@@ -47,3 +61,15 @@ def test_unique_max_value(self):
47
61
48
62
# test_unique_min_value isn't needed since PositiveSmallIntegerField has a
49
63
# 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