diff options
| author | Vajrasky Kok <sky.kok@speaklikeaking.com> | 2013-11-05 18:02:54 +0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-11-29 08:01:30 -0500 |
| commit | 7e2d61a9724644d6d1c7ce9361d9fd5be3e2ab86 (patch) | |
| tree | 294d13ea68cd5125832407619ad07056494675d1 /tests | |
| parent | 42ac13800952e74e3969b850fa635b400948c5ee (diff) | |
Fixed #21380 -- Added a way to set different permission for static directories.
Previously when collecting static files, the directories would receive permissions
from the global umask. Now the default permission comes from FILE_UPLOAD_DIRECTORY_PERMISSIONS
and there's an option to specify the permissions by subclassing any of the
static files storage classes and setting the directory_permissions_mode parameter.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/staticfiles_tests/tests.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py index 39ce49817c..e7c1383373 100644 --- a/tests/staticfiles_tests/tests.py +++ b/tests/staticfiles_tests/tests.py @@ -823,6 +823,7 @@ class CustomStaticFilesStorage(storage.StaticFilesStorage): """ def __init__(self, *args, **kwargs): kwargs['file_permissions_mode'] = 0o640 + kwargs['directory_permissions_mode'] = 0o740 super(CustomStaticFilesStorage, self).__init__(*args, **kwargs) @@ -839,21 +840,49 @@ class TestStaticFilePermissions(BaseCollectionTestCase, StaticFilesTestCase): 'link': False, 'dry_run': False} + def setUp(self): + self.umask = 0o027 + self.old_umask = os.umask(self.umask) + super(TestStaticFilePermissions, self).setUp() + + def tearDown(self): + os.umask(self.old_umask) + super(TestStaticFilePermissions, self).tearDown() + # Don't run collectstatic command in this test class. def run_collectstatic(self, **kwargs): pass - @override_settings(FILE_UPLOAD_PERMISSIONS=0o655) - def test_collect_static_files_default_permissions(self): + @override_settings(FILE_UPLOAD_PERMISSIONS=0o655, + FILE_UPLOAD_DIRECTORY_PERMISSIONS=0o765) + def test_collect_static_files_permissions(self): collectstatic.Command().execute(**self.command_params) test_file = os.path.join(settings.STATIC_ROOT, "test.txt") + test_dir = os.path.join(settings.STATIC_ROOT, "subdir") file_mode = os.stat(test_file)[0] & 0o777 + dir_mode = os.stat(test_dir)[0] & 0o777 self.assertEqual(file_mode, 0o655) + self.assertEqual(dir_mode, 0o765) + + @override_settings(FILE_UPLOAD_PERMISSIONS=None, + FILE_UPLOAD_DIRECTORY_PERMISSIONS=None) + def test_collect_static_files_default_permissions(self): + collectstatic.Command().execute(**self.command_params) + test_file = os.path.join(settings.STATIC_ROOT, "test.txt") + test_dir = os.path.join(settings.STATIC_ROOT, "subdir") + file_mode = os.stat(test_file)[0] & 0o777 + dir_mode = os.stat(test_dir)[0] & 0o777 + self.assertEqual(file_mode, 0o666 & ~self.umask) + self.assertEqual(dir_mode, 0o777 & ~self.umask) @override_settings(FILE_UPLOAD_PERMISSIONS=0o655, + FILE_UPLOAD_DIRECTORY_PERMISSIONS=0o765, STATICFILES_STORAGE='staticfiles_tests.tests.CustomStaticFilesStorage') def test_collect_static_files_subclass_of_static_storage(self): collectstatic.Command().execute(**self.command_params) test_file = os.path.join(settings.STATIC_ROOT, "test.txt") + test_dir = os.path.join(settings.STATIC_ROOT, "subdir") file_mode = os.stat(test_file)[0] & 0o777 + dir_mode = os.stat(test_dir)[0] & 0o777 self.assertEqual(file_mode, 0o640) + self.assertEqual(dir_mode, 0o740) |
