From 88b6cf4ae41a983bda735a5f61f69f6b1482e2ca Mon Sep 17 00:00:00 2001 From: Duncan Parkes Date: Sat, 4 Oct 2014 12:02:10 +0100 Subject: [PATCH] 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. --- django/test/signals.py | 10 +++++++++- tests/test_utils/tests.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/django/test/signals.py b/django/test/signals.py index dd88389d62..0f9c5b1fa1 100644 --- a/django/test/signals.py +++ b/django/test/signals.py @@ -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 diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index ef3114cd16..ead688dcef 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -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)