diff options
| author | Simon Charette <charette.s@gmail.com> | 2016-01-06 23:34:55 -0500 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2016-01-07 12:04:39 -0500 |
| commit | 56c461a0d7c1cbb9d5709bda817579c7ee18d474 (patch) | |
| tree | 7174f775f36a6c3406c4cf8f1432e84224aabb70 /tests | |
| parent | 6ea7b6776c79b7a30b32c4f0c1f2658bc49dfe6c (diff) | |
Fixed #26038 -- Changed FileSystemStorage defaults on setting change.
Thanks to Dave Voutila for the report and Tim for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/file_storage/tests.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index 6b02073bbf..25c6161d5e 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -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): |
