summaryrefslogtreecommitdiff
path: root/tests/admin_utils
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2025-03-12 11:05:50 +0000
committernessita <124304+nessita@users.noreply.github.com>2025-03-12 16:25:28 -0300
commit27b68bcadf1ab2e9f7fd223aed42db352ccdc62d (patch)
tree14e4e19a450da3cd0e92402eb0017fa43db66b4f /tests/admin_utils
parented984f2ac4923d6bc625adb4e8d9146765a02ab1 (diff)
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>
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 7ba43c4ba0..a800de0fad 100644
--- a/tests/admin_utils/test_logentry.py
+++ b/tests/admin_utils/test_logentry.py
@@ -254,12 +254,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")
@@ -283,9 +284,55 @@ 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, [])
+ 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