@@ -73,3 +73,62 @@ def test_validate_min_value(self):
7373 msg = "{'positive_small': ['Ensure this value is greater than or equal to 0.']"
7474 with self .assertRaisesMessage (ValidationError , msg ):
7575 Integers (positive_small = self .min_value - 1 ).full_clean ()
76+
77+
78+ class SmallUniqueTests (TestCase ):
79+ """
80+ Duplicate values < 32 bits are prohibited. This confirms integer field
81+ values are cast to Int64 so MongoDB stores it as long. Otherwise, the
82+ partialFilterExpression: {$type: long} unique constraint doesn't work.
83+ """
84+
85+ test_value = 123
86+
87+ def test_integerfield (self ):
88+ Integers .objects .create (normal = self .test_value )
89+ with self .assertRaises (IntegrityError ):
90+ Integers .objects .create (normal = self .test_value )
91+
92+ def test_bigintegerfield (self ):
93+ Integers .objects .create (big = self .test_value )
94+ with self .assertRaises (IntegrityError ):
95+ Integers .objects .create (big = self .test_value )
96+
97+ def test_positiveintegerfield (self ):
98+ Integers .objects .create (positive = self .test_value )
99+ with self .assertRaises (IntegrityError ):
100+ Integers .objects .create (positive = self .test_value )
101+
102+ def test_positivebigintegerfield (self ):
103+ Integers .objects .create (positive_big = self .test_value )
104+ with self .assertRaises (IntegrityError ):
105+ Integers .objects .create (positive_big = self .test_value )
106+
107+
108+ class LargeUniqueTests (TestCase ):
109+ """
110+ Duplicate values > 32 bits are prohibited. This confirms each field uses
111+ the long db_type() rather than the 32 bit int type.
112+ """
113+
114+ test_value = 2 ** 63 - 1
115+
116+ def test_integerfield (self ):
117+ Integers .objects .create (normal = self .test_value )
118+ with self .assertRaises (IntegrityError ):
119+ Integers .objects .create (normal = self .test_value )
120+
121+ def test_bigintegerfield (self ):
122+ Integers .objects .create (big = self .test_value )
123+ with self .assertRaises (IntegrityError ):
124+ Integers .objects .create (big = self .test_value )
125+
126+ def test_positiveintegerfield (self ):
127+ Integers .objects .create (positive = self .test_value )
128+ with self .assertRaises (IntegrityError ):
129+ Integers .objects .create (positive = self .test_value )
130+
131+ def test_positivebigintegerfield (self ):
132+ Integers .objects .create (positive_big = self .test_value )
133+ with self .assertRaises (IntegrityError ):
134+ Integers .objects .create (positive_big = self .test_value )
0 commit comments