test_browsing_theme_assets.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_file_is_displayed_on_theme_asset_list(assets_client, theme, css):
  14. response = assets_client(theme)
  15. assert_contains(response, css.name)
  16. def test_css_link_is_displayed_on_theme_asset_list(assets_client, theme, css_link):
  17. response = assets_client(theme)
  18. assert_contains(response, css_link.name)
  19. def test_media_is_displayed_on_themes_asset_list(assets_client, theme, media):
  20. response = assets_client(theme)
  21. assert_contains(response, media.name)
  22. def test_image_is_displayed_on_themes_asset_list(assets_client, theme, image):
  23. response = assets_client(theme)
  24. assert_contains(response, image.name)
  25. def test_image_thumbnail_is_displayed_on_themes_asset_list(assets_client, theme, image):
  26. response = assets_client(theme)
  27. assert_contains(response, image.thumbnail.url)
  28. def test_other_theme_assets_are_not_displayed(
  29. assets_client, other_theme, css, css_link, media, image
  30. ):
  31. response = assets_client(other_theme)
  32. assert_not_contains(response, css.name)
  33. assert_not_contains(response, css_link.name)
  34. assert_not_contains(response, media.name)
  35. assert_not_contains(response, image.name)
  36. def test_user_is_redirected_away_with_message_from_default_theme_assets_list(
  37. assets_client, default_theme
  38. ):
  39. response = assets_client(default_theme)
  40. assert response.status_code == 302
  41. assert_has_error_message(response)
  42. def test_user_is_redirected_away_with_message_from_nonexisting_theme(
  43. assets_client, nonexisting_theme
  44. ):
  45. response = assets_client(nonexisting_theme)
  46. assert response.status_code == 302
  47. assert_has_error_message(response)