From af1e52d1bb5a54e461d169a5abf5742cfc3094a3 Mon Sep 17 00:00:00 2001 From: Anders <6058745+ddabble@users.noreply.github.com> Date: Sun, 14 Apr 2024 22:52:13 +0200 Subject: [PATCH] Test num queries of latest_of_each() --- simple_history/tests/tests/test_manager.py | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/simple_history/tests/tests/test_manager.py b/simple_history/tests/tests/test_manager.py index 30e5ec11..d86926d8 100644 --- a/simple_history/tests/tests/test_manager.py +++ b/simple_history/tests/tests/test_manager.py @@ -163,21 +163,24 @@ def test_historical_query_set(self): queryset = RankedDocument.history.filter(history_date__lte=t2) self.assertEqual(queryset.count(), 4) - # only want the most recend records (provided by HistoricalQuerySet) - self.assertEqual(queryset.latest_of_each().count(), 2) + # only want the most recent records (provided by HistoricalQuerySet) + with self.assertNumQueries(1): + self.assertEqual(queryset.latest_of_each().count(), 2) # want to see the instances as of that time? - self.assertEqual(queryset.latest_of_each().as_instances().count(), 1) + with self.assertNumQueries(1): + self.assertEqual(queryset.latest_of_each().as_instances().count(), 1) # these new methods are idempotent - self.assertEqual( - queryset.latest_of_each() - .latest_of_each() - .as_instances() - .as_instances() - .count(), - 1, - ) + with self.assertNumQueries(1): + self.assertEqual( + queryset.latest_of_each() + .latest_of_each() + .as_instances() + .as_instances() + .count(), + 1, + ) # that was all the same as calling as_of! self.assertEqual(