diff options
| author | Mads Jensen <mje@inducks.org> | 2017-05-28 21:37:21 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-07-29 19:07:23 -0400 |
| commit | a51c4de1945be2225f20fad794cfb52d8f1f9236 (patch) | |
| tree | 36386b70a27cf027a8a491de319c3e59e0d3d0cd /tests/forms_tests | |
| parent | 38988f289f7f5708f5ea85de2d5dfe0d86b23106 (diff) | |
Used assertRaisesMessage() to test Django's error messages.
Diffstat (limited to 'tests/forms_tests')
| -rw-r--r-- | tests/forms_tests/field_tests/test_uuidfield.py | 3 | ||||
| -rw-r--r-- | tests/forms_tests/tests/test_formsets.py | 3 | ||||
| -rw-r--r-- | tests/forms_tests/tests/tests.py | 6 |
3 files changed, 8 insertions, 4 deletions
diff --git a/tests/forms_tests/field_tests/test_uuidfield.py b/tests/forms_tests/field_tests/test_uuidfield.py index 08498ab9c9..ed08efd659 100644 --- a/tests/forms_tests/field_tests/test_uuidfield.py +++ b/tests/forms_tests/field_tests/test_uuidfield.py @@ -18,9 +18,8 @@ class UUIDFieldTest(SimpleTestCase): def test_uuidfield_3(self): field = UUIDField() - with self.assertRaises(ValidationError) as cm: + with self.assertRaisesMessage(ValidationError, 'Enter a valid UUID.'): field.clean('550e8400') - self.assertEqual(cm.exception.messages[0], 'Enter a valid UUID.') def test_uuidfield_4(self): field = UUIDField() diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index 29f138b2d1..defa46b730 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -1338,7 +1338,8 @@ ArticleFormSet = formset_factory(ArticleForm) class TestIsBoundBehavior(SimpleTestCase): def test_no_data_raises_validation_error(self): - with self.assertRaises(ValidationError): + msg = 'ManagementForm data is missing or has been tampered with' + with self.assertRaisesMessage(ValidationError, msg): ArticleFormSet({}).is_valid() def test_with_management_data_attrs_work_fine(self): diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py index 043b8e0edc..a54ad09c26 100644 --- a/tests/forms_tests/tests/tests.py +++ b/tests/forms_tests/tests/tests.py @@ -247,7 +247,11 @@ class RelatedModelFormTests(SimpleTestCase): model = A fields = '__all__' - with self.assertRaises(ValueError): + msg = ( + "Cannot create form field for 'ref' yet, because " + "its related model 'B' has not been loaded yet" + ) + with self.assertRaisesMessage(ValueError, msg): ModelFormMetaclass('Form', (ModelForm,), {'Meta': Meta}) class B(models.Model): |
