mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	[1.6.x] Reworked the detection of local storages for the collectstatic command.
Before4befb30the detection was broken because we used isinstance against a LazyObject rather than against a Storage class. That commit fixed it by looking directly at the object wrapped by LazyObject. This could however be a problem to anyone who subclasses the collectstatic management Command and directly supplies a Storage class. Refs #21581. Backport of7e27885c6efrom master.
This commit is contained in:
		| @@ -22,6 +22,9 @@ from django.utils import six | ||||
|  | ||||
| from django.contrib.staticfiles import finders, storage | ||||
|  | ||||
| from .storage import DummyStorage | ||||
|  | ||||
|  | ||||
| TEST_ROOT = os.path.dirname(upath(__file__)) | ||||
| TEST_SETTINGS = { | ||||
|     'DEBUG': True, | ||||
| @@ -233,6 +236,29 @@ class TestConfiguration(StaticFilesTestCase): | ||||
|                         'without having set the STATIC_ROOT setting to a filesystem path'): | ||||
|                     call_command('collectstatic', interactive=False, verbosity=0, stderr=err) | ||||
|  | ||||
|     def test_local_storage_detection_helper(self): | ||||
|         staticfiles_storage = storage.staticfiles_storage | ||||
|         try: | ||||
|             storage.staticfiles_storage._wrapped = empty | ||||
|             with override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage'): | ||||
|                 command = collectstatic.Command() | ||||
|                 self.assertTrue(command.is_local_storage()) | ||||
|  | ||||
|             storage.staticfiles_storage._wrapped = empty | ||||
|             with override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage'): | ||||
|                 command = collectstatic.Command() | ||||
|                 self.assertFalse(command.is_local_storage()) | ||||
|  | ||||
|             storage.staticfiles_storage = storage.FileSystemStorage() | ||||
|             command = collectstatic.Command() | ||||
|             self.assertTrue(command.is_local_storage()) | ||||
|  | ||||
|             storage.staticfiles_storage = DummyStorage() | ||||
|             command = collectstatic.Command() | ||||
|             self.assertFalse(command.is_local_storage()) | ||||
|         finally: | ||||
|             storage.staticfiles_storage = staticfiles_storage | ||||
|  | ||||
|  | ||||
| class TestCollection(CollectionTestCase, TestDefaults): | ||||
|     """ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user