mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
A theme change compiled Bootswatch with libsass (34 MB, upstream deprecated) into two tracked files, which updates, rollbacks and new Docker containers then reset. The 27 themes now ship as static/css/themes/<theme>.min.css, built by "manage.py build_themes"; the Settings page only saves the theme name and every page links that file (zephyr when no settings are in context, as on the 500 page). libsass moves to dev/requirements.txt; a test checks that each shipped file is its theme compiled from dev/scss. The "Theme SASS Path" setting is removed, and the theme default "flaty", a typo that never applied, becomes zephyr, the theme those installs showed. The update and rollback steps restore an older version's rewritten theme files only where they are modified.
30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
"""The settings page picks one of the prebuilt themes in static/css/themes;
|
|
every page links the chosen theme's file."""
|
|
|
|
from appsettings.models import AppSettings
|
|
from django.contrib.auth.models import User
|
|
from django.test import TestCase
|
|
from django.urls import reverse
|
|
from lxml import html
|
|
|
|
|
|
class ThemeNameTests(TestCase):
|
|
def setUp(self):
|
|
self.client.force_login(User.objects.create_superuser("th-admin", "th@example.com", "pw"))
|
|
self.before = AppSettings.objects.get(key="BOOTSTRAP_THEME").value
|
|
|
|
def theme_link(self, url):
|
|
(href,) = html.fromstring(self.client.get(url).content).xpath("//link[@id='wvc_css']/@href")
|
|
return href
|
|
|
|
def test_a_name_that_is_not_a_theme_is_refused(self):
|
|
for theme in ("../../etc", "flatly.min.css", "nope", ""):
|
|
with self.subTest(theme=theme):
|
|
self.client.post(reverse("appsettings"), {"BOOTSTRAP_THEME": theme})
|
|
self.assertEqual(AppSettings.objects.get(key="BOOTSTRAP_THEME").value, self.before)
|
|
|
|
def test_pages_link_the_chosen_theme(self):
|
|
self.assertEqual(self.theme_link(reverse("appsettings")), "/static/css/themes/zephyr.min.css")
|
|
self.client.post(reverse("appsettings"), {"BOOTSTRAP_THEME": "flatly"})
|
|
self.assertEqual(AppSettings.objects.get(key="BOOTSTRAP_THEME").value, "flatly")
|
|
self.assertEqual(self.theme_link(reverse("appsettings")), "/static/css/themes/flatly.min.css")
|