summaryrefslogtreecommitdiff
path: root/tests/many_to_one_null
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/many_to_one_null
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
downloaddjango-9c19aff7c7561e3a82978a272ecdaad40dda5c00.tar.gz
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/many_to_one_null')
-rw-r--r--tests/many_to_one_null/models.py6
-rw-r--r--tests/many_to_one_null/tests.py26
2 files changed, 20 insertions, 12 deletions
diff --git a/tests/many_to_one_null/models.py b/tests/many_to_one_null/models.py
index d8561fcee5..a0fcfa6ce5 100644
--- a/tests/many_to_one_null/models.py
+++ b/tests/many_to_one_null/models.py
@@ -17,7 +17,7 @@ class Article(models.Model):
reporter = models.ForeignKey(Reporter, models.SET_NULL, null=True)
class Meta:
- ordering = ('headline',)
+ ordering = ("headline",)
def __str__(self):
return self.headline
@@ -28,4 +28,6 @@ class Car(models.Model):
class Driver(models.Model):
- car = models.ForeignKey(Car, models.SET_NULL, to_field='make', null=True, related_name='drivers')
+ car = models.ForeignKey(
+ Car, models.SET_NULL, to_field="make", null=True, related_name="drivers"
+ )
diff --git a/tests/many_to_one_null/tests.py b/tests/many_to_one_null/tests.py
index d27143bf00..5bd06b1ac4 100644
--- a/tests/many_to_one_null/tests.py
+++ b/tests/many_to_one_null/tests.py
@@ -7,20 +7,20 @@ class ManyToOneNullTests(TestCase):
@classmethod
def setUpTestData(cls):
# Create a Reporter.
- cls.r = Reporter(name='John Smith')
+ cls.r = Reporter(name="John Smith")
cls.r.save()
# Create an Article.
- cls.a = Article(headline='First', reporter=cls.r)
+ cls.a = Article(headline="First", reporter=cls.r)
cls.a.save()
# Create an Article via the Reporter object.
- cls.a2 = cls.r.article_set.create(headline='Second')
+ cls.a2 = cls.r.article_set.create(headline="Second")
# Create an Article with no Reporter by passing "reporter=None".
- cls.a3 = Article(headline='Third', reporter=None)
+ cls.a3 = Article(headline="Third", reporter=None)
cls.a3.save()
# Create another article and reporter
- cls.r2 = Reporter(name='Paul Jones')
+ cls.r2 = Reporter(name="Paul Jones")
cls.r2.save()
- cls.a4 = cls.r2.article_set.create(headline='Fourth')
+ cls.a4 = cls.r2.article_set.create(headline="Fourth")
def test_get_related(self):
self.assertEqual(self.a.reporter.id, self.r.id)
@@ -34,7 +34,9 @@ class ManyToOneNullTests(TestCase):
def test_related_set(self):
# Reporter objects have access to their related Article objects.
self.assertSequenceEqual(self.r.article_set.all(), [self.a, self.a2])
- self.assertSequenceEqual(self.r.article_set.filter(headline__startswith='Fir'), [self.a])
+ self.assertSequenceEqual(
+ self.r.article_set.filter(headline__startswith="Fir"), [self.a]
+ )
self.assertEqual(self.r.article_set.count(), 2)
def test_created_without_related(self):
@@ -42,12 +44,14 @@ class ManyToOneNullTests(TestCase):
# Need to reget a3 to refresh the cache
a3 = Article.objects.get(pk=self.a3.pk)
with self.assertRaises(AttributeError):
- getattr(a3.reporter, 'id')
+ getattr(a3.reporter, "id")
# Accessing an article's 'reporter' attribute returns None
# if the reporter is set to None.
self.assertIsNone(a3.reporter)
# To retrieve the articles with no reporters set, use "reporter__isnull=True".
- self.assertSequenceEqual(Article.objects.filter(reporter__isnull=True), [self.a3])
+ self.assertSequenceEqual(
+ Article.objects.filter(reporter__isnull=True), [self.a3]
+ )
# We can achieve the same thing by filtering for the case where the
# reporter is None.
self.assertSequenceEqual(Article.objects.filter(reporter=None), [self.a3])
@@ -61,7 +65,9 @@ class ManyToOneNullTests(TestCase):
# Remove an article from the set, and check that it was removed.
self.r.article_set.remove(a3)
self.assertSequenceEqual(self.r.article_set.all(), [self.a, self.a2])
- self.assertSequenceEqual(Article.objects.filter(reporter__isnull=True), [self.a3])
+ self.assertSequenceEqual(
+ Article.objects.filter(reporter__isnull=True), [self.a3]
+ )
def test_remove_from_wrong_set(self):
self.assertSequenceEqual(self.r2.article_set.all(), [self.a4])