Skip to content

Commit cbbe2fb

Browse files
committed
Add array field unit test
1 parent 5d5f225 commit cbbe2fb

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tests/model_fields_/test_arrayfield.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ def test_blank_true(self):
800800
# This should not raise a validation error
801801
field.clean([1, None], None)
802802

803-
def test_with_size(self):
804-
field = ArrayField(models.IntegerField(), size=3)
803+
def test_with_max_size(self):
804+
field = ArrayField(models.IntegerField(), max_size=3)
805805
field.clean([1, 2, 3], None)
806806
with self.assertRaises(exceptions.ValidationError) as cm:
807807
field.clean([1, 2, 3, 4], None)
@@ -810,13 +810,30 @@ def test_with_size(self):
810810
"List contains 4 items, it should contain no more than 3.",
811811
)
812812

813-
def test_with_size_singular(self):
814-
field = ArrayField(models.IntegerField(), size=1)
813+
def test_with_max_size_singular(self):
814+
field = ArrayField(models.IntegerField(), max_size=1)
815815
field.clean([1], None)
816816
msg = "List contains 2 items, it should contain no more than 1."
817817
with self.assertRaisesMessage(exceptions.ValidationError, msg):
818818
field.clean([1, 2], None)
819819

820+
def test_with_size(self):
821+
field = ArrayField(models.IntegerField(), size=3)
822+
field.clean([1, 2, 3], None)
823+
with self.assertRaises(exceptions.ValidationError) as cm:
824+
field.clean([1, 2, 3, 4], None)
825+
self.assertEqual(
826+
cm.exception.messages[0],
827+
"List contains 4 items, it should contain 3.",
828+
)
829+
830+
def test_with_size_singular(self):
831+
field = ArrayField(models.IntegerField(), size=2)
832+
field.clean([1, 2], None)
833+
msg = "List contains 1 item, it should contain 2."
834+
with self.assertRaisesMessage(exceptions.ValidationError, msg):
835+
field.clean([1], None)
836+
820837
def test_nested_array_mismatch(self):
821838
field = ArrayField(ArrayField(models.IntegerField()))
822839
field.clean([[1, 2], [3, 4]], None)

0 commit comments

Comments
 (0)