diff options
| author | Jannis Leidel <jannis@leidel.info> | 2012-02-04 16:06:09 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2012-02-04 16:06:09 +0000 |
| commit | 2b0c1ea64155bd3f825b06e266d73c00dbf4196f (patch) | |
| tree | 5d9be580e033480f0f3200077282c8fdf6507914 /tests | |
| parent | 56d787df99a923cf96d02f9cd07ca8d383dbc028 (diff) | |
Fixed #17527 -- Improved exception message when adding the wrong type of object to a ManyToManyField. Thanks, guettli and cClaude Paroz.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17437 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/many_to_many/tests.py | 5 | ||||
| -rw-r--r-- | tests/modeltests/many_to_one/tests.py | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/tests/modeltests/many_to_many/tests.py b/tests/modeltests/many_to_many/tests.py index b00d7da140..9fa524f993 100644 --- a/tests/modeltests/many_to_many/tests.py +++ b/tests/modeltests/many_to_many/tests.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import +from __future__ import absolute_import, with_statement from django.test import TestCase @@ -52,7 +52,8 @@ class ManyToManyTests(TestCase): ]) # Adding an object of the wrong type raises TypeError - self.assertRaises(TypeError, a6.publications.add, a5) + with self.assertRaisesRegexp(TypeError, "'Publication' instance expected, got <Article.*"): + a6.publications.add(a5) # Add a Publication directly via publications.add by using keyword arguments. p4 = a6.publications.create(title='Highlights for Adults') self.assertQuerysetEqual(a6.publications.all(), diff --git a/tests/modeltests/many_to_one/tests.py b/tests/modeltests/many_to_one/tests.py index 922506eac0..bc9fe64be4 100644 --- a/tests/modeltests/many_to_one/tests.py +++ b/tests/modeltests/many_to_one/tests.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import +from __future__ import absolute_import, with_statement from copy import deepcopy from datetime import datetime @@ -68,7 +68,8 @@ class ManyToOneTests(TestCase): self.assertQuerysetEqual(self.r2.article_set.all(), ["<Article: Paul's story>"]) # Adding an object of the wrong type raises TypeError. - self.assertRaises(TypeError, self.r.article_set.add, self.r2) + with self.assertRaisesRegexp(TypeError, "'Article' instance expected, got <Reporter.*"): + self.r.article_set.add(self.r2) self.assertQuerysetEqual(self.r.article_set.all(), [ "<Article: John's second story>", |
