conftest.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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):
  20. url = reverse("misago:admin:appearance: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):
  31. url = reverse("misago:admin:appearance: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(
  38. "misago:admin:appearance:themes:upload-media", kwargs={"pk": theme.pk}
  39. )
  40. with open(os.path.join(TESTS_DIR, "images", "test.svg")) as fp:
  41. admin_client.post(url, {"assets": [fp]})
  42. return theme.media.get(name="test.svg")
  43. @pytest.fixture
  44. def image(admin_client, theme):
  45. url = reverse(
  46. "misago:admin:appearance:themes:upload-media", kwargs={"pk": theme.pk}
  47. )
  48. with open(os.path.join(TESTS_DIR, "images", "test.png"), "rb") as fp:
  49. admin_client.post(url, {"assets": [fp]})
  50. return theme.media.get(name="test.png")
  51. @pytest.fixture(autouse=True)
  52. def mock_build_single_theme_css(mocker):
  53. delay = mocker.Mock()
  54. mocker.patch(
  55. "misago.themes.admin.views.build_single_theme_css", mocker.Mock(delay=delay)
  56. )
  57. return delay
  58. @pytest.fixture(autouse=True)
  59. def mock_build_theme_css(mocker):
  60. delay = mocker.Mock()
  61. mocker.patch("misago.themes.admin.views.build_theme_css", mocker.Mock(delay=delay))
  62. return delay
  63. @pytest.fixture(autouse=True)
  64. def mock_update_remote_css_size(mocker):
  65. delay = mocker.Mock()
  66. mocker.patch(
  67. "misago.themes.admin.views.update_remote_css_size", mocker.Mock(delay=delay)
  68. )
  69. return delay