From 1c4c68dfed289093aaa2baf86bac7826c91e59ce Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Tue, 5 Nov 2019 23:20:23 -0800 Subject: [PATCH] Refs #29983 -- Added test for FILE_UPLOAD_TEMP_DIR pathlib support. --- tests/files/tests.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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): """