[Django] #36038: Added a test case for the display_for_field function when a FileField is passed.

27 views
Skip to first unread message

Django

unread,
Dec 25, 2024, 8:40:35 AM12/25/24
to django-...@googlegroups.com
#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: (none)
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: 5.1
Severity: Normal | Keywords: display_for_field,
Triage Stage: | FileFIeld
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
{{{
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
...
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
...
}}}
There is no test case for the display_for_field function when a
`FileField` object is passed. -->
[https://github.com/django/django/blob/main/tests/admin_utils/tests.py
admin_utils test code]

When the `FileField` handling was added in the above function, I found
that the test was conducted indirectly through the ModelAdmin
readonly_fields attribute. -->
[https://github.com/django/django/blob/main/tests/admin_widgets/tests.py#L654
test code]

However, I believe it would be better to have a direct test case for when
a FileField is passed, considering that display_for_field function is
globally accessible.
--
Ticket URL: <https://code.djangoproject.com/ticket/36038>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 25, 2024, 8:40:46 AM12/25/24
to django-...@googlegroups.com
#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: display_for_field, | Triage Stage:
FileFIeld | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* owner: (none) => Antoliny

--
Ticket URL: <https://code.djangoproject.com/ticket/36038#comment:1>

Django

unread,
Dec 25, 2024, 8:42:57 AM12/25/24
to django-...@googlegroups.com
#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: display_for_field, | Triage Stage:
FileFIeld | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Antoliny:

Old description:

> {{{
> def display_for_field(value, field, empty_value_display):
> from django.contrib.admin.templatetags.admin_list import
> _boolean_icon
> ...
> elif isinstance(field, (models.IntegerField, models.FloatField)):
> return formats.number_format(value)
> elif isinstance(field, models.FileField) and value:
> return format_html('<a href="{}">{}</a>', value.url, value)
> ...
> }}}
> There is no test case for the display_for_field function when a
> `FileField` object is passed. -->
> [https://github.com/django/django/blob/main/tests/admin_utils/tests.py
> admin_utils test code]
>
> When the `FileField` handling was added in the above function, I found
> that the test was conducted indirectly through the ModelAdmin
> readonly_fields attribute. -->
> [https://github.com/django/django/blob/main/tests/admin_widgets/tests.py#L654
> test code]
>
> However, I believe it would be better to have a direct test case for when
> a FileField is passed, considering that display_for_field function is
> globally accessible.

New description:

{{{
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
...
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
...
}}}
There is no test case for the display_for_field function when a
`FileField` object is passed. -->
[https://github.com/django/django/blob/main/tests/admin_utils/tests.py
admin_utils test code]

When the `FileField` handling was added in the above function, I found
that the test was conducted indirectly through the FileWidget readonly
attribute. -->
[https://github.com/django/django/blob/main/tests/admin_widgets/tests.py#L654
test code]

However, I believe it would be better to have a direct test case for when
a FileField is passed, considering that display_for_field function is
globally accessible.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36038#comment:2>

Django

unread,
Dec 25, 2024, 8:43:38 AM12/25/24
to django-...@googlegroups.com

Django

unread,
Dec 26, 2024, 10:45:00 AM12/26/24
to django-...@googlegroups.com
#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: display_for_field, | Triage Stage: Accepted
FileFIeld |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* component: Utilities => contrib.admin
* stage: Unreviewed => Accepted
* version: 5.1 => dev

Comment:

Thank you Antoliny! Missing tests are always welcomed.
--
Ticket URL: <https://code.djangoproject.com/ticket/36038#comment:4>

Django

unread,
Dec 26, 2024, 11:15:22 PM12/26/24
to django-...@googlegroups.com
#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: display_for_field, | Triage Stage: Accepted
FileFIeld |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Antoliny):

[https://github.com/django/django/pull/18974 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/36038#comment:5>

Django

unread,
Dec 26, 2024, 11:15:35 PM12/26/24
to django-...@googlegroups.com
#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: display_for_field, | Triage Stage: Accepted
FileFIeld |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36038#comment:6>

Django

unread,
Jan 2, 2025, 8:54:28 AM1/2/25
to django-...@googlegroups.com
#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: display_for_field, | Triage Stage: Accepted
FileFIeld |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce):

You're right that this is already covered by existing tests and this PR
would add double cover.
The existing assert is "strong" enough that changes to `display_for_field`
for FileField would make the existing test fail.
I would prefer we add tests where we are [https://djangoci.com/job/django-
coverage/HTML_20Coverage_20Report/ missing coverage] or in parallel with a
ticket for which the tests add value. Otherwise, it feels unnecessary
--
Ticket URL: <https://code.djangoproject.com/ticket/36038#comment:7>

Django

unread,
Jan 2, 2025, 9:00:07 AM1/2/25
to django-...@googlegroups.com
#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: display_for_field, | Triage Stage: Accepted
FileFIeld |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36038#comment:8>

Django

unread,
Jan 6, 2025, 3:37:34 AM1/6/25
to django-...@googlegroups.com
#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: display_for_field, | Triage Stage: Accepted
FileFIeld |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => wontfix
* status: assigned => closed

--
Ticket URL: <https://code.djangoproject.com/ticket/36038#comment:9>
Reply all
Reply to author
Forward
0 new messages