Skip to content

Commit

Permalink
Test num queries of latest_of_each()
Browse files Browse the repository at this point in the history
  • Loading branch information
ddabble authored Apr 14, 2024
1 parent 4d39103 commit af1e52d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions simple_history/tests/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit af1e52d

Please sign in to comment.