diff --git a/tests/files/tests.py b/tests/files/tests.py index 1c005dde577..047c8935b82 100644 --- a/tests/files/tests.py +++ b/tests/files/tests.py @@ -5,6 +5,7 @@ import struct import tempfile import unittest from io import BytesIO, StringIO, TextIOWrapper +from pathlib import Path from unittest import mock from django.core.files import File @@ -15,6 +16,7 @@ from django.core.files.uploadedfile import ( InMemoryUploadedFile, SimpleUploadedFile, TemporaryUploadedFile, UploadedFile, ) +from django.test import override_settings try: from PIL import Image @@ -231,6 +233,12 @@ class TemporaryUploadedFileTests(unittest.TestCase): with TemporaryUploadedFile('test.txt', 'text/plain', 1, 'utf8') as temp_file: self.assertTrue(temp_file.file.name.endswith('.upload.txt')) + def test_file_upload_temp_dir_pathlib(self): + with tempfile.TemporaryDirectory() as tmp_dir: + with override_settings(FILE_UPLOAD_TEMP_DIR=Path(tmp_dir)): + with TemporaryUploadedFile('test.txt', 'text/plain', 1, 'utf-8') as temp_file: + self.assertTrue(os.path.exists(temp_file.file.name)) + class DimensionClosingBug(unittest.TestCase): """