Skip to content

Commit

Permalink
test num queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ddabble committed Aug 24, 2024
1 parent d8cf0b8 commit 760ad00
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion simple_history/tests/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import django
from django.contrib.auth import get_user_model
from django.db import IntegrityError, transaction
from django.db import IntegrityError, connection, transaction
from django.test import TestCase, TransactionTestCase, override_settings
from django.utils import timezone

Expand Down Expand Up @@ -155,6 +155,22 @@ def test_bulk_create_history_with_disabled_setting(self):
self.assertEqual(Poll.objects.count(), 5)
self.assertEqual(Poll.history.count(), 0)

def test_bulk_create_history_without_pks(self):
for poll in self.data:
poll.pk = None

# See https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create
db_supports_returning_autofield_pks = connection.vendor in {
"postgresql",
"sqlite",
}
# An extra query must be made on some DBs to retrieve the auto-generated PKs
with self.assertNumQueries(2 if db_supports_returning_autofield_pks else 3):
bulk_create_with_history(self.data, Poll)

self.assertEqual(Poll.objects.count(), 5)
self.assertEqual(Poll.history.count(), 5)

def test_bulk_create_history_alternative_manager(self):
bulk_create_with_history(
self.data,
Expand Down

0 comments on commit 760ad00

Please sign in to comment.