summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_array.py
diff options
context:
space:
mode:
authorSkyiesac <jainsachi1202@gmail.com>2025-11-17 00:46:37 +0530
committerJacob Walls <jacobtylerwalls@gmail.com>2025-12-03 09:18:10 -0500
commitd338c2243fa0786225e056c5d7003f7ad67d44de (patch)
tree9e1af2794830ffc04f8936027fb7e1ce747dd9c0 /tests/postgres_tests/test_array.py
parentdba622ebc1f6a6700b75303a65f8a334bd46bd8e (diff)
Fixed #36280 -- Replaced exception checks with assertRaisesMessage().
Diffstat (limited to 'tests/postgres_tests/test_array.py')
-rw-r--r--tests/postgres_tests/test_array.py46
1 files changed, 14 insertions, 32 deletions
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index d4289d79df..eea9935804 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -1087,12 +1087,9 @@ class TestValidation(PostgreSQLSimpleTestCase):
def test_with_size(self):
field = ArrayField(models.IntegerField(), size=3)
field.clean([1, 2, 3], None)
- with self.assertRaises(exceptions.ValidationError) as cm:
+ msg = "List contains 4 items, it should contain no more than 3."
+ with self.assertRaisesMessage(exceptions.ValidationError, msg):
field.clean([1, 2, 3, 4], None)
- self.assertEqual(
- cm.exception.messages[0],
- "List contains 4 items, it should contain no more than 3.",
- )
def test_with_size_singular(self):
field = ArrayField(models.IntegerField(), size=1)
@@ -1156,21 +1153,15 @@ class TestSimpleFormField(PostgreSQLSimpleTestCase):
def test_to_python_fail(self):
field = SimpleArrayField(forms.IntegerField())
- with self.assertRaises(exceptions.ValidationError) as cm:
+ msg = "Item 1 in the array did not validate: Enter a whole number."
+ with self.assertRaisesMessage(exceptions.ValidationError, msg):
field.clean("a,b,9")
- self.assertEqual(
- cm.exception.messages[0],
- "Item 1 in the array did not validate: Enter a whole number.",
- )
def test_validate_fail(self):
field = SimpleArrayField(forms.CharField(required=True))
- with self.assertRaises(exceptions.ValidationError) as cm:
+ msg = "Item 3 in the array did not validate: This field is required."
+ with self.assertRaisesMessage(exceptions.ValidationError, msg):
field.clean("a,b,")
- self.assertEqual(
- cm.exception.messages[0],
- "Item 3 in the array did not validate: This field is required.",
- )
def test_validate_fail_base_field_error_params(self):
field = SimpleArrayField(forms.CharField(max_length=2))
@@ -1203,12 +1194,9 @@ class TestSimpleFormField(PostgreSQLSimpleTestCase):
def test_validators_fail(self):
field = SimpleArrayField(forms.RegexField("[a-e]{2}"))
- with self.assertRaises(exceptions.ValidationError) as cm:
+ msg = "Item 1 in the array did not validate: Enter a valid value."
+ with self.assertRaisesMessage(exceptions.ValidationError, msg):
field.clean("a,bc,de")
- self.assertEqual(
- cm.exception.messages[0],
- "Item 1 in the array did not validate: Enter a valid value.",
- )
def test_delimiter(self):
field = SimpleArrayField(forms.CharField(), delimiter="|")
@@ -1227,21 +1215,15 @@ class TestSimpleFormField(PostgreSQLSimpleTestCase):
def test_max_length(self):
field = SimpleArrayField(forms.CharField(), max_length=2)
- with self.assertRaises(exceptions.ValidationError) as cm:
+ msg = "List contains 3 items, it should contain no more than 2."
+ with self.assertRaisesMessage(exceptions.ValidationError, msg):
field.clean("a,b,c")
- self.assertEqual(
- cm.exception.messages[0],
- "List contains 3 items, it should contain no more than 2.",
- )
def test_min_length(self):
field = SimpleArrayField(forms.CharField(), min_length=4)
- with self.assertRaises(exceptions.ValidationError) as cm:
+ msg = "List contains 3 items, it should contain no fewer than 4."
+ with self.assertRaisesMessage(exceptions.ValidationError, msg):
field.clean("a,b,c")
- self.assertEqual(
- cm.exception.messages[0],
- "List contains 3 items, it should contain no fewer than 4.",
- )
def test_min_length_singular(self):
field = SimpleArrayField(forms.IntegerField(), min_length=2)
@@ -1252,9 +1234,9 @@ class TestSimpleFormField(PostgreSQLSimpleTestCase):
def test_required(self):
field = SimpleArrayField(forms.CharField(), required=True)
- with self.assertRaises(exceptions.ValidationError) as cm:
+ msg = "This field is required."
+ with self.assertRaisesMessage(exceptions.ValidationError, msg):
field.clean("")
- self.assertEqual(cm.exception.messages[0], "This field is required.")
def test_model_field_formfield(self):
model_field = ArrayField(models.CharField(max_length=27))