mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #23600 -- Made default_storage aware of more settings changes.
Added MEDIA_URL, FILE_UPLOAD_PERMISSIONS, and FILE_UPLOAD_DIRECTORY_PERMISSIONS to the list of settings.
This commit is contained in:
parent
0af4ddabf4
commit
88b6cf4ae4
@ -112,7 +112,15 @@ def language_changed(**kwargs):
|
||||
|
||||
@receiver(setting_changed)
|
||||
def file_storage_changed(**kwargs):
|
||||
if kwargs['setting'] in ('MEDIA_ROOT', 'DEFAULT_FILE_STORAGE'):
|
||||
file_storage_settings = {
|
||||
'DEFAULT_FILE_STORAGE',
|
||||
'FILE_UPLOAD_DIRECTORY_PERMISSIONS',
|
||||
'FILE_UPLOAD_PERMISSIONS',
|
||||
'MEDIA_ROOT',
|
||||
'MEDIA_URL',
|
||||
}
|
||||
|
||||
if kwargs['setting'] in file_storage_settings:
|
||||
from django.core.files.storage import default_storage
|
||||
default_storage._wrapped = empty
|
||||
|
||||
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
||||
import unittest
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.core.files.storage import default_storage
|
||||
from django.core.urlresolvers import NoReverseMatch, reverse
|
||||
from django.db import connection
|
||||
from django.forms import EmailField, IntegerField
|
||||
@ -791,3 +792,41 @@ class OverrideSettingsTests(TestCase):
|
||||
|
||||
self.assertRaises(NoReverseMatch, lambda: reverse('first'))
|
||||
self.assertRaises(NoReverseMatch, lambda: reverse('second'))
|
||||
|
||||
def test_override_media_root(self):
|
||||
"""
|
||||
Overriding the MEDIA_ROOT setting should be reflected in the
|
||||
base_location attribute of django.core.files.storage.default_storage.
|
||||
"""
|
||||
self.assertEqual(default_storage.base_location, '')
|
||||
with self.settings(MEDIA_ROOT='test_value'):
|
||||
self.assertEqual(default_storage.base_location, 'test_value')
|
||||
|
||||
def test_override_media_url(self):
|
||||
"""
|
||||
Overriding the MEDIA_URL setting should be reflected in the
|
||||
base_url attribute of django.core.files.storage.default_storage.
|
||||
"""
|
||||
self.assertEqual(default_storage.base_location, '')
|
||||
with self.settings(MEDIA_URL='/test_value/'):
|
||||
self.assertEqual(default_storage.base_url, '/test_value/')
|
||||
|
||||
def test_override_file_upload_permissions(self):
|
||||
"""
|
||||
Overriding the FILE_UPLOAD_PERMISSIONS setting should be reflected in
|
||||
the file_permissions_mode attribute of
|
||||
django.core.files.storage.default_storage.
|
||||
"""
|
||||
self.assertIsNone(default_storage.file_permissions_mode)
|
||||
with self.settings(FILE_UPLOAD_PERMISSIONS=0o777):
|
||||
self.assertEqual(default_storage.file_permissions_mode, 0o777)
|
||||
|
||||
def test_override_file_upload_directory_permissions(self):
|
||||
"""
|
||||
Overriding the FILE_UPLOAD_DIRECTORY_PERMISSIONS setting should be
|
||||
reflected in the directory_permissions_mode attribute of
|
||||
django.core.files.storage.default_storage.
|
||||
"""
|
||||
self.assertIsNone(default_storage.directory_permissions_mode)
|
||||
with self.settings(FILE_UPLOAD_DIRECTORY_PERMISSIONS=0o777):
|
||||
self.assertEqual(default_storage.directory_permissions_mode, 0o777)
|
||||
|
Loading…
Reference in New Issue
Block a user