diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-11-07 01:26:22 -0800 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2019-11-07 10:26:22 +0100 |
| commit | 77aa74cb70dd85497dbade6bc0f394aa41e88c94 (patch) | |
| tree | f526b5e63897415e8753c6e38396bba535e3fc75 /tests/model_fields | |
| parent | 367634f976ab43db93321bf4eb898449b670e291 (diff) | |
Refs #29983 -- Added support for using pathlib.Path in all settings.
Diffstat (limited to 'tests/model_fields')
| -rw-r--r-- | tests/model_fields/test_filefield.py | 9 |
1 files changed, 9 insertions, 0 deletions
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'))) |
