mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #26038 -- Changed FileSystemStorage defaults on setting change.
Thanks to Dave Voutila for the report and Tim for the review.
This commit is contained in:
parent
6ea7b6776c
commit
56c461a0d7
3 changed files with 84 additions and 28 deletions
|
@ -83,7 +83,7 @@ class FileStorageDeconstructionTests(unittest.TestCase):
|
|||
self.assertEqual(kwargs, kwargs_orig)
|
||||
|
||||
|
||||
class FileStorageTests(unittest.TestCase):
|
||||
class FileStorageTests(SimpleTestCase):
|
||||
storage_class = FileSystemStorage
|
||||
|
||||
def setUp(self):
|
||||
|
@ -403,6 +403,44 @@ class FileStorageTests(unittest.TestCase):
|
|||
with self.assertRaises(AssertionError):
|
||||
self.storage.delete('')
|
||||
|
||||
@override_settings(
|
||||
MEDIA_ROOT='media_root',
|
||||
MEDIA_URL='media_url/',
|
||||
FILE_UPLOAD_PERMISSIONS=0o777,
|
||||
FILE_UPLOAD_DIRECTORY_PERMISSIONS=0o777,
|
||||
)
|
||||
def test_setting_changed(self):
|
||||
"""
|
||||
Properties using settings values as defaults should be updated on
|
||||
referenced settings change while specified values should be unchanged.
|
||||
"""
|
||||
storage = self.storage_class(
|
||||
location='explicit_location',
|
||||
base_url='explicit_base_url/',
|
||||
file_permissions_mode=0o666,
|
||||
directory_permissions_mode=0o666,
|
||||
)
|
||||
defaults_storage = self.storage_class()
|
||||
settings = {
|
||||
'MEDIA_ROOT': 'overriden_media_root',
|
||||
'MEDIA_URL': 'overriden_media_url/',
|
||||
'FILE_UPLOAD_PERMISSIONS': 0o333,
|
||||
'FILE_UPLOAD_DIRECTORY_PERMISSIONS': 0o333,
|
||||
}
|
||||
with self.settings(**settings):
|
||||
self.assertEqual(storage.base_location, 'explicit_location')
|
||||
self.assertIn('explicit_location', storage.location)
|
||||
self.assertEqual(storage.base_url, 'explicit_base_url/')
|
||||
self.assertEqual(storage.file_permissions_mode, 0o666)
|
||||
self.assertEqual(storage.directory_permissions_mode, 0o666)
|
||||
self.assertEqual(defaults_storage.base_location, settings['MEDIA_ROOT'])
|
||||
self.assertIn(settings['MEDIA_ROOT'], defaults_storage.location)
|
||||
self.assertEqual(defaults_storage.base_url, settings['MEDIA_URL'])
|
||||
self.assertEqual(defaults_storage.file_permissions_mode, settings['FILE_UPLOAD_PERMISSIONS'])
|
||||
self.assertEqual(
|
||||
defaults_storage.directory_permissions_mode, settings['FILE_UPLOAD_DIRECTORY_PERMISSIONS']
|
||||
)
|
||||
|
||||
|
||||
class CustomStorage(FileSystemStorage):
|
||||
def get_available_name(self, name, max_length=None):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue