From 4b032142faa6f2bdcbef9a99267c51a3e8c9fe66 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 5 Aug 2020 21:51:14 +0100 Subject: [PATCH] Used assertRaisesMessage() in CharField tests. --- tests/model_fields/test_charfield.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/model_fields/test_charfield.py b/tests/model_fields/test_charfield.py index a8ac895a11..0e6109c860 100644 --- a/tests/model_fields/test_charfield.py +++ b/tests/model_fields/test_charfield.py @@ -61,7 +61,8 @@ class ValidationTests(SimpleTestCase): def test_charfield_raises_error_on_empty_string(self): f = models.CharField() - with self.assertRaises(ValidationError): + msg = 'This field cannot be blank.' + with self.assertRaisesMessage(ValidationError, msg): f.clean('', None) def test_charfield_cleans_empty_string_when_blank_true(self): @@ -74,7 +75,8 @@ class ValidationTests(SimpleTestCase): def test_charfield_with_choices_raises_error_on_invalid_choice(self): f = models.CharField(choices=[('a', 'A'), ('b', 'B')]) - with self.assertRaises(ValidationError): + msg = "Value 'not a' is not a valid choice." + with self.assertRaisesMessage(ValidationError, msg): f.clean('not a', None) def test_enum_choices_cleans_valid_string(self): @@ -83,10 +85,12 @@ class ValidationTests(SimpleTestCase): def test_enum_choices_invalid_input(self): f = models.CharField(choices=self.Choices.choices, max_length=1) - with self.assertRaises(ValidationError): + msg = "Value 'a' is not a valid choice." + with self.assertRaisesMessage(ValidationError, msg): f.clean('a', None) def test_charfield_raises_error_on_empty_input(self): f = models.CharField(null=False) - with self.assertRaises(ValidationError): + msg = 'This field cannot be null.' + with self.assertRaisesMessage(ValidationError, msg): f.clean(None, None)