diff options
author | Claude Paroz <claude@2xlibre.net> | 2019-08-18 11:10:49 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-08-18 20:34:54 +0200 |
commit | af69842dbd98e69519f1263eca2619c3165ba13b (patch) | |
tree | 865dd1993b1aa271d5ea40889258d911e943a207 /tests/file_storage | |
parent | 04681597634a0c803246fe68b3bcb64f81e7305c (diff) | |
download | django-af69842dbd98e69519f1263eca2619c3165ba13b.tar.gz |
Refs #28428 -- Added test for a callable FileField.upload_to that returns pathlib.Path.
Diffstat (limited to 'tests/file_storage')
-rw-r--r-- | tests/file_storage/models.py | 5 | ||||
-rw-r--r-- | tests/file_storage/tests.py | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/tests/file_storage/models.py b/tests/file_storage/models.py index 38675a6673..96805f6ad5 100644 --- a/tests/file_storage/models.py +++ b/tests/file_storage/models.py @@ -7,6 +7,7 @@ and where files should be stored. import random import tempfile +from pathlib import Path from django.core.files.storage import FileSystemStorage from django.db import models @@ -31,8 +32,12 @@ class Storage(models.Model): # to make sure it only gets called once. return '%s/%s' % (random.randint(100, 999), filename) + def pathlib_upload_to(self, filename): + return Path('bar') / filename + normal = models.FileField(storage=temp_storage, upload_to='tests') custom = models.FileField(storage=temp_storage, upload_to=custom_upload_to) + pathlib_callable = models.FileField(storage=temp_storage, upload_to=pathlib_upload_to) random = models.FileField(storage=temp_storage, upload_to=random_upload_to) custom_valid_name = models.FileField( storage=CustomValidNameStorage(location=temp_storage_location), diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index 892d4129a5..6edfd2902c 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -792,6 +792,12 @@ class FileFieldStorageTests(TestCase): self.assertEqual(obj.empty.read(), b"more content") obj.empty.close() + def test_pathlib_upload_to(self): + obj = Storage() + obj.pathlib_callable.save('some_file1.txt', ContentFile('some content')) + self.assertEqual(obj.pathlib_callable.name, 'bar/some_file1.txt') + obj.random.close() + def test_random_upload_to(self): # Verify the fix for #5655, making sure the directory is only # determined once. |