Skip to content

Commit 521e1de

Browse files
committed
Handle exception message in the CM.
1 parent 3ea89ea commit 521e1de

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

tests/model_fields_/test_arrayfield.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,9 @@ def test_blank_true(self):
803803
def test_with_max_size(self):
804804
field = ArrayField(models.IntegerField(), max_size=3)
805805
field.clean([1, 2, 3], None)
806-
with self.assertRaises(exceptions.ValidationError) as cm:
806+
msg = "List contains 4 items, it should contain no more than 3."
807+
with self.assertRaisesMessage(exceptions.ValidationError, msg):
807808
field.clean([1, 2, 3, 4], None)
808-
self.assertEqual(
809-
cm.exception.messages[0],
810-
"List contains 4 items, it should contain no more than 3.",
811-
)
812809

813810
def test_with_max_size_singular(self):
814811
field = ArrayField(models.IntegerField(), max_size=1)
@@ -820,12 +817,9 @@ def test_with_max_size_singular(self):
820817
def test_with_size(self):
821818
field = ArrayField(models.IntegerField(), size=3)
822819
field.clean([1, 2, 3], None)
823-
with self.assertRaises(exceptions.ValidationError) as cm:
820+
msg = "List contains 4 items, it should contain 3."
821+
with self.assertRaisesMessage(exceptions.ValidationError, msg):
824822
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-
)
829823

830824
def test_with_size_singular(self):
831825
field = ArrayField(models.IntegerField(), size=2)

0 commit comments

Comments
 (0)