Fixed isolation of GenericRelationTests.test_filter_targets_related_pk().

This commit is contained in:
Mariusz Felisiak 2021-07-08 13:13:40 +02:00 committed by GitHub
parent 90ba716bf0
commit 7bb0605a8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -228,9 +228,11 @@ class GenericRelationTests(TestCase):
self.assertEqual(qs.filter(links__sum__isnull=False).count(), 0)
def test_filter_targets_related_pk(self):
HasLinkThing.objects.create()
hs2 = HasLinkThing.objects.create()
link = Link.objects.create(content_object=hs2)
# Use hardcoded PKs to ensure different PKs for "link" and "hs2"
# objects.
HasLinkThing.objects.create(pk=1)
hs2 = HasLinkThing.objects.create(pk=2)
link = Link.objects.create(content_object=hs2, pk=1)
self.assertNotEqual(link.object_id, link.pk)
self.assertSequenceEqual(HasLinkThing.objects.filter(links=link.pk), [hs2])