1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 04:06:47 +00:00

fix(static): collectstatic writes to staticfiles/, and its output is no longer committed

This commit is contained in:
catborise 2026-10-07 16:05:16 +03:00
parent 841c412f76
commit 7639d21ec4
134 changed files with 52 additions and 11155 deletions

View file

@ -1,7 +1,7 @@
"""
Django dev settings for webvirtcloud project.
HowTo: python3 manage.py runserver 0:8000 --settings=webvirtcloud.settings-dev --nostatic
HowTo: python3 manage.py runserver 0:8000 --settings=webvirtcloud.settings-dev
"""

View file

@ -192,7 +192,10 @@ USE_TZ = True
STATIC_URL = "/static/"
STATIC_ROOT = Path.joinpath(BASE_DIR, "static")
# Source assets live in static/; collectstatic gathers them with the apps'
# assets into staticfiles/ (gitignored), which WhiteNoise and nginx serve.
STATICFILES_DIRS = [BASE_DIR / "static"]
STATIC_ROOT = BASE_DIR / "staticfiles"
BS_ICONS_CACHE = Path.joinpath(BASE_DIR, 'static/icon_cache')

View file

@ -0,0 +1,31 @@
"""Source assets live in static/; collectstatic gathers them with the apps'
assets into STATIC_ROOT, outside the source tree."""
import tempfile
from pathlib import Path
from django.conf import settings
from django.contrib.staticfiles import finders
from django.core.management import call_command
from django.test import SimpleTestCase, override_settings
SOURCE = Path(settings.BASE_DIR) / "static"
class StaticFilesTestCase(SimpleTestCase):
def test_static_root_is_not_the_source_dir(self):
self.assertNotEqual(Path(settings.STATIC_ROOT).resolve(), SOURCE.resolve())
self.assertIn(SOURCE, [Path(d) for d in settings.STATICFILES_DIRS])
def test_no_collected_files_in_the_source_dir(self):
for byproduct in ("staticfiles.json", "rest_framework", "bootstrap_icons"):
self.assertFalse((SOURCE / byproduct).exists(), byproduct)
self.assertEqual(list(SOURCE.rglob("*.gz")), [])
def test_collectstatic_gathers_source_and_app_assets(self):
with tempfile.TemporaryDirectory() as root, override_settings(STATIC_ROOT=root):
call_command("collectstatic", "--noinput", verbosity=0)
for name in ("css/webvirtcloud.css", "rest_framework/css/bootstrap.min.css",
"bootstrap_icons/css/bootstrap_icons.css"):
self.assertTrue((Path(root) / name).exists(), name)
self.assertIsNotNone(finders.find("css/webvirtcloud.css"))