mirror of
https://github.com/django-components/django-components.git
synced 2025-08-10 01:08:00 +00:00
Add tests for components with dynamic template.
This commit is contained in:
parent
6906888b2c
commit
475bc8720f
3 changed files with 24 additions and 0 deletions
1
tests/templates/svg_dynamic1.svg
Normal file
1
tests/templates/svg_dynamic1.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg>Dynamic1</svg>
|
After Width: | Height: | Size: 20 B |
1
tests/templates/svg_dynamic2.svg
Normal file
1
tests/templates/svg_dynamic2.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg>Dynamic2</svg>
|
After Width: | Height: | Size: 20 B |
|
@ -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>
|
||||
""")
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue