diff options
| author | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-12-12 16:55:42 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-15 22:28:37 +0100 |
| commit | 6c120508b6445cb0d6198b4eacccd411960686d2 (patch) | |
| tree | 95eda814c10c2d78b1f0d4dc258b55b17fecea49 /tests | |
| parent | 817bc5800b40bcc74534de5e5176919cb826494f (diff) | |
Refs #34462 -- Removed ModelAdmin.log_deletion() and LogEntryManager.log_action() per deprecation timeline.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_utils/models.py | 24 | ||||
| -rw-r--r-- | tests/admin_utils/test_logentry.py | 59 | ||||
| -rw-r--r-- | tests/modeladmin/tests.py | 75 |
3 files changed, 1 insertions, 157 deletions
diff --git a/tests/admin_utils/models.py b/tests/admin_utils/models.py index 8e812e27eb..243f314b03 100644 --- a/tests/admin_utils/models.py +++ b/tests/admin_utils/models.py @@ -1,5 +1,4 @@ from django.contrib import admin -from django.contrib.admin.models import LogEntry, LogEntryManager from django.db import models from django.utils.translation import gettext_lazy as _ @@ -87,26 +86,3 @@ class VehicleMixin(Vehicle): class Car(VehicleMixin): pass - - -class InheritedLogEntryManager(LogEntryManager): - model = LogEntry - - def log_action( - self, - user_id, - content_type_id, - object_id, - object_repr, - action_flag, - change_message="", - ): - return LogEntry.objects.create( - user_id=user_id, - content_type_id=content_type_id, - object_id=str(object_id), - # Changing actual repr to test repr - object_repr="Test Repr", - action_flag=action_flag, - change_message=change_message, - ) diff --git a/tests/admin_utils/test_logentry.py b/tests/admin_utils/test_logentry.py index e97441eb2e..491a220199 100644 --- a/tests/admin_utils/test_logentry.py +++ b/tests/admin_utils/test_logentry.py @@ -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 diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index 00db6c19bc..3d2e8d00fb 100644 --- a/tests/modeladmin/tests.py +++ b/tests/modeladmin/tests.py @@ -21,7 +21,6 @@ from django.db import models from django.forms.widgets import Select from django.test import RequestFactory, SimpleTestCase, TestCase from django.test.utils import isolate_apps -from django.utils.deprecation import RemovedInDjango60Warning from .models import Band, Concert, Song @@ -891,80 +890,6 @@ class ModelAdminTests(TestCase): ] self.assertSequenceEqual(logs, expected_log_values) - # RemovedInDjango60Warning. - def test_log_deletion(self): - ma = ModelAdmin(Band, self.site) - mock_request = MockRequest() - mock_request.user = User.objects.create(username="bill") - content_type = get_content_type_for_model(self.band) - msg = "ModelAdmin.log_deletion() is deprecated. Use log_deletions() instead." - with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: - created = ma.log_deletion(mock_request, self.band, str(self.band)) - self.assertEqual(ctx.filename, __file__) - fetched = LogEntry.objects.filter(action_flag=DELETION).latest("id") - self.assertEqual(created, fetched) - self.assertEqual(fetched.action_flag, DELETION) - self.assertEqual(fetched.content_type, content_type) - self.assertEqual(fetched.object_id, str(self.band.pk)) - self.assertEqual(fetched.user, mock_request.user) - self.assertEqual(fetched.change_message, "") - self.assertEqual(fetched.object_repr, str(self.band)) - - # RemovedInDjango60Warning. - def test_log_deletion_fallback(self): - class InheritedModelAdmin(ModelAdmin): - def log_deletion(self, request, obj, object_repr): - return super().log_deletion(request, obj, object_repr) - - ima = InheritedModelAdmin(Band, self.site) - mock_request = MockRequest() - mock_request.user = User.objects.create(username="akash") - content_type = get_content_type_for_model(self.band) - Band.objects.create( - name="The Beatles", - bio="A legendary rock band from Liverpool.", - sign_date=date(1962, 1, 1), - ) - Band.objects.create( - name="Mohiner Ghoraguli", - bio="A progressive rock band from Calcutta.", - sign_date=date(1975, 1, 1), - ) - queryset = Band.objects.all().order_by("-id")[:3] - self.assertEqual(len(queryset), 3) - msg = ( - "The usage of log_deletion() is deprecated. Implement log_deletions() " - "instead." - ) - with self.assertNumQueries(3): - with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: - ima.log_deletions(mock_request, queryset) - self.assertEqual(ctx.filename, __file__) - logs = ( - LogEntry.objects.filter(action_flag=DELETION) - .order_by("id") - .values_list( - "user_id", - "content_type", - "object_id", - "object_repr", - "action_flag", - "change_message", - ) - ) - expected_log_values = [ - ( - mock_request.user.id, - content_type.id, - str(obj.pk), - str(obj), - DELETION, - "", - ) - for obj in queryset - ] - self.assertSequenceEqual(logs, expected_log_values) - def test_get_autocomplete_fields(self): class NameAdmin(ModelAdmin): search_fields = ["name"] |
