Skip to content

Commit

Permalink
Refs #34462 -- Moved ModelAdmin.log_deletion() test to a separate tes…
Browse files Browse the repository at this point in the history
…t case.
  • Loading branch information
Akash-Kumar-Sen authored and felixxm committed Oct 31, 2023
1 parent 523fed1 commit 45e0c58
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions tests/modeladmin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,6 @@ def test_log_actions(self):
tests = (
(ma.log_addition, ADDITION, {"added": {}}),
(ma.log_change, CHANGE, {"changed": {"fields": ["name", "bio"]}}),
(ma.log_deletion, DELETION, str(self.band)),
)
for method, flag, message in tests:
with self.subTest(name=method.__name__):
Expand All @@ -831,12 +830,23 @@ def test_log_actions(self):
self.assertEqual(fetched.content_type, content_type)
self.assertEqual(fetched.object_id, str(self.band.pk))
self.assertEqual(fetched.user, mock_request.user)
if flag == DELETION:
self.assertEqual(fetched.change_message, "")
self.assertEqual(fetched.object_repr, message)
else:
self.assertEqual(fetched.change_message, str(message))
self.assertEqual(fetched.object_repr, str(self.band))
self.assertEqual(fetched.change_message, str(message))
self.assertEqual(fetched.object_repr, str(self.band))

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)
created = ma.log_deletion(mock_request, self.band, str(self.band))
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))

def test_get_autocomplete_fields(self):
class NameAdmin(ModelAdmin):
Expand Down

0 comments on commit 45e0c58

Please sign in to comment.