Skip to content

Commit

Permalink
Fixed expected num queries for MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
ddabble authored Apr 14, 2024
1 parent af1e52d commit 9733b94
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions simple_history/tests/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import django
from django.contrib.auth import get_user_model
from django.db import IntegrityError
from django.db import IntegrityError, connection
from django.test import TestCase, override_settings, skipUnlessDBFeature

from simple_history.manager import SIMPLE_HISTORY_REVERSE_ATTR_NAME
Expand Down Expand Up @@ -151,6 +151,9 @@ def test_historical_query_set(self):
"""
Demonstrates how the HistoricalQuerySet works to provide as_of functionality.
"""
backend = connection.vendor
expected_latest_of_each_queries = 2 if backend == "mysql" else 1

document1 = RankedDocument.objects.create(rank=42)
document2 = RankedDocument.objects.create(rank=84)
document2.rank = 51
Expand All @@ -164,15 +167,15 @@ def test_historical_query_set(self):
self.assertEqual(queryset.count(), 4)

# only want the most recent records (provided by HistoricalQuerySet)
with self.assertNumQueries(1):
with self.assertNumQueries(expected_latest_of_each_queries):
self.assertEqual(queryset.latest_of_each().count(), 2)

# want to see the instances as of that time?
with self.assertNumQueries(1):
with self.assertNumQueries(expected_latest_of_each_queries):
self.assertEqual(queryset.latest_of_each().as_instances().count(), 1)

# these new methods are idempotent
with self.assertNumQueries(1):
with self.assertNumQueries(expected_latest_of_each_queries):
self.assertEqual(
queryset.latest_of_each()
.latest_of_each()
Expand Down

0 comments on commit 9733b94

Please sign in to comment.