-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor how we get the default storage class
- Loading branch information
Showing
6 changed files
with
125 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import django | ||
from django.test import override_settings | ||
import pytest | ||
from imagekit.utils import get_storage | ||
|
||
|
||
def test_get_storage_default(): | ||
from django.core.files.storage import default_storage | ||
|
||
if django.VERSION >= (4, 2): | ||
assert get_storage() == default_storage | ||
else: | ||
assert isinstance(get_storage(), type(default_storage._wrapped)) | ||
|
||
|
||
@pytest.mark.skipif( | ||
django.VERSION >= (5, 1), | ||
reason="DEFAULT_FILE_STORAGE is removed in Django 5.1.", | ||
) | ||
def test_get_storage_custom_import_path(): | ||
from tests.utils import CustomStorage | ||
|
||
with override_settings(IMAGEKIT_DEFAULT_FILE_STORAGE="tests.utils.CustomStorage"): | ||
assert isinstance(get_storage(), CustomStorage) | ||
|
||
|
||
@pytest.mark.skipif( | ||
django.VERSION < (4, 2), | ||
reason="STORAGES was introduced in Django 4.2", | ||
) | ||
def test_get_storage_custom_key(): | ||
from tests.utils import CustomStorage | ||
|
||
with override_settings( | ||
STORAGES={ | ||
"custom": { | ||
"BACKEND": "tests.utils.CustomStorage", | ||
} | ||
}, | ||
IMAGEKIT_DEFAULT_FILE_STORAGE="custom", | ||
): | ||
assert isinstance(get_storage(), CustomStorage) |