diff options
author | django-bot <ops@djangoproject.com> | 2022-02-03 20:24:19 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-07 20:37:05 +0100 |
commit | 9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch) | |
tree | f0506b668a013d0063e5fba3dbf4863b466713ba /tests/get_object_or_404 | |
parent | f68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff) | |
download | django-9c19aff7c7561e3a82978a272ecdaad40dda5c00.tar.gz |
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/get_object_or_404')
-rw-r--r-- | tests/get_object_or_404/models.py | 4 | ||||
-rw-r--r-- | tests/get_object_or_404/tests.py | 37 |
2 files changed, 16 insertions, 25 deletions
diff --git a/tests/get_object_or_404/models.py b/tests/get_object_or_404/models.py index 24c6aa975c..d130883c53 100644 --- a/tests/get_object_or_404/models.py +++ b/tests/get_object_or_404/models.py @@ -19,12 +19,12 @@ class Author(models.Model): class ArticleManager(models.Manager): def get_queryset(self): - return super().get_queryset().filter(authors__name__icontains='sir') + return super().get_queryset().filter(authors__name__icontains="sir") class AttributeErrorManager(models.Manager): def get_queryset(self): - raise AttributeError('AttributeErrorManager') + raise AttributeError("AttributeErrorManager") class Article(models.Model): diff --git a/tests/get_object_or_404/tests.py b/tests/get_object_or_404/tests.py index 87bfa6d3ea..5fdceaa04a 100644 --- a/tests/get_object_or_404/tests.py +++ b/tests/get_object_or_404/tests.py @@ -18,15 +18,11 @@ class GetObjectOr404Tests(TestCase): article = Article.objects.create(title="Run away!") article.authors.set([a1, a2]) # get_object_or_404 can be passed a Model to query. - self.assertEqual( - get_object_or_404(Article, title__contains="Run"), - article - ) + self.assertEqual(get_object_or_404(Article, title__contains="Run"), article) # We can also use the Article manager through an Author object. self.assertEqual( - get_object_or_404(a1.article_set, title__contains="Run"), - article + get_object_or_404(a1.article_set, title__contains="Run"), article ) # No articles containing "Camelot". This should raise an Http404 error. @@ -35,14 +31,12 @@ class GetObjectOr404Tests(TestCase): # Custom managers can be used too. self.assertEqual( - get_object_or_404(Article.by_a_sir, title="Run away!"), - article + get_object_or_404(Article.by_a_sir, title="Run away!"), article ) # QuerySets can be used too. self.assertEqual( - get_object_or_404(Article.objects.all(), title__contains="Run"), - article + get_object_or_404(Article.objects.all(), title__contains="Run"), article ) # Just as when using a get() lookup, you will get an error if more than @@ -57,8 +51,7 @@ class GetObjectOr404Tests(TestCase): # get_list_or_404 can be used to get lists of objects self.assertEqual( - get_list_or_404(a1.article_set, title__icontains="Run"), - [article] + get_list_or_404(a1.article_set, title__icontains="Run"), [article] ) # Http404 is returned if the list is empty. @@ -67,29 +60,27 @@ class GetObjectOr404Tests(TestCase): # Custom managers can be used too. self.assertEqual( - get_list_or_404(Article.by_a_sir, title__icontains="Run"), - [article] + get_list_or_404(Article.by_a_sir, title__icontains="Run"), [article] ) # QuerySets can be used too. self.assertEqual( - get_list_or_404(Article.objects.all(), title__icontains="Run"), - [article] + get_list_or_404(Article.objects.all(), title__icontains="Run"), [article] ) # Q objects. self.assertEqual( get_object_or_404( Article, - Q(title__startswith='Run') | Q(title__startswith='Walk'), - authors__name__contains='Brave', + Q(title__startswith="Run") | Q(title__startswith="Walk"), + authors__name__contains="Brave", ), article, ) self.assertEqual( get_list_or_404( Article, - Q(title__startswith='Run') | Q(title__startswith='Walk'), - authors__name='Patsy', + Q(title__startswith="Run") | Q(title__startswith="Walk"), + authors__name="Patsy", ), [article], ) @@ -115,10 +106,10 @@ class GetObjectOr404Tests(TestCase): def test_get_object_or_404_queryset_attribute_error(self): """AttributeError raised by QuerySet.get() isn't hidden.""" - with self.assertRaisesMessage(AttributeError, 'AttributeErrorManager'): + with self.assertRaisesMessage(AttributeError, "AttributeErrorManager"): get_object_or_404(Article.attribute_error_objects, id=42) def test_get_list_or_404_queryset_attribute_error(self): """AttributeError raised by QuerySet.filter() isn't hidden.""" - with self.assertRaisesMessage(AttributeError, 'AttributeErrorManager'): - get_list_or_404(Article.attribute_error_objects, title__icontains='Run') + with self.assertRaisesMessage(AttributeError, "AttributeErrorManager"): + get_list_or_404(Article.attribute_error_objects, title__icontains="Run") |