test_changing_active_theme.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import pytest
  2. from django.urls import reverse
  3. from ....cache.test import assert_invalidates_cache
  4. from ....test import assert_has_error_message
  5. from ... import THEME_CACHE
  6. from ...models import Theme
  7. @pytest.fixture
  8. def activate_link(theme):
  9. return reverse("misago:admin:appearance:themes:activate", kwargs={"pk": theme.pk})
  10. def test_active_theme_can_changed(admin_client, activate_link, theme):
  11. admin_client.post(activate_link)
  12. theme.refresh_from_db()
  13. assert theme.is_active
  14. def test_default_theme_can_be_set_as_active_theme(admin_client, default_theme):
  15. activate_link = reverse(
  16. "misago:admin:appearance:themes:activate", kwargs={"pk": default_theme.pk}
  17. )
  18. admin_client.post(activate_link)
  19. default_theme.refresh_from_db()
  20. assert default_theme.is_active
  21. def test_changing_active_theme_removes_active_status_from_previous_active_theme(
  22. admin_client, activate_link, theme
  23. ):
  24. admin_client.post(activate_link)
  25. # objets.get() will raise if more than one theme is active
  26. assert Theme.objects.get(is_active=True) == theme
  27. def test_changing_active_theme_to_nonexisting_theme_sets_error_message(
  28. admin_client, nonexisting_theme
  29. ):
  30. activate_link = reverse(
  31. "misago:admin:appearance:themes:activate", kwargs={"pk": nonexisting_theme.pk}
  32. )
  33. response = admin_client.post(activate_link)
  34. assert_has_error_message(response)
  35. def test_changing_active_theme_invalidates_themes_cache(admin_client, activate_link):
  36. with assert_invalidates_cache(THEME_CACHE):
  37. admin_client.post(activate_link)