Skip to content

Commit

Permalink
Merge pull request #194 from felixxm/was_modified_since_size
Browse files Browse the repository at this point in the history
Removed passing unused size parameter to was_modified_since().
  • Loading branch information
Natim authored Aug 5, 2022
2 parents df439fb + 293403b commit 338e171
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 4 additions & 5 deletions django_downloadview/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def was_modified_since(self, file_instance, since):
Else, fallbacks to default implementation, which uses
:py:func:`django.views.static.was_modified_since`.
Django's ``was_modified_since`` function needs a datetime and a size.
It is passed ``modified_time`` and ``size`` attributes from file
wrapper. If file wrapper does not support these attributes
Django's ``was_modified_since`` function needs a datetime.
It is passed the ``modified_time`` attribute from file
wrapper. If file wrapper does not support this attribute
(``AttributeError`` or ``NotImplementedError`` is raised), then
the file is considered as modified and ``True`` is returned.
Expand All @@ -116,12 +116,11 @@ def was_modified_since(self, file_instance, since):
modification_time = calendar.timegm(
file_instance.modified_time.utctimetuple()
)
size = file_instance.size
except (AttributeError, NotImplementedError) as e:
print("!=======!", e)
return True
else:
return was_modified_since(since, modification_time, size)
return was_modified_since(since, modification_time)

def not_modified_response(self, *response_args, **response_kwargs):
"""Return :class:`django.http.HttpResponseNotModified` instance."""
Expand Down
6 changes: 2 additions & 4 deletions tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ def test_was_modified_since_django(self):
When calling file wrapper's ``was_modified_since()`` raises
``NotImplementedError`` or ``AttributeError``,
:meth:`django_downloadview.views.base.DownloadMixin.was_modified_since`
tries to pass file wrapper's ``size`` and ``modified_time`` to
tries to pass file wrapper's ``modified_time`` to
:func:`django.views.static import was_modified_since`.
"""
file_wrapper = mock.Mock()
file_wrapper.was_modified_since = mock.Mock(side_effect=AttributeError)
file_wrapper.size = mock.sentinel.size
file_wrapper.modified_time = datetime.now()
was_modified_since_mock = mock.Mock(return_value=mock.sentinel.was_modified)
mixin = views.DownloadMixin()
Expand All @@ -106,7 +105,6 @@ def test_was_modified_since_django(self):
was_modified_since_mock.assert_called_once_with(
mock.sentinel.since,
calendar.timegm(file_wrapper.modified_time.utctimetuple()),
mock.sentinel.size,
)

def test_was_modified_since_fallback(self):
Expand All @@ -117,7 +115,7 @@ def test_was_modified_since_fallback(self):
* calling file wrapper's ``was_modified_since()`` raises
``NotImplementedError`` or ``AttributeError``;
* and accessing ``size`` and ``modified_time`` from file wrapper raises
* and accessing ``modified_time`` from file wrapper raises
``NotImplementedError`` or ``AttributeError``...
... then
Expand Down

0 comments on commit 338e171

Please sign in to comment.