summaryrefslogtreecommitdiff
path: root/tests/admin_utils
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2024-08-09 13:03:24 -0400
committernessita <124304+nessita@users.noreply.github.com>2024-08-28 11:44:05 -0300
commit57307bbc7d88927989cf5b314f16d6e13ade04e6 (patch)
tree2f110306223f71903fbe38a35bedeb898d38677a /tests/admin_utils
parent39abd56a7fb1e2f735040df0fdfc08f57d91a49b (diff)
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.
Diffstat (limited to 'tests/admin_utils')
-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")