mirror of
https://github.com/django-components/django-components.git
synced 2025-10-17 01:07:12 +00:00
Add render() and render_dependencies() to Compoent.
This commit is contained in:
parent
972f99af05
commit
6492081b64
3 changed files with 41 additions and 7 deletions
|
@ -1,23 +1,38 @@
|
|||
from textwrap import dedent
|
||||
import unittest
|
||||
import django
|
||||
from django.conf import settings
|
||||
from django_components import component
|
||||
|
||||
class SimpleComponent(component.Component):
|
||||
def context(self, variable):
|
||||
def context(self, variable=None):
|
||||
return {
|
||||
"variable": variable,
|
||||
}
|
||||
|
||||
class Media:
|
||||
template = "template.html"
|
||||
template = "simple_template.html"
|
||||
css = {"all": "style.css"}
|
||||
js = ("script.js",)
|
||||
|
||||
class ComponentRegistryTest(unittest.TestCase):
|
||||
def test_simple_component(self):
|
||||
def setUp(self):
|
||||
settings.configure(
|
||||
TEMPLATES=[{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': ["tests/templates/"],
|
||||
}]
|
||||
)
|
||||
django.setup()
|
||||
|
||||
def test_simple_component(self):
|
||||
comp = SimpleComponent()
|
||||
|
||||
self.assertEqual(comp.context("test"), {"variable": "test"})
|
||||
self.assertEqual(comp._media.template, "template.html")
|
||||
self.assertEqual(comp._media.css, {"all": "style.css"})
|
||||
self.assertEqual(comp._media.js, ("script.js",))
|
||||
self.assertEqual(comp.render_dependencies(), dedent("""
|
||||
<link href="style.css" type="text/css" media="all" rel="stylesheet" />
|
||||
<script type="text/javascript" src="script.js"></script>
|
||||
""").strip())
|
||||
|
||||
self.assertEqual(comp.render(variable="test"), dedent("""
|
||||
Variable: <strong>test</strong>
|
||||
""").lstrip())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue