summaryrefslogtreecommitdiff
path: root/tests/model_fields
diff options
context:
space:
mode:
authorDavid Smith <smithdc@gmail.com>2020-08-05 21:51:14 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-09-25 10:12:01 +0200
commit4b032142faa6f2bdcbef9a99267c51a3e8c9fe66 (patch)
tree84a1e1db9e98a45b944cdc2f89aaa025bd51a00e /tests/model_fields
parente4ab44a4b2ef70be09c35c9197a19fd2e993b4d6 (diff)
downloaddjango-4b032142faa6f2bdcbef9a99267c51a3e8c9fe66.tar.gz
Used assertRaisesMessage() in CharField tests.
Diffstat (limited to 'tests/model_fields')
-rw-r--r--tests/model_fields/test_charfield.py12
1 files 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)