test_browsing_theme_assets.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import pytest
  2. from django.urls import reverse
  3. from ....test import assert_contains, assert_not_contains, assert_has_error_message
  4. @pytest.fixture
  5. def assets_client(admin_client):
  6. def get_theme_assets(theme):
  7. url = reverse("misago:admin:appearance:themes:assets", kwargs={"pk": theme.pk})
  8. return admin_client.get(url)
  9. return get_theme_assets
  10. def test_theme_assets_list_is_displayed(assets_client, theme):
  11. response = assets_client(theme)
  12. assert_contains(response, theme.name)
  13. def test_css_is_displayed_on_theme_asset_list(assets_client, theme, css):
  14. response = assets_client(theme)
  15. assert_contains(response, css.name)
  16. def test_media_is_displayed_on_themes_asset_list(assets_client, theme, media):
  17. response = assets_client(theme)
  18. assert_contains(response, media.name)
  19. def test_image_is_displayed_on_themes_asset_list(assets_client, theme, image):
  20. response = assets_client(theme)
  21. assert_contains(response, image.name)
  22. def test_image_thumbnail_is_displayed_on_themes_asset_list(assets_client, theme, image):
  23. response = assets_client(theme)
  24. assert_contains(response, image.thumbnail.url)
  25. def test_other_theme_assets_are_not_displayed(
  26. assets_client, other_theme, css, media, image
  27. ):
  28. response = assets_client(other_theme)
  29. assert_not_contains(response, css.name)
  30. assert_not_contains(response, media.name)
  31. assert_not_contains(response, image.name)
  32. def test_user_is_redirected_away_with_message_from_default_theme_assets_list(
  33. assets_client, default_theme
  34. ):
  35. response = assets_client(default_theme)
  36. assert response.status_code == 302
  37. assert_has_error_message(response)
  38. def test_user_is_redirected_away_with_message_from_nonexisting_theme(
  39. assets_client, nonexisting_theme
  40. ):
  41. response = assets_client(nonexisting_theme)
  42. assert response.status_code == 302
  43. assert_has_error_message(response)