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/staticfiles_tests | |
parent | 367634f976ab43db93321bf4eb898449b670e291 (diff) | |
download | django-77aa74cb70dd85497dbade6bc0f394aa41e88c94.tar.gz |
Refs #29983 -- Added support for using pathlib.Path in all settings.
Diffstat (limited to 'tests/staticfiles_tests')
-rw-r--r-- | tests/staticfiles_tests/cases.py | 5 | ||||
-rw-r--r-- | tests/staticfiles_tests/project/pathlib/pathlib.txt | 1 | ||||
-rw-r--r-- | tests/staticfiles_tests/settings.py | 2 | ||||
-rw-r--r-- | tests/staticfiles_tests/test_management.py | 11 |
4 files changed, 18 insertions, 1 deletions
diff --git a/tests/staticfiles_tests/cases.py b/tests/staticfiles_tests/cases.py index 24de4e029e..4e767d9cb0 100644 --- a/tests/staticfiles_tests/cases.py +++ b/tests/staticfiles_tests/cases.py @@ -64,7 +64,7 @@ class CollectionTestCase(BaseStaticFilesMixin, SimpleTestCase): def setUp(self): super().setUp() - temp_dir = tempfile.mkdtemp() + temp_dir = self.mkdtemp() # Override the STATIC_ROOT for all tests from setUp to tearDown # rather than as a context manager self.patched_settings = self.settings(STATIC_ROOT=temp_dir) @@ -78,6 +78,9 @@ class CollectionTestCase(BaseStaticFilesMixin, SimpleTestCase): self.patched_settings.disable() super().tearDown() + def mkdtemp(self): + return tempfile.mkdtemp() + def run_collectstatic(self, *, verbosity=0, **kwargs): call_command('collectstatic', interactive=False, verbosity=verbosity, ignore_patterns=['*.ignoreme'], **kwargs) diff --git a/tests/staticfiles_tests/project/pathlib/pathlib.txt b/tests/staticfiles_tests/project/pathlib/pathlib.txt new file mode 100644 index 0000000000..c7709d3d41 --- /dev/null +++ b/tests/staticfiles_tests/project/pathlib/pathlib.txt @@ -0,0 +1 @@ +pathlib diff --git a/tests/staticfiles_tests/settings.py b/tests/staticfiles_tests/settings.py index 1320da7a0d..444450358f 100644 --- a/tests/staticfiles_tests/settings.py +++ b/tests/staticfiles_tests/settings.py @@ -1,4 +1,5 @@ import os.path +from pathlib import Path TEST_ROOT = os.path.dirname(__file__) @@ -10,6 +11,7 @@ TEST_SETTINGS = { 'STATICFILES_DIRS': [ os.path.join(TEST_ROOT, 'project', 'documents'), ('prefix', os.path.join(TEST_ROOT, 'project', 'prefixed')), + Path(TEST_ROOT) / 'project' / 'pathlib', ], 'STATICFILES_FINDERS': [ 'django.contrib.staticfiles.finders.FileSystemFinder', diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index 7630efbd9b..1236d533d3 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -4,6 +4,7 @@ import shutil import tempfile import unittest from io import StringIO +from pathlib import Path from unittest import mock from admin_scripts.tests import AdminScriptTestCase @@ -102,6 +103,7 @@ class TestFindStatic(TestDefaults, CollectionTestCase): # FileSystemFinder searched locations self.assertIn(TEST_SETTINGS['STATICFILES_DIRS'][1][1], searched_locations) self.assertIn(TEST_SETTINGS['STATICFILES_DIRS'][0], searched_locations) + self.assertIn(str(TEST_SETTINGS['STATICFILES_DIRS'][2]), searched_locations) # DefaultStorageFinder searched locations self.assertIn( os.path.join('staticfiles_tests', 'project', 'site_media', 'media'), @@ -174,6 +176,15 @@ class TestCollection(TestDefaults, CollectionTestCase): self.assertFileNotFound('test/backup~') self.assertFileNotFound('test/CVS') + def test_pathlib(self): + self.assertFileContains('pathlib.txt', 'pathlib') + + +class TestCollectionPathLib(TestCollection): + def mkdtemp(self): + tmp_dir = super().mkdtemp() + return Path(tmp_dir) + class TestCollectionVerbosity(CollectionTestCase): copying_msg = 'Copying ' |