diff options
| author | Akash Kumar Sen <Akash-Kumar-Sen@users.noreply.github.com> | 2023-06-12 08:50:55 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-10-31 18:06:44 +0100 |
| commit | 40b3975e7d3e1464a733c69171ad7d38f8814280 (patch) | |
| tree | dabd02bf22c82b52556931bb7c633b28753f6ab0 /tests/admin_views | |
| parent | 45e0c5892f84b5bb47999cbe16eabb5a13293d85 (diff) | |
Fixed #34462 -- Made admin log actions in bulk.
This also deprecates ModelAdmin.log_deletion() and
LogEntryManager.log_action().
Diffstat (limited to 'tests/admin_views')
| -rw-r--r-- | tests/admin_views/test_actions.py | 19 | ||||
| -rw-r--r-- | tests/admin_views/test_history_view.py | 9 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 24 |
3 files changed, 29 insertions, 23 deletions
diff --git a/tests/admin_views/test_actions.py b/tests/admin_views/test_actions.py index 35e4583d95..8e1fc144e4 100644 --- a/tests/admin_views/test_actions.py +++ b/tests/admin_views/test_actions.py @@ -4,9 +4,11 @@ from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME from django.contrib.admin.views.main import IS_POPUP_VAR from django.contrib.auth.models import Permission, User from django.core import mail +from django.db import connection from django.template.loader import render_to_string from django.template.response import TemplateResponse from django.test import TestCase, override_settings +from django.test.utils import CaptureQueriesContext from django.urls import reverse from .admin import SubscriberAdmin @@ -74,8 +76,21 @@ class AdminActionsTest(TestCase): self.assertContains(confirmation, "<li>Subscribers: 2</li>") self.assertContains(confirmation, "<li>External subscribers: 1</li>") self.assertContains(confirmation, ACTION_CHECKBOX_NAME, count=2) - self.client.post( - reverse("admin:admin_views_subscriber_changelist"), delete_confirmation_data + with CaptureQueriesContext(connection) as ctx: + self.client.post( + reverse("admin:admin_views_subscriber_changelist"), + delete_confirmation_data, + ) + # Log entries are inserted in bulk. + self.assertEqual( + len( + [ + q["sql"] + for q in ctx.captured_queries + if q["sql"].startswith("INSERT") + ] + ), + 1, ) self.assertEqual(Subscriber.objects.count(), 0) diff --git a/tests/admin_views/test_history_view.py b/tests/admin_views/test_history_view.py index ddfdd56ca6..dfac3530bf 100644 --- a/tests/admin_views/test_history_view.py +++ b/tests/admin_views/test_history_view.py @@ -1,7 +1,6 @@ from django.contrib.admin.models import CHANGE, LogEntry from django.contrib.admin.tests import AdminSeleniumTestCase from django.contrib.auth.models import User -from django.contrib.contenttypes.models import ContentType from django.core.paginator import Paginator from django.test import TestCase, override_settings from django.urls import reverse @@ -61,15 +60,13 @@ class SeleniumTests(AdminSeleniumTestCase): password="secret", email="super@example.com", ) - content_type_pk = ContentType.objects.get_for_model(User).pk for i in range(1, 1101): - LogEntry.objects.log_action( + LogEntry.objects.log_actions( self.superuser.pk, - content_type_pk, - self.superuser.pk, - repr(self.superuser), + [self.superuser], CHANGE, change_message=f"Changed something {i}", + single_object=True, ) self.admin_login( username="super", diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 053270db40..ecb177e47f 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -3808,33 +3808,27 @@ class AdminViewStringPrimaryKeyTest(TestCase): r"""-_.!~*'() ;/?:@&=+$, <>#%" {}|\^[]`""" ) cls.m1 = ModelWithStringPrimaryKey.objects.create(string_pk=cls.pk) - content_type_pk = ContentType.objects.get_for_model( - ModelWithStringPrimaryKey - ).pk user_pk = cls.superuser.pk - LogEntry.objects.log_action( + LogEntry.objects.log_actions( user_pk, - content_type_pk, - cls.pk, - cls.pk, + [cls.m1], 2, change_message="Changed something", + single_object=True, ) - LogEntry.objects.log_action( + LogEntry.objects.log_actions( user_pk, - content_type_pk, - cls.pk, - cls.pk, + [cls.m1], 1, change_message="Added something", + single_object=True, ) - LogEntry.objects.log_action( + LogEntry.objects.log_actions( user_pk, - content_type_pk, - cls.pk, - cls.pk, + [cls.m1], 3, change_message="Deleted something", + single_object=True, ) def setUp(self): |
