Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_plugin_template_instance(self):
renderer = TemplatePluginRenderer()
renderer.register_template_renderer(HTML, Template("{{ plugin.html|safe }}"))
page = Page.objects.create(template_key="standard")
HTML.objects.create(
parent=page, ordering=10, region="main", html="<b>Hello</b>"
)
regions = Regions.from_item(page, renderer=renderer)
self.assertEqual(regions.render("main", Context()), "<b>Hello</b>")
self.assertEqual(regions.render("main", None), "<b>Hello</b>")
)
page = Page.objects.create(template_key="standard")
HTML.objects.create(
parent=page, ordering=10, region="main", html="<b>Hello</b>"
)
regions = Regions.from_item(page, renderer=renderer)
self.assertEqual(regions.render("main", Context()), "<b>Hello</b>\n")
regions = Regions.from_item(page, renderer=renderer)
self.assertEqual(
regions.render("main", Context({"outer": "Test"})), "<b>Hello</b>Test\n"
)
regions = Regions.from_item(page, renderer=renderer, timeout=3)
self.assertEqual(
regions.render("main", Context({"outer": "Test2"})), "<b>Hello</b>Test2\n"
)
regions = Regions.from_item(page, renderer=renderer, timeout=3)
# Output stays the same.
self.assertEqual(
regions.render("main", Context({"outer": "Test3"})), "<b>Hello</b>Test2\n"
)
self.assertEqual(regions.cache_key("main"), "testapp.page-%s-main" % page.pk)