Add tests for components with dynamic template.

This commit is contained in:
Emil Stenström 2021-02-20 10:04:10 +01:00
parent 6906888b2c
commit 475bc8720f
3 changed files with 24 additions and 0 deletions

View file

@ -0,0 +1 @@
<svg>Dynamic1</svg>

After

Width:  |  Height:  |  Size: 20 B

View file

@ -0,0 +1 @@
<svg>Dynamic2</svg>

After

Width:  |  Height:  |  Size: 20 B

View file

@ -75,3 +75,25 @@ class ComponentRegistryTest(SimpleTestCase):
Var1: <strong>test1</strong>
Var2 (uppercased): <strong>TEST2</strong>
""").lstrip())
def test_component_with_dynamic_template(self):
class SvgComponent(component.Component):
def context(self, name, css_class="", title="", **attrs):
return {"name": name, "css_class": css_class, "title": title, **attrs}
def template(self, context):
return f"svg_{context['name']}.svg"
comp = SvgComponent("svg_component")
self.assertHTMLEqual(
comp.render(Context(comp.context(name="dynamic1"))),
dedent("""\
<svg>Dynamic1</svg>
""")
)
self.assertHTMLEqual(
comp.render(Context(comp.context(name="dynamic2"))),
dedent("""\
<svg>Dynamic2</svg>
""")
)