summaryrefslogtreecommitdiff
path: root/tests/admin_utils/test_logentry.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2024-08-09 13:03:24 -0400
committerNatalia <124304+nessita@users.noreply.github.com>2024-08-28 11:47:15 -0300
commit9a461cae3e5536cbacafa53dbd290ff68df22e67 (patch)
tree7aea2bcfc8b8fd339341aa5c7cb6143a3b99d858 /tests/admin_utils/test_logentry.py
parentdd58edcc373afe57a56bf7c2374a4fc8446e80e9 (diff)
[5.1.x] Fixed #35666 -- Documented stacklevel usage and testing, and adjusted test suite accordingly.
Over the years we've had multiple instances of hit and misses when emitting warnings: either setting the wrong stacklevel or not setting it at all. This work adds assertions for the existing warnings that were declaring the correct stacklevel, but were lacking tests for it. Backport of 57307bbc7d88927989cf5b314f16d6e13ade04e6 from main.
Diffstat (limited to 'tests/admin_utils/test_logentry.py')
-rw-r--r--tests/admin_utils/test_logentry.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/tests/admin_utils/test_logentry.py b/tests/admin_utils/test_logentry.py
index 20bbcccb1c..e97441eb2e 100644
--- a/tests/admin_utils/test_logentry.py
+++ b/tests/admin_utils/test_logentry.py
@@ -240,7 +240,7 @@ class LogEntryTests(TestCase):
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):
+ with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
log_entry = LogEntry.objects.log_action(
self.user.pk,
content_type_val,
@@ -250,6 +250,7 @@ class LogEntryTests(TestCase):
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")
@@ -297,9 +298,12 @@ class LogEntryTests(TestCase):
msg = (
"The usage of log_action() is deprecated. Implement log_actions() instead."
)
- with self.assertNumQueries(3):
- with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
- LogEntry.objects2.log_actions(self.user.pk, queryset, DELETION)
+ 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")