From 77aa74cb70dd85497dbade6bc0f394aa41e88c94 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 7 Nov 2019 01:26:22 -0800 Subject: Refs #29983 -- Added support for using pathlib.Path in all settings. --- tests/model_fields/test_filefield.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/model_fields') diff --git a/tests/model_fields/test_filefield.py b/tests/model_fields/test_filefield.py index 9642e7e80b..8150260476 100644 --- a/tests/model_fields/test_filefield.py +++ b/tests/model_fields/test_filefield.py @@ -1,6 +1,8 @@ import os import sys +import tempfile import unittest +from pathlib import Path from django.core.files import temp from django.core.files.base import ContentFile @@ -94,3 +96,10 @@ class FileFieldTests(TestCase): # open() doesn't write to disk. d.myfile.file = ContentFile(b'', name='bla') self.assertEqual(d.myfile, d.myfile.open()) + + def test_media_root_pathlib(self): + with tempfile.TemporaryDirectory() as tmp_dir: + with override_settings(MEDIA_ROOT=Path(tmp_dir)): + with TemporaryUploadedFile('foo.txt', 'text/plain', 1, 'utf-8') as tmp_file: + Document.objects.create(myfile=tmp_file) + self.assertTrue(os.path.exists(os.path.join(tmp_dir, 'unused', 'foo.txt'))) -- cgit v1.3