Skip to content

Commit

Permalink
fix test_storage
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Jan 29, 2023
1 parent 783b716 commit 2441cb7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import tempfile
from posixpath import basename
from typing import Any

import django
import pytest
Expand All @@ -22,49 +23,50 @@

@pytest.fixture()
def setup():
staticfiles_storage._wrapped = empty
# stubs don't mark staticfiles_storage as a lazy object with _wrapped
staticfiles_storage._wrapped = empty # type: ignore [attr-defined]
files = Files("static")
tmp = tempfile.mkdtemp()
with override_settings(
STATICFILES_DIRS=[files.directory],
STATIC_ROOT=tmp,
):
yield settings
staticfiles_storage._wrapped = empty
staticfiles_storage._wrapped = empty # type: ignore [attr-defined]
shutil.rmtree(tmp)


@pytest.fixture()
def _compressed_storage(setup):
backend = "whitenoise.storage.CompressedStaticFilesStorage"
if django.VERSION >= (4, 2):
storages = {
overrides: dict[str, Any] = {
"STORAGES": {
**settings.STORAGES,
"staticfiles": {"BACKEND": backend},
}
}
else:
storages = {"STATICFILES_STORAGE": backend}
overrides = {"STATICFILES_STORAGE": backend}

with override_settings(**storages):
with override_settings(**overrides):
yield


@pytest.fixture()
def _compressed_manifest_storage(setup):
backend = "whitenoise.storage.CompressedManifestStaticFilesStorage"
if django.VERSION >= (4, 2):
storages = {
overrides: dict[str, Any] = {
"STORAGES": {
**settings.STORAGES,
"staticfiles": {"BACKEND": backend},
}
}
else:
storages = {"STATICFILES_STORAGE": backend}
overrides = {"STATICFILES_STORAGE": backend}

with override_settings(**storages, WHITENOISE_KEEP_ONLY_HASHED_FILES=True):
with override_settings(**overrides, WHITENOISE_KEEP_ONLY_HASHED_FILES=True):
call_command("collectstatic", verbosity=0, interactive=False)


Expand Down

0 comments on commit 2441cb7

Please sign in to comment.