test_getting_active_theme.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from django.core.files.base import ContentFile
  2. from ..activetheme import get_active_theme
  3. from ..models import Theme
  4. def test_active_theme_data_can_be_obtained(db):
  5. assert get_active_theme()
  6. def test_if_active_theme_is_default_theme_include_defaults_flag_is_set(db):
  7. assert get_active_theme()["include_defaults"]
  8. def test_if_active_theme_is_default_themes_child_include_defaults_flag_is_set(
  9. default_theme, active_theme
  10. ):
  11. active_theme.parent = default_theme
  12. active_theme.save()
  13. assert get_active_theme()["include_defaults"]
  14. def test_if_active_theme_is_not_default_themes_child_include_defaults_flag_is_not_set(
  15. active_theme,
  16. ):
  17. assert not get_active_theme()["include_defaults"]
  18. def test_active_theme_styles_are_included(active_theme):
  19. active_theme.css.create(name="test", url="https://example.com")
  20. assert get_active_theme()["styles"]
  21. def test_active_theme_parents_styles_are_included(active_theme):
  22. parent_theme = Theme.objects.create(name="Parent theme")
  23. parent_theme.css.create(name="test", url="https://example.com")
  24. active_theme.move_to(parent_theme)
  25. active_theme.save()
  26. assert get_active_theme()["styles"]
  27. def test_active_theme_child_themes_styles_are_not_included(active_theme):
  28. child_theme = Theme.objects.create(parent=active_theme, name="Child theme")
  29. child_theme.css.create(name="test", url="https://example.com")
  30. assert not get_active_theme()["styles"]
  31. def test_active_theme_styles_are_ordered(active_theme):
  32. last_css = active_theme.css.create(
  33. name="test", url="https://last-example.com", order=1
  34. )
  35. first_css = active_theme.css.create(
  36. name="test", url="https://first-example.com", order=0
  37. )
  38. assert get_active_theme()["styles"] == [first_css.url, last_css.url]
  39. def test_active_theme_styles_list_includes_url_to_remote_css(active_theme):
  40. css = active_theme.css.create(name="test", url="https://last-example.com")
  41. assert get_active_theme()["styles"] == [css.url]
  42. def test_active_theme_styles_list_contains_url_to_local_css(active_theme):
  43. css = active_theme.css.create(
  44. name="test",
  45. source_file=ContentFile("body {}", name="test.css"),
  46. source_hash="abcdefgh",
  47. )
  48. assert get_active_theme()["styles"] == [css.source_file.url]
  49. def test_active_theme_styles_list_contains_url_to_local_built_css(active_theme):
  50. css = active_theme.css.create(
  51. name="test",
  52. source_needs_building=True,
  53. build_file=ContentFile("body {}", name="test.css"),
  54. build_hash="abcdefgh",
  55. )
  56. assert get_active_theme()["styles"] == [css.build_file.url]
  57. def test_active_theme_styles_list_exclude_url_to_css_that_has_not_been_built(
  58. active_theme,
  59. ):
  60. active_theme.css.create(
  61. name="test",
  62. source_file=ContentFile("body {}", name="test.css"),
  63. source_hash="abcdefgh",
  64. source_needs_building=True,
  65. )
  66. assert not get_active_theme()["styles"]