diff options
author | Bob Renwick <bob.renwick@gmail.com> | 2020-10-06 10:04:11 +0000 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-06 21:19:56 +0200 |
commit | 036f160733fcceb10975bf03c2fc9ffd9c114612 (patch) | |
tree | a9fc8cc1907a867b7ce5ddb2eb45960914323b35 /tests/prefetch_related | |
parent | 999cddd58d30469f3ee85278985313fdf528323d (diff) | |
download | django-036f160733fcceb10975bf03c2fc9ffd9c114612.tar.gz |
Refs #20577 -- Deferred filtering of prefetched related querysets by reverse m2o relation.
Diffstat (limited to 'tests/prefetch_related')
-rw-r--r-- | tests/prefetch_related/tests.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index 740e9cb1b5..c368e040ea 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -294,17 +294,20 @@ class PrefetchRelatedTests(TestDataMixin, TestCase): def test_filter_deferred(self): """ - Related filtering of prefetched querysets is deferred until necessary. + Related filtering of prefetched querysets is deferred on m2m and + reverse m2o relations until necessary. """ add_q = Query.add_q - with mock.patch.object( - Query, - 'add_q', - autospec=True, - side_effect=lambda self, q: add_q(self, q), - ) as add_q_mock: - list(Book.objects.prefetch_related('authors')) - self.assertEqual(add_q_mock.call_count, 1) + for relation in ['authors', 'first_time_authors']: + with self.subTest(relation=relation): + with mock.patch.object( + Query, + 'add_q', + autospec=True, + side_effect=lambda self, q: add_q(self, q), + ) as add_q_mock: + list(Book.objects.prefetch_related(relation)) + self.assertEqual(add_q_mock.call_count, 1) class RawQuerySetTests(TestDataMixin, TestCase): |