Fix: better handle favicon with static dir (#10107)

This commit is contained in:
shamoon
2025-06-03 08:05:59 -07:00
committed by GitHub
parent 1512599f4f
commit 4e082f997c
3 changed files with 34 additions and 15 deletions

View File

@@ -0,0 +1,25 @@
import tempfile
from pathlib import Path
from django.conf import settings
def test_favicon_view(client):
with tempfile.TemporaryDirectory() as tmpdir:
static_dir = Path(tmpdir)
favicon_path = static_dir / "paperless" / "img" / "favicon.ico"
favicon_path.parent.mkdir(parents=True, exist_ok=True)
favicon_path.write_bytes(b"FAKE ICON DATA")
settings.STATIC_ROOT = static_dir
response = client.get("/favicon.ico")
assert response.status_code == 200
assert response["Content-Type"] == "image/x-icon"
assert b"".join(response.streaming_content) == b"FAKE ICON DATA"
def test_favicon_view_missing_file(client):
settings.STATIC_ROOT = Path(tempfile.mkdtemp())
response = client.get("/favicon.ico")
assert response.status_code == 404