summaryrefslogtreecommitdiff
path: root/tests/null_fk
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-03 20:24:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch)
treef0506b668a013d0063e5fba3dbf4863b466713ba /tests/null_fk
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
downloaddjango-9c19aff7c7561e3a82978a272ecdaad40dda5c00.tar.gz
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/null_fk')
-rw-r--r--tests/null_fk/models.py5
-rw-r--r--tests/null_fk/tests.py49
2 files changed, 27 insertions, 27 deletions
diff --git a/tests/null_fk/models.py b/tests/null_fk/models.py
index 01f69c1807..13a425f646 100644
--- a/tests/null_fk/models.py
+++ b/tests/null_fk/models.py
@@ -32,7 +32,8 @@ class Comment(models.Model):
comment_text = models.CharField(max_length=250)
class Meta:
- ordering = ('comment_text',)
+ ordering = ("comment_text",)
+
# Ticket 15823
@@ -46,6 +47,6 @@ class PropertyValue(models.Model):
class Property(models.Model):
- item = models.ForeignKey(Item, models.CASCADE, related_name='props')
+ item = models.ForeignKey(Item, models.CASCADE, related_name="props")
key = models.CharField(max_length=100)
value = models.ForeignKey(PropertyValue, models.SET_NULL, null=True)
diff --git a/tests/null_fk/tests.py b/tests/null_fk/tests.py
index e587d6551b..174d5ba064 100644
--- a/tests/null_fk/tests.py
+++ b/tests/null_fk/tests.py
@@ -1,20 +1,17 @@
from django.db.models import Q
from django.test import TestCase
-from .models import (
- Comment, Forum, Item, Post, PropertyValue, SystemDetails, SystemInfo,
-)
+from .models import Comment, Forum, Item, Post, PropertyValue, SystemDetails, SystemInfo
class NullFkTests(TestCase):
-
def test_null_fk(self):
- d = SystemDetails.objects.create(details='First details')
- s = SystemInfo.objects.create(system_name='First forum', system_details=d)
- f = Forum.objects.create(system_info=s, forum_name='First forum')
- p = Post.objects.create(forum=f, title='First Post')
- c1 = Comment.objects.create(post=p, comment_text='My first comment')
- c2 = Comment.objects.create(comment_text='My second comment')
+ d = SystemDetails.objects.create(details="First details")
+ s = SystemInfo.objects.create(system_name="First forum", system_details=d)
+ f = Forum.objects.create(system_info=s, forum_name="First forum")
+ p = Post.objects.create(forum=f, title="First Post")
+ c1 = Comment.objects.create(post=p, comment_text="My first comment")
+ c2 = Comment.objects.create(comment_text="My second comment")
# Starting from comment, make sure that a .select_related(...) with a specified
# set of fields will properly LEFT JOIN multiple levels of NULLs (and the things
@@ -25,33 +22,35 @@ class NullFkTests(TestCase):
self.assertIsNone(Comment.objects.select_related().get(id=c2.id).post)
self.assertQuerysetEqual(
- Comment.objects.select_related('post__forum__system_info').all(),
+ Comment.objects.select_related("post__forum__system_info").all(),
[
- (c1.id, 'My first comment', '<Post: First Post>'),
- (c2.id, 'My second comment', 'None')
+ (c1.id, "My first comment", "<Post: First Post>"),
+ (c2.id, "My second comment", "None"),
],
- transform=lambda c: (c.id, c.comment_text, repr(c.post))
+ transform=lambda c: (c.id, c.comment_text, repr(c.post)),
)
# Regression test for #7530, #7716.
- self.assertIsNone(Comment.objects.select_related('post').filter(post__isnull=True)[0].post)
+ self.assertIsNone(
+ Comment.objects.select_related("post").filter(post__isnull=True)[0].post
+ )
self.assertQuerysetEqual(
- Comment.objects.select_related('post__forum__system_info__system_details'),
+ Comment.objects.select_related("post__forum__system_info__system_details"),
[
- (c1.id, 'My first comment', '<Post: First Post>'),
- (c2.id, 'My second comment', 'None')
+ (c1.id, "My first comment", "<Post: First Post>"),
+ (c2.id, "My second comment", "None"),
],
- transform=lambda c: (c.id, c.comment_text, repr(c.post))
+ transform=lambda c: (c.id, c.comment_text, repr(c.post)),
)
def test_combine_isnull(self):
- item = Item.objects.create(title='Some Item')
- pv = PropertyValue.objects.create(label='Some Value')
- item.props.create(key='a', value=pv)
- item.props.create(key='b') # value=NULL
- q1 = Q(props__key='a', props__value=pv)
- q2 = Q(props__key='b', props__value__isnull=True)
+ item = Item.objects.create(title="Some Item")
+ pv = PropertyValue.objects.create(label="Some Value")
+ item.props.create(key="a", value=pv)
+ item.props.create(key="b") # value=NULL
+ q1 = Q(props__key="a", props__value=pv)
+ q2 = Q(props__key="b", props__value__isnull=True)
# Each of these individually should return the item.
self.assertEqual(Item.objects.get(q1), item)