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
|
@ -9,32 +9,44 @@ from ..models import Author
|
|||
|
||||
|
||||
class NullIfTests(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
Author.objects.create(name='John Smith', alias='smithj')
|
||||
Author.objects.create(name='Rhonda', alias='Rhonda')
|
||||
Author.objects.create(name="John Smith", alias="smithj")
|
||||
Author.objects.create(name="Rhonda", alias="Rhonda")
|
||||
|
||||
def test_basic(self):
|
||||
authors = Author.objects.annotate(nullif=NullIf('alias', 'name')).values_list('nullif')
|
||||
authors = Author.objects.annotate(nullif=NullIf("alias", "name")).values_list(
|
||||
"nullif"
|
||||
)
|
||||
self.assertSequenceEqual(
|
||||
authors, [
|
||||
('smithj',),
|
||||
('' if connection.features.interprets_empty_strings_as_nulls else None,)
|
||||
]
|
||||
authors,
|
||||
[
|
||||
("smithj",),
|
||||
(
|
||||
""
|
||||
if connection.features.interprets_empty_strings_as_nulls
|
||||
else None,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_null_argument(self):
|
||||
authors = Author.objects.annotate(nullif=NullIf('name', Value(None))).values_list('nullif')
|
||||
self.assertSequenceEqual(authors, [('John Smith',), ('Rhonda',)])
|
||||
authors = Author.objects.annotate(
|
||||
nullif=NullIf("name", Value(None))
|
||||
).values_list("nullif")
|
||||
self.assertSequenceEqual(authors, [("John Smith",), ("Rhonda",)])
|
||||
|
||||
def test_too_few_args(self):
|
||||
msg = "'NullIf' takes exactly 2 arguments (1 given)"
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
NullIf('name')
|
||||
NullIf("name")
|
||||
|
||||
@skipUnless(connection.vendor == 'oracle', 'Oracle specific test for NULL-literal')
|
||||
@skipUnless(connection.vendor == "oracle", "Oracle specific test for NULL-literal")
|
||||
def test_null_literal(self):
|
||||
msg = 'Oracle does not allow Value(None) for expression1.'
|
||||
msg = "Oracle does not allow Value(None) for expression1."
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
list(Author.objects.annotate(nullif=NullIf(Value(None), 'name')).values_list('nullif'))
|
||||
list(
|
||||
Author.objects.annotate(nullif=NullIf(Value(None), "name")).values_list(
|
||||
"nullif"
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue