def test_injecting_into_weird_places(): request = get_request() (template, layout, gibberish, ctx) = get_test_template_bits(request, **{ RESOURCE_CONTAINER_VAR_NAME: ResourceContainer() }) with pytest.raises(ValueError): add_resource(ctx, "yes", "hello.js")
def test_jinja_resource(): request = get_request() (template, layout, gibberish, context) = get_test_template_bits(request) assert JinjaMarkupResource("1+1={{ 1+1|float }}", context).render() == "1+1=2.0" assert JinjaMarkupResource("{{ 1|thisdoesnwork }}", context) == "(Error while rendering.)" assert JinjaMarkupResource("", context) == "" assert str(JinjaMarkupResource("1+1", context)) == "1+1" container = ResourceContainer() container.add_resource("body_end", JinjaMarkupResource("1+1={{ 1+1|float }}", context)) container.add_resource("body_end", JinjaMarkupResource("{{ 1|thisdoesnwork }}", context)) container.add_resource("body_end", JinjaMarkupResource("", context)) rendered_resource = container._render_resource("://example.com/js.js?random_text") assert "unknown resource type" not in rendered_resource assert rendered_resource == '<script src="://example.com/js.js?random_text"></script>' assert container.render_resources("body_end") == "1+1=2.0(Error while rendering.)"
def test_jinja_resource(): request = get_request() (template, layout, gibberish, context) = get_test_template_bits(request) assert JinjaMarkupResource("1+1={{ 1+1|float }}", context).render() == "1+1=2.0" assert JinjaMarkupResource("{{ 1|thisdoesnwork }}", context) == "(Error while rendering)" assert JinjaMarkupResource("", context) == "" assert str(JinjaMarkupResource("1+1", context)) == "1+1" container = ResourceContainer() container.add_resource("body_end", JinjaMarkupResource("1+1={{ 1+1|float }}", context)) container.add_resource("body_end", JinjaMarkupResource("{{ 1|thisdoesnwork }}", context)) container.add_resource("body_end", JinjaMarkupResource("", context)) assert container.render_resources("body_end") == "1+1=2.0(Error while rendering)"
def render(self, *args, **kwargs): """ Render the template and postprocess it. :return: Rendered markup :rtype: str """ vars = dict(*args, **kwargs) vars[RESOURCE_CONTAINER_VAR_NAME] = ResourceContainer() ctx = self.new_context(vars) try: content = concat(self.root_render_func(ctx)) return self._postprocess(ctx, content) except Exception: exc_info = sys.exc_info() return self.environment.handle_exception(exc_info, True)
def render(self, *args, **kwargs): """ Render the template and postprocess it. :return: Rendered markup :rtype: str """ vars = dict(*args, **kwargs) vars[RESOURCE_CONTAINER_VAR_NAME] = ResourceContainer() ctx = self.new_context(vars) try: content = concat(self.root_render_func(ctx)) if ctx and ctx.name and ctx.name in settings.SHUUP_XTHEME_EXCLUDE_TEMPLATES_FROM_RESOUCE_INJECTION: return content return self._postprocess(ctx, content) except Exception: exc_info = sys.exc_info() return self.environment.handle_exception(exc_info, True)