test_theme_creation_and_edition.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import pytest
  2. from django.urls import reverse
  3. from ....test import assert_contains, assert_not_contains
  4. from ...models import Theme
  5. @pytest.fixture
  6. def create_link():
  7. return reverse("misago:admin:appearance:themes:new")
  8. def test_theme_creation_form_is_displayed(admin_client, create_link):
  9. response = admin_client.get(create_link)
  10. assert response.status_code == 200
  11. assert_contains(response, "New theme")
  12. def test_theme_creation_form_reads_parent_from_url_and_preselects_it_in_parent_select(
  13. admin_client, create_link, theme
  14. ):
  15. response = admin_client.get("%s?parent=%s" % (create_link, theme.pk))
  16. assert_contains(response, '<option value="%s" selected>' % theme.pk)
  17. def test_theme_creation_form_reads_parent_from_url_and_discards_invalid_value(
  18. admin_client, create_link, theme
  19. ):
  20. response = admin_client.get("%s?parent=%s" % (create_link, theme.pk + 1))
  21. assert response.status_code == 200
  22. def test_theme_can_be_created(
  23. admin_client, create_link
  24. ):
  25. admin_client.post(create_link, {"name": "New Theme"})
  26. Theme.objects.get(name="New Theme")
  27. def test_child_theme_for_custom_theme_can_be_created(
  28. admin_client, create_link, theme
  29. ):
  30. admin_client.post(create_link, {"name": "New Theme", "parent": theme.pk})
  31. child_theme = Theme.objects.get(name="New Theme")
  32. assert child_theme.parent == theme
  33. def test_child_theme_for_default_theme_can_be_created(
  34. admin_client, create_link, default_theme
  35. ):
  36. admin_client.post(create_link, {"name": "New Theme", "parent": default_theme.pk})
  37. child_theme = Theme.objects.get(name="New Theme")
  38. assert child_theme.parent == default_theme
  39. def test_creating_child_theme_updates_themes_tree(
  40. admin_client, create_link, theme
  41. ):
  42. admin_client.post(create_link, {"name": "New Theme", "parent": theme.pk})
  43. child_theme = Theme.objects.get(name="New Theme")
  44. assert child_theme.tree_id == theme.tree_id
  45. assert child_theme.lft == 2
  46. assert child_theme.rght == 3
  47. theme.refresh_from_db()
  48. assert theme.lft == 1
  49. assert theme.rght == 4
  50. def test_theme_creation_fails_if_name_is_not_given(admin_client, create_link):
  51. admin_client.post(create_link, {"name": ""})
  52. assert Theme.objects.count() == 1