Example #1
0
def test_theme_selection():
    """
    Test that a theme with a `template_dir` actually affects template directory selection.
    """
    with override_current_theme_class(), override_provides("xtheme", [
        "shoop_tests.xtheme.utils:FauxTheme",
        "shoop_tests.xtheme.utils:FauxTheme2",
        "shoop_tests.xtheme.utils:H2G2Theme",
    ]):
        ThemeSettings.objects.all().delete()
        for theme in get_provide_objects("xtheme"):
            set_current_theme(theme.identifier)
            je = get_jinja2_engine()
            wrapper = (noop() if theme.identifier == "h2g2" else pytest.raises(TemplateDoesNotExist))
            with wrapper:
                t = je.get_template("42.jinja")
                content = t.render().strip()
                assert "a slice of lemon wrapped around a large gold brick" in content.replace("\n", " ")
Example #2
0
def test_theme_selection():
    """
    Test that a theme with a `template_dir` actually affects template directory selection.
    """
    with override_current_theme_class(), override_provides(
            "xtheme", [
                "shoop_tests.xtheme.utils:FauxTheme",
                "shoop_tests.xtheme.utils:FauxTheme2",
                "shoop_tests.xtheme.utils:H2G2Theme",
            ]):
        ThemeSettings.objects.all().delete()
        for theme in get_provide_objects("xtheme"):
            set_current_theme(theme.identifier)
            je = get_jinja2_engine()
            wrapper = (noop() if theme.identifier == "h2g2" else
                       pytest.raises(TemplateDoesNotExist))
            with wrapper:
                t = je.get_template("42.jinja")
                content = t.render().strip()
                assert "a slice of lemon wrapped around a large gold brick" in content.replace(
                    "\n", " ")
Example #3
0
def test_theme_activation():
    with override_current_theme_class():
        with override_provides("xtheme", [
            "shoop_tests.xtheme.utils:FauxTheme",
            "shoop_tests.xtheme.utils:FauxTheme2"
        ]):
            ThemeSettings.objects.all().delete()
            assert not get_current_theme()
            set_current_theme(FauxTheme.identifier)
            assert isinstance(get_current_theme(), FauxTheme)
            set_current_theme(FauxTheme2.identifier)
            assert isinstance(get_current_theme(), FauxTheme2)
            with pytest.raises(ValueError):
                set_current_theme(printable_gibberish())
Example #4
0
 def form_valid(self, form):
     identifier = form.cleaned_data["activate"]
     set_current_theme(identifier)
     messages.success(self.request, _("Theme activated."))
     return HttpResponseRedirect(self.request.path)
Example #5
0
 def form_valid(self, form):
     identifier = form.cleaned_data["activate"]
     set_current_theme(identifier)
     messages.success(self.request, _("Theme activated."))
     return HttpResponseRedirect(self.request.path)