conftest.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import os
  2. import pytest
  3. from django.urls import reverse
  4. from ...models import Theme
  5. @pytest.fixture
  6. def default_theme(db):
  7. return Theme.objects.get(is_default=True)
  8. @pytest.fixture
  9. def theme(db):
  10. return Theme.objects.create(name="Custom theme")
  11. @pytest.fixture
  12. def other_theme(db):
  13. return Theme.objects.create(name="Other theme")
  14. @pytest.fixture
  15. def nonexisting_theme(mocker, default_theme):
  16. return mocker.Mock(pk=default_theme.pk + 1)
  17. TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
  18. @pytest.fixture
  19. def css(admin_client, theme, mock_build_theme_css):
  20. url = reverse("misago:admin:themes:upload-css", kwargs={"pk": theme.pk})
  21. with open(os.path.join(TESTS_DIR, "css", "test.css")) as fp:
  22. admin_client.post(url, {"assets": [fp]})
  23. return theme.css.get(name="test.css")
  24. @pytest.fixture
  25. def css_link(admin_client, theme):
  26. return theme.css.create(
  27. name="CSS link", url="https://example.com/cdn.css", order=theme.css.count()
  28. )
  29. @pytest.fixture
  30. def css_needing_build(admin_client, theme, mock_build_theme_css):
  31. url = reverse("misago:admin:themes:upload-css", kwargs={"pk": theme.pk})
  32. with open(os.path.join(TESTS_DIR, "css", "test.needs-build.css")) as fp:
  33. admin_client.post(url, {"assets": [fp]})
  34. return theme.css.get(name="test.needs-build.css")
  35. @pytest.fixture
  36. def media(admin_client, theme):
  37. url = reverse("misago:admin:themes:upload-media", kwargs={"pk": theme.pk})
  38. with open(os.path.join(TESTS_DIR, "images", "test.svg")) as fp:
  39. admin_client.post(url, {"assets": [fp]})
  40. return theme.media.get(name="test.svg")
  41. @pytest.fixture
  42. def image(admin_client, theme):
  43. url = reverse("misago:admin:themes:upload-media", kwargs={"pk": theme.pk})
  44. with open(os.path.join(TESTS_DIR, "images", "test.png"), "rb") as fp:
  45. admin_client.post(url, {"assets": [fp]})
  46. return theme.media.get(name="test.png")
  47. @pytest.fixture(autouse=True)
  48. def mock_build_single_theme_css(mocker):
  49. delay = mocker.Mock()
  50. mocker.patch(
  51. "misago.themes.admin.views.build_single_theme_css", mocker.Mock(delay=delay)
  52. )
  53. return delay
  54. @pytest.fixture(autouse=True)
  55. def mock_build_theme_css(mocker):
  56. delay = mocker.Mock()
  57. mocker.patch("misago.themes.admin.views.build_theme_css", mocker.Mock(delay=delay))
  58. mocker.patch(
  59. "misago.themes.admin.importer.build_theme_css", mocker.Mock(delay=delay)
  60. )
  61. return delay
  62. @pytest.fixture(autouse=True)
  63. def mock_update_remote_css_size(mocker):
  64. delay = mocker.Mock()
  65. mocker.patch(
  66. "misago.themes.admin.views.update_remote_css_size", mocker.Mock(delay=delay)
  67. )
  68. mocker.patch(
  69. "misago.themes.admin.importer.update_remote_css_size", mocker.Mock(delay=delay)
  70. )
  71. return delay