summaryrefslogtreecommitdiff
path: root/tests/model_inheritance
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2017-05-28 21:37:21 +0200
committerTim Graham <timograham@gmail.com>2017-07-29 19:07:23 -0400
commita51c4de1945be2225f20fad794cfb52d8f1f9236 (patch)
tree36386b70a27cf027a8a491de319c3e59e0d3d0cd /tests/model_inheritance
parent38988f289f7f5708f5ea85de2d5dfe0d86b23106 (diff)
downloaddjango-a51c4de1945be2225f20fad794cfb52d8f1f9236.tar.gz
Used assertRaisesMessage() to test Django's error messages.
Diffstat (limited to 'tests/model_inheritance')
-rw-r--r--tests/model_inheritance/test_abstract_inheritance.py5
-rw-r--r--tests/model_inheritance/tests.py12
2 files changed, 12 insertions, 5 deletions
diff --git a/tests/model_inheritance/test_abstract_inheritance.py b/tests/model_inheritance/test_abstract_inheritance.py
index c496ac963b..f03bc3fa7e 100644
--- a/tests/model_inheritance/test_abstract_inheritance.py
+++ b/tests/model_inheritance/test_abstract_inheritance.py
@@ -150,10 +150,11 @@ class AbstractInheritanceTests(TestCase):
def full_name(self):
return self.first_name + self.last_name
- with self.assertRaises(FieldDoesNotExist):
+ msg = "Descendant has no field named %r"
+ with self.assertRaisesMessage(FieldDoesNotExist, msg % 'middle_name'):
Descendant._meta.get_field('middle_name')
- with self.assertRaises(FieldDoesNotExist):
+ with self.assertRaisesMessage(FieldDoesNotExist, msg % 'full_name'):
Descendant._meta.get_field('full_name')
def test_overriding_field_removed_by_concrete_model(self):
diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py
index feff4a1407..e1eca65742 100644
--- a/tests/model_inheritance/tests.py
+++ b/tests/model_inheritance/tests.py
@@ -43,7 +43,7 @@ class ModelInheritanceTests(TestCase):
# However, the CommonInfo class cannot be used as a normal model (it
# doesn't exist as a model).
- with self.assertRaises(AttributeError):
+ with self.assertRaisesMessage(AttributeError, "'CommonInfo' has no attribute 'objects'"):
CommonInfo.objects.all()
def test_reverse_relation_for_different_hierarchy_tree(self):
@@ -51,7 +51,12 @@ class ModelInheritanceTests(TestCase):
# Restaurant object cannot access that reverse relation, since it's not
# part of the Place-Supplier Hierarchy.
self.assertQuerysetEqual(Place.objects.filter(supplier__name="foo"), [])
- with self.assertRaises(FieldError):
+ msg = (
+ "Cannot resolve keyword 'supplier' into field. Choices are: "
+ "address, chef, chef_id, id, italianrestaurant, lot, name, "
+ "place_ptr, place_ptr_id, provider, rating, serves_hot_dogs, serves_pizza"
+ )
+ with self.assertRaisesMessage(FieldError, msg):
Restaurant.objects.filter(supplier__name="foo")
def test_model_with_distinct_accessors(self):
@@ -65,7 +70,8 @@ class ModelInheritanceTests(TestCase):
# The Post model doesn't have an attribute called
# 'attached_%(class)s_set'.
- with self.assertRaises(AttributeError):
+ msg = "'Post' object has no attribute 'attached_%(class)s_set'"
+ with self.assertRaisesMessage(AttributeError, msg):
getattr(post, "attached_%(class)s_set")
def test_model_with_distinct_related_query_name(self):