mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
parent
f68fa8b45d
commit
9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions
|
@ -11,25 +11,25 @@ lorem_ipsum = """
|
|||
|
||||
|
||||
class CoalesceTests(TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
Author.objects.create(name='John Smith', alias='smithj')
|
||||
Author.objects.create(name='Rhonda')
|
||||
authors = Author.objects.annotate(display_name=Coalesce('alias', 'name'))
|
||||
Author.objects.create(name="John Smith", alias="smithj")
|
||||
Author.objects.create(name="Rhonda")
|
||||
authors = Author.objects.annotate(display_name=Coalesce("alias", "name"))
|
||||
self.assertQuerysetEqual(
|
||||
authors.order_by('name'), ['smithj', 'Rhonda'],
|
||||
lambda a: a.display_name
|
||||
authors.order_by("name"), ["smithj", "Rhonda"], lambda a: a.display_name
|
||||
)
|
||||
|
||||
def test_gt_two_expressions(self):
|
||||
with self.assertRaisesMessage(ValueError, 'Coalesce must take at least two expressions'):
|
||||
Author.objects.annotate(display_name=Coalesce('alias'))
|
||||
with self.assertRaisesMessage(
|
||||
ValueError, "Coalesce must take at least two expressions"
|
||||
):
|
||||
Author.objects.annotate(display_name=Coalesce("alias"))
|
||||
|
||||
def test_mixed_values(self):
|
||||
a1 = Author.objects.create(name='John Smith', alias='smithj')
|
||||
a2 = Author.objects.create(name='Rhonda')
|
||||
a1 = Author.objects.create(name="John Smith", alias="smithj")
|
||||
a2 = Author.objects.create(name="Rhonda")
|
||||
ar1 = Article.objects.create(
|
||||
title='How to Django',
|
||||
title="How to Django",
|
||||
text=lorem_ipsum,
|
||||
written=timezone.now(),
|
||||
)
|
||||
|
@ -37,42 +37,33 @@ class CoalesceTests(TestCase):
|
|||
ar1.authors.add(a2)
|
||||
# mixed Text and Char
|
||||
article = Article.objects.annotate(
|
||||
headline=Coalesce('summary', 'text', output_field=TextField()),
|
||||
headline=Coalesce("summary", "text", output_field=TextField()),
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
article.order_by('title'), [lorem_ipsum],
|
||||
lambda a: a.headline
|
||||
article.order_by("title"), [lorem_ipsum], lambda a: a.headline
|
||||
)
|
||||
# mixed Text and Char wrapped
|
||||
article = Article.objects.annotate(
|
||||
headline=Coalesce(Lower('summary'), Lower('text'), output_field=TextField()),
|
||||
headline=Coalesce(
|
||||
Lower("summary"), Lower("text"), output_field=TextField()
|
||||
),
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
article.order_by('title'), [lorem_ipsum.lower()],
|
||||
lambda a: a.headline
|
||||
article.order_by("title"), [lorem_ipsum.lower()], lambda a: a.headline
|
||||
)
|
||||
|
||||
def test_ordering(self):
|
||||
Author.objects.create(name='John Smith', alias='smithj')
|
||||
Author.objects.create(name='Rhonda')
|
||||
authors = Author.objects.order_by(Coalesce('alias', 'name'))
|
||||
self.assertQuerysetEqual(
|
||||
authors, ['Rhonda', 'John Smith'],
|
||||
lambda a: a.name
|
||||
)
|
||||
authors = Author.objects.order_by(Coalesce('alias', 'name').asc())
|
||||
self.assertQuerysetEqual(
|
||||
authors, ['Rhonda', 'John Smith'],
|
||||
lambda a: a.name
|
||||
)
|
||||
authors = Author.objects.order_by(Coalesce('alias', 'name').desc())
|
||||
self.assertQuerysetEqual(
|
||||
authors, ['John Smith', 'Rhonda'],
|
||||
lambda a: a.name
|
||||
)
|
||||
Author.objects.create(name="John Smith", alias="smithj")
|
||||
Author.objects.create(name="Rhonda")
|
||||
authors = Author.objects.order_by(Coalesce("alias", "name"))
|
||||
self.assertQuerysetEqual(authors, ["Rhonda", "John Smith"], lambda a: a.name)
|
||||
authors = Author.objects.order_by(Coalesce("alias", "name").asc())
|
||||
self.assertQuerysetEqual(authors, ["Rhonda", "John Smith"], lambda a: a.name)
|
||||
authors = Author.objects.order_by(Coalesce("alias", "name").desc())
|
||||
self.assertQuerysetEqual(authors, ["John Smith", "Rhonda"], lambda a: a.name)
|
||||
|
||||
def test_empty_queryset(self):
|
||||
Author.objects.create(name='John Smith')
|
||||
Author.objects.create(name="John Smith")
|
||||
tests = [
|
||||
Author.objects.none(),
|
||||
Subquery(Author.objects.none()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue