new FT test_theme for theme switcher functionality; theme-switcher content added to home.html, several dashboard views & urls, all appropriate ITs & UTs; lyric user model saves theme (migrations run); django-compressor and django-libsass libraries added to dependencies
This commit is contained in:
@@ -255,3 +255,50 @@ class ViewAuthListTest(TestCase):
|
||||
self.client.force_login(guest)
|
||||
response = self.client.get(reverse("view_list", args=[self.our_list.id]))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
class SetThemeTest(TestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create(email="a@b.cde")
|
||||
self.client.force_login(self.user)
|
||||
self.url = reverse("home")
|
||||
|
||||
def test_anonymous_user_is_redirected_home(self):
|
||||
response = self.client.post("/dashboard/set_theme")
|
||||
self.assertRedirects(response, "/")
|
||||
|
||||
def test_set_theme_updates_user_theme(self):
|
||||
User.objects.filter(pk=self.user.pk).update(theme="theme-sheol")
|
||||
self.client.post("/dashboard/set_theme", data={"theme": "theme-default"})
|
||||
self.user.refresh_from_db()
|
||||
self.assertEqual(self.user.theme, "theme-default")
|
||||
|
||||
def test_locked_theme_is_rejected(self):
|
||||
response = self.client.post("/dashboard/set_theme", data={"theme": "theme-nirvana"})
|
||||
self.user.refresh_from_db()
|
||||
self.assertEqual(self.user.theme, "theme-default")
|
||||
self.assertRedirects(response, "/")
|
||||
|
||||
def test_set_theme_redirects_home(self):
|
||||
response = self.client.post("/dashboard/set_theme", data={"theme": "theme-default"})
|
||||
self.assertRedirects(response, "/")
|
||||
|
||||
def test_my_lists_contains_set_theme_form(self):
|
||||
response = self.client.get(self.url)
|
||||
parsed = lxml.html.fromstring(response.content)
|
||||
forms = parsed.cssselect('form[action="/dashboard/set_theme"]')
|
||||
self.assertEqual(len(forms), 1)
|
||||
|
||||
def test_active_theme_swatch_has_active_class(self):
|
||||
response = self.client.get(self.url)
|
||||
parsed = lxml.html.fromstring(response.content)
|
||||
[active] = parsed.cssselect(".swatch.active")
|
||||
self.assertIn("theme-default", active.classes)
|
||||
|
||||
def test_locked_themes_are_not_forms(self):
|
||||
response = self.client.get(self.url)
|
||||
parsed = lxml.html.fromstring(response.content)
|
||||
locked = parsed.cssselect(".swatch.locked")
|
||||
self.assertEqual(len(locked), 2)
|
||||
# they mustn't be button els
|
||||
for swatch in locked:
|
||||
self.assertNotEqual(swatch.tag, "button")
|
||||
|
||||
@@ -6,4 +6,5 @@ urlpatterns = [
|
||||
path('list/<uuid:list_id>/', views.view_list, name='view_list'),
|
||||
path('users/<uuid:user_id>/', views.my_lists, name='my_lists'),
|
||||
path('list/<uuid:list_id>/share_list', views.share_list, name="share_list"),
|
||||
path('set_theme', views.set_theme, name='set_theme'),
|
||||
]
|
||||
|
||||
@@ -7,6 +7,9 @@ from .models import Item, List
|
||||
from apps.lyric.models import User
|
||||
|
||||
|
||||
UNLOCKED_THEMES = frozenset(["theme-default"])
|
||||
|
||||
|
||||
def home_page(request):
|
||||
return render(request, "apps/dashboard/home.html", {"form": ItemForm()})
|
||||
|
||||
@@ -59,3 +62,13 @@ def share_list(request, list_id):
|
||||
pass
|
||||
messages.success(request, "An invite has been sent if that address is registered.")
|
||||
return redirect(our_list)
|
||||
|
||||
def set_theme(request):
|
||||
if not request.user.is_authenticated:
|
||||
return redirect("home")
|
||||
if request.method == "POST":
|
||||
theme = request.POST.get("theme", "")
|
||||
if theme in UNLOCKED_THEMES:
|
||||
request.user.theme = theme
|
||||
request.user.save(update_fields=["theme"])
|
||||
return redirect("home")
|
||||
|
||||
Reference in New Issue
Block a user