test_deleting_assets.py 3.2 KB

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