summaryrefslogtreecommitdiff
path: root/tests/admin_utils
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2025-03-12 11:05:50 +0000
committerNatalia <124304+nessita@users.noreply.github.com>2025-03-12 16:36:48 -0300
commit95031c1ab1e67c2d77562a0cbce974e6ec439536 (patch)
treef792a83f8b531e750bb5a54ebc5f148d54cb121d /tests/admin_utils
parent5fdc951f43dfc2fc4c2c9ad433d2b05d19243c87 (diff)
[5.2.x] Fixed #36234 -- Restored single_object argument to LogEntry.objects.log_actions().
Thank you Adam Johnson for the report and fix. Thank you Sarah Boyce for your spot on analysis. Regression in c09bceef68e5abb79accedd12dade16aa6577a09, which is partially reverted in this branch. Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Backport of 27b68bcadf1ab2e9f7fd223aed42db352ccdc62d from main.
Diffstat (limited to 'tests/admin_utils')
-rw-r--r--tests/admin_utils/test_logentry.py49
1 files changed, 48 insertions, 1 deletions
diff --git a/tests/admin_utils/test_logentry.py b/tests/admin_utils/test_logentry.py
index 37ddb0da7d..43b6cf5573 100644
--- a/tests/admin_utils/test_logentry.py
+++ b/tests/admin_utils/test_logentry.py
@@ -271,12 +271,13 @@ class LogEntryTests(TestCase):
content_type = ContentType.objects.get_for_model(self.a1)
self.assertEqual(len(queryset), 3)
with self.assertNumQueries(1):
- LogEntry.objects.log_actions(
+ result = LogEntry.objects.log_actions(
self.user.pk,
queryset,
DELETION,
change_message=msg,
)
+ self.assertEqual(len(result), len(queryset))
logs = (
LogEntry.objects.filter(action_flag=DELETION)
.order_by("id")
@@ -300,6 +301,18 @@ class LogEntryTests(TestCase):
)
for obj in queryset
]
+ result_logs = [
+ (
+ entry.user_id,
+ entry.content_type_id,
+ str(entry.object_id),
+ entry.object_repr,
+ entry.action_flag,
+ entry.change_message,
+ )
+ for entry in result
+ ]
+ self.assertSequenceEqual(logs, result_logs)
self.assertSequenceEqual(logs, expected_log_values)
self.assertEqual(self.signals, [])
@@ -343,6 +356,40 @@ class LogEntryTests(TestCase):
]
self.assertSequenceEqual(log_values, expected_log_values)
+ def test_log_actions_single_object_param(self):
+ queryset = Article.objects.filter(pk=self.a1.pk)
+ msg = "Deleted Something"
+ content_type = ContentType.objects.get_for_model(self.a1)
+ self.assertEqual(len(queryset), 1)
+ for single_object in (True, False):
+ self.signals = []
+ with self.subTest(single_object=single_object), self.assertNumQueries(1):
+ result = LogEntry.objects.log_actions(
+ self.user.pk,
+ queryset,
+ DELETION,
+ change_message=msg,
+ single_object=single_object,
+ )
+ if single_object:
+ self.assertIsInstance(result, LogEntry)
+ entry = result
+ else:
+ self.assertIsInstance(result, list)
+ self.assertEqual(len(result), 1)
+ entry = result[0]
+ self.assertEqual(entry.user_id, self.user.pk)
+ self.assertEqual(entry.content_type_id, content_type.id)
+ self.assertEqual(str(entry.object_id), str(self.a1.pk))
+ self.assertEqual(entry.object_repr, str(self.a1))
+ self.assertEqual(entry.action_flag, DELETION)
+ self.assertEqual(entry.change_message, msg)
+ expected_signals = [
+ ("pre_save", entry),
+ ("post_save", entry, True),
+ ]
+ self.assertEqual(self.signals, expected_signals)
+
def test_recentactions_without_content_type(self):
"""
If a LogEntry is missing content_type it will not display it in span