mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #26022 -- Used context manager version of assertRaisesMessage in tests.
This commit is contained in:
parent
3d0dcd7f5a
commit
253adc2b8a
21 changed files with 584 additions and 566 deletions
|
@ -91,31 +91,22 @@ class CustomColumnsTests(TestCase):
|
|||
self.assertEqual(self.a1, Author.objects.get(first_name__exact='John'))
|
||||
|
||||
def test_filter_on_nonexistent_field(self):
|
||||
self.assertRaisesMessage(
|
||||
FieldError,
|
||||
msg = (
|
||||
"Cannot resolve keyword 'firstname' into field. Choices are: "
|
||||
"Author_ID, article, first_name, last_name, primary_set",
|
||||
Author.objects.filter,
|
||||
firstname__exact='John'
|
||||
"Author_ID, article, first_name, last_name, primary_set"
|
||||
)
|
||||
with self.assertRaisesMessage(FieldError, msg):
|
||||
Author.objects.filter(firstname__exact='John')
|
||||
|
||||
def test_author_get_attributes(self):
|
||||
a = Author.objects.get(last_name__exact='Smith')
|
||||
self.assertEqual('John', a.first_name)
|
||||
self.assertEqual('Smith', a.last_name)
|
||||
self.assertRaisesMessage(
|
||||
AttributeError,
|
||||
"'Author' object has no attribute 'firstname'",
|
||||
getattr,
|
||||
a, 'firstname'
|
||||
)
|
||||
with self.assertRaisesMessage(AttributeError, "'Author' object has no attribute 'firstname'"):
|
||||
getattr(a, 'firstname')
|
||||
|
||||
self.assertRaisesMessage(
|
||||
AttributeError,
|
||||
"'Author' object has no attribute 'last'",
|
||||
getattr,
|
||||
a, 'last'
|
||||
)
|
||||
with self.assertRaisesMessage(AttributeError, "'Author' object has no attribute 'last'"):
|
||||
getattr(a, 'last')
|
||||
|
||||
def test_m2m_table(self):
|
||||
self.assertQuerysetEqual(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue