1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #34462 -- Removed ModelAdmin.log_deletion() and LogEntryManager.log_action() per deprecation timeline.

This commit is contained in:
Sarah Boyce
2024-12-12 16:55:42 +01:00
parent 817bc5800b
commit 6c120508b6
6 changed files with 4 additions and 240 deletions

View File

@@ -8,10 +8,9 @@ from django.contrib.contenttypes.models import ContentType
from django.test import TestCase, override_settings
from django.urls import reverse
from django.utils import translation
from django.utils.deprecation import RemovedInDjango60Warning
from django.utils.html import escape
from .models import Article, ArticleProxy, Car, InheritedLogEntryManager, Site
from .models import Article, ArticleProxy, Car, Site
@override_settings(ROOT_URLCONF="admin_utils.urls")
@@ -236,22 +235,6 @@ class LogEntryTests(TestCase):
logentry = LogEntry.objects.first()
self.assertEqual(repr(logentry), str(logentry.action_time))
# RemovedInDjango60Warning.
def test_log_action(self):
msg = "LogEntryManager.log_action() is deprecated. Use log_actions() instead."
content_type_val = ContentType.objects.get_for_model(Article).pk
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
log_entry = LogEntry.objects.log_action(
self.user.pk,
content_type_val,
self.a1.pk,
repr(self.a1),
CHANGE,
change_message="Changed something else",
)
self.assertEqual(log_entry, LogEntry.objects.latest("id"))
self.assertEqual(ctx.filename, __file__)
def test_log_actions(self):
queryset = Article.objects.all().order_by("-id")
msg = "Deleted Something"
@@ -289,46 +272,6 @@ class LogEntryTests(TestCase):
]
self.assertSequenceEqual(logs, expected_log_values)
# RemovedInDjango60Warning.
def test_log_action_fallback(self):
LogEntry.objects2 = InheritedLogEntryManager()
queryset = Article.objects.all().order_by("-id")
content_type = ContentType.objects.get_for_model(self.a1)
self.assertEqual(len(queryset), 3)
msg = (
"The usage of log_action() is deprecated. Implement log_actions() instead."
)
with (
self.assertNumQueries(3),
self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx,
):
LogEntry.objects2.log_actions(self.user.pk, queryset, DELETION)
self.assertEqual(ctx.filename, __file__)
log_values = (
LogEntry.objects.filter(action_flag=DELETION)
.order_by("id")
.values_list(
"user",
"content_type",
"object_id",
"object_repr",
"action_flag",
"change_message",
)
)
expected_log_values = [
(
self.user.pk,
content_type.id,
str(obj.pk),
"Test Repr",
DELETION,
"",
)
for obj in queryset
]
self.assertSequenceEqual(log_values, expected_log_values)
def test_recentactions_without_content_type(self):
"""
If a LogEntry is missing content_type it will not display it in span