1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #26022 -- Used context manager version of assertRaisesMessage in tests.

This commit is contained in:
Hasan
2016-01-04 12:20:08 +03:30
committed by Tim Graham
parent 3d0dcd7f5a
commit 253adc2b8a
21 changed files with 584 additions and 566 deletions

View File

@@ -58,12 +58,12 @@ class EarliestOrLatestTests(TestCase):
# Ensure that error is raised if the user forgot to add a get_latest_by
# in the Model.Meta
Article.objects.model._meta.get_latest_by = None
self.assertRaisesMessage(
with self.assertRaisesMessage(
AssertionError,
"earliest() and latest() require either a field_name parameter or "
"'get_latest_by' in the model",
lambda: Article.objects.earliest(),
)
"'get_latest_by' in the model"
):
Article.objects.earliest()
def test_latest(self):
# Because no Articles exist yet, latest() raises ArticleDoesNotExist.
@@ -109,12 +109,11 @@ class EarliestOrLatestTests(TestCase):
# Ensure that error is raised if the user forgot to add a get_latest_by
# in the Model.Meta
Article.objects.model._meta.get_latest_by = None
self.assertRaisesMessage(
with self.assertRaisesMessage(
AssertionError,
"earliest() and latest() require either a field_name parameter or "
"'get_latest_by' in the model",
lambda: Article.objects.latest(),
)
"earliest() and latest() require either a field_name parameter or "
"'get_latest_by' in the model"):
Article.objects.latest()
def test_latest_manual(self):
# You can still use latest() with a model that doesn't have