test_deleting_assets.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import pytest
  2. from django.urls import reverse
  3. from ....cache.test import assert_invalidates_cache
  4. from ....test import assert_has_success_message
  5. from ... import THEME_CACHE
  6. @pytest.fixture
  7. def delete_css(admin_client):
  8. def delete_assets(theme, assets):
  9. url = reverse(
  10. "misago:admin:appearance:themes:delete-css", kwargs={"pk": theme.pk}
  11. )
  12. return admin_client.post(url, {"item": [i.pk for i in assets]})
  13. return delete_assets
  14. @pytest.fixture
  15. def delete_media(admin_client):
  16. def delete_assets(theme, assets):
  17. url = reverse(
  18. "misago:admin:appearance:themes:delete-media", kwargs={"pk": theme.pk}
  19. )
  20. return admin_client.post(url, {"item": [i.pk for i in assets]})
  21. return delete_assets
  22. def test_theme_css_can_be_deleted(theme, delete_css, css):
  23. delete_css(theme, [css])
  24. assert not theme.css.exists()
  25. def test_theme_css_link_can_be_deleted(theme, delete_css, css_link):
  26. delete_css(theme, [css_link])
  27. assert not theme.css.exists()
  28. def test_multiple_theme_css_can_be_deleted_at_single_time(
  29. theme, delete_css, css, css_link
  30. ):
  31. delete_css(theme, [css, css_link])
  32. assert not theme.css.exists()
  33. def test_theme_media_can_be_deleted(theme, delete_media, media):
  34. delete_media(theme, [media])
  35. assert not theme.media.exists()
  36. def test_theme_images_can_be_deleted(theme, delete_media, image):
  37. delete_media(theme, [image])
  38. assert not theme.media.exists()
  39. def test_multiple_theme_media_can_be_deleted_at_single_time(
  40. theme, delete_media, media, image
  41. ):
  42. delete_media(theme, [media, image])
  43. assert not theme.media.exists()
  44. def test_success_message_is_set_after_css_is_deleted(theme, delete_css, css):
  45. response = delete_css(theme, [css])
  46. assert_has_success_message(response)
  47. def test_success_message_is_set_after_media_is_deleted(theme, delete_media, media):
  48. response = delete_media(theme, [media])
  49. assert_has_success_message(response)
  50. def test_selecting_no_css_to_delete_causes_no_errors(theme, delete_css, css):
  51. delete_css(theme, [])
  52. assert theme.css.exists()
  53. def test_selecting_no_media_to_delete_causes_no_errors(theme, delete_media, media):
  54. delete_media(theme, [])
  55. assert theme.media.exists()
  56. def test_selecting_invalid_css_id_to_delete_causes_no_errors(
  57. mocker, theme, delete_css, css
  58. ):
  59. delete_css(theme, [mocker.Mock(pk="str")])
  60. assert theme.css.exists()
  61. def test_selecting_invalid_media_id_to_delete_causes_no_errors(
  62. mocker, theme, delete_media, media
  63. ):
  64. delete_media(theme, [mocker.Mock(pk="str")])
  65. assert theme.media.exists()
  66. def test_selecting_nonexisting_css_id_to_delete_causes_no_errors(
  67. mocker, theme, delete_css, css
  68. ):
  69. delete_css(theme, [mocker.Mock(pk=css.pk + 1)])
  70. assert theme.css.exists()
  71. def test_selecting_nonexisting_media_id_to_delete_causes_no_errors(
  72. mocker, theme, delete_media, media
  73. ):
  74. delete_media(theme, [mocker.Mock(pk=media.pk + 1)])
  75. assert theme.media.exists()
  76. def test_other_theme_css_is_not_deleted(delete_css, theme, other_theme, css):
  77. delete_css(other_theme, [css])
  78. assert theme.css.exists()
  79. def test_other_theme_media_is_not_deleted(delete_media, theme, other_theme, media):
  80. delete_media(other_theme, [media])
  81. assert theme.media.exists()
  82. def test_deleting_css_invalidates_theme_cache(theme, delete_css, css):
  83. with assert_invalidates_cache(THEME_CACHE):
  84. delete_css(theme, [css])