diff options
author | Hasan <hasan.r67@gmail.com> | 2016-01-04 12:20:08 +0330 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-01-29 13:03:39 -0500 |
commit | 253adc2b8a52982139d40c4f55b3fd446e1cb8f3 (patch) | |
tree | c508d48636f5b37e97c8078737d398d7475ff8cc /tests/custom_columns | |
parent | 3d0dcd7f5af378d3ab6adb303b913e6c7b2e0ee5 (diff) | |
download | django-253adc2b8a52982139d40c4f55b3fd446e1cb8f3.tar.gz |
Refs #26022 -- Used context manager version of assertRaisesMessage in tests.
Diffstat (limited to 'tests/custom_columns')
-rw-r--r-- | tests/custom_columns/tests.py | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/tests/custom_columns/tests.py b/tests/custom_columns/tests.py index 2b5526453f..7102e4fdbe 100644 --- a/tests/custom_columns/tests.py +++ b/tests/custom_columns/tests.py @@ -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( |