Skip to content

Commit ed23ce2

Browse files
committed
test: make sure missing field is not breaking the admin
1 parent 64f5045 commit ed23ce2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test_proj/blog/tests/test_admin.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,32 @@ def test_skip_rendering_actions_for_unsaved_objects(admin_client, mocker, articl
216216
admin = ArticleAdmin(unsaved_article, admin_site)
217217

218218
assert admin.render_inline_actions(unsaved_article) == ''
219+
220+
221+
@pytest.mark.django_db
222+
def test_missing_render_inline_actions_from_readonly_fields(
223+
rf, admin_user, admin_site, article
224+
):
225+
"""
226+
Make sure that customization does not break the app.
227+
"""
228+
from test_proj.blog import admin
229+
230+
class ArticleAdmin(admin.InlineActionsModelAdminMixin, admin.admin.ModelAdmin):
231+
list_display = ('name',)
232+
inline_actions = None
233+
234+
def get_readonly_fields(self, *args, **kwargs):
235+
"""
236+
Do some fancy logic to return a list of fields, which does not include `render_inline_actions`.
237+
"""
238+
return []
239+
240+
request = rf.get(f'/admin/blog/articles/{article.id}/')
241+
request.user = admin_user
242+
243+
admin = ArticleAdmin(Article, admin_site)
244+
245+
# even though `render_inline_actions` is not part of the fields,
246+
# it should not fail :)
247+
admin.changeform_view(request)

0 commit comments

Comments
 (0)