Skip to content

Commit d908d4d

Browse files
Fix tests (#799)
* chore: added libavif-dev to build the pillow-avif-plugin wheel * feat: make ruff happy * chore: fixes timezone aware dates * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent eb17128 commit d908d4d

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install system dependencies
2323
run: |
2424
sudo apt-get update
25-
sudo apt-get install imagemagick libgraphicsmagick1-dev graphicsmagick libjpeg62 zlib1g-dev
25+
sudo apt-get install imagemagick libgraphicsmagick1-dev graphicsmagick libjpeg62 zlib1g-dev libavif-dev
2626
2727
- name: Set up Python ${{ matrix.python-version }}
2828
uses: actions/setup-python@v5

sorl/thumbnail/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django import forms
22
from django.db import models
3-
from django.utils.translation import gettext_lazy as _
43
from django.forms.widgets import FileInput
4+
from django.utils.translation import gettext_lazy as _
55

66
from sorl.thumbnail import default
77

sorl/thumbnail/kvstores/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import warnings
22

3+
from django.utils import timezone
4+
35
from sorl.thumbnail.conf import settings
46
from sorl.thumbnail.helpers import ThumbnailError, deserialize, serialize
57
from sorl.thumbnail.images import deserialize_image_file, serialize_image_file
@@ -100,6 +102,11 @@ def delete_all_thumbnail_files(self, older_than=None):
100102
if thumbnail:
101103
if older_than is not None:
102104
created_time = thumbnail.storage.get_created_time(thumbnail.name)
105+
# Make created_time timezone-aware if it's naive
106+
if timezone.is_naive(created_time):
107+
created_time = timezone.make_aware(created_time)
108+
if timezone.is_naive(older_than):
109+
older_than = timezone.make_aware(older_than)
103110
if created_time > older_than:
104111
continue
105112
thumbnail.delete()

sorl/thumbnail/management/commands/thumbnail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def handle(self, *labels, **options):
4747
duration = parse_duration(options['timeout'])
4848
if not duration:
4949
raise CommandError(f"Unable to parse '{options['timeout']}' as a duration")
50-
seconds = duration.seconds
50+
seconds = int(duration.total_seconds())
5151
timeout_date = timezone.now() - timedelta(seconds=seconds)
5252
if verbosity >= 1:
5353
msg = "Delete all thumbnail files referenced in Key Value Store"

tests/thumbnail_tests/test_formfields.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django import forms
2-
from django.test import SimpleTestCase
32
from django.forms.widgets import FileInput
3+
from django.test import SimpleTestCase
44

55
from sorl.thumbnail.fields import ImageFormField
66

@@ -15,4 +15,7 @@ class Form(forms.Form):
1515
def test_widget_attrs_default_accept(self):
1616
f = ImageFormField()
1717
self.assertEqual(f.widget_attrs(FileInput()), {'accept': 'image/*'})
18-
self.assertWidgetRendersTo(f, '<input type="file" name="f" accept="image/*" required id="id_f" />')
18+
self.assertWidgetRendersTo(
19+
f,
20+
'<input type="file" name="f" accept="image/*" required id="id_f" />'
21+
)

0 commit comments

Comments
 (0)