From 9733b94e3d4c466a3f940cf09d7f45dcb52e6254 Mon Sep 17 00:00:00 2001 From: Anders <6058745+ddabble@users.noreply.github.com> Date: Sun, 14 Apr 2024 23:05:04 +0200 Subject: [PATCH] Fixed expected num queries for MySQL --- simple_history/tests/tests/test_manager.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/simple_history/tests/tests/test_manager.py b/simple_history/tests/tests/test_manager.py index d86926d8..1a112a0f 100644 --- a/simple_history/tests/tests/test_manager.py +++ b/simple_history/tests/tests/test_manager.py @@ -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 @@ -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 @@ -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()