Caching templates to allow for dynamic template generation

Co-authored-by: rbeard0330 <@dul2k3BKW6m>
This commit is contained in:
Emil Stenström 2021-02-15 21:07:14 +01:00 committed by GitHub
parent 3919943cbd
commit 07986c5216
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 17 deletions

View file

@ -10,7 +10,10 @@ if not settings.configured:
TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ["tests/templates/"],
}]
}],
COMPONENTS={
'TEMPLATE_CACHE_SIZE': 128
},
)
else:
settings.configure(

View file

@ -2,11 +2,11 @@ from textwrap import dedent
from django.template import Context
from django_components import component
from .django_test_setup import * # NOQA
from .testutils import Django111CompatibleSimpleTestCase as SimpleTestCase
from django_components import component
class ComponentRegistryTest(SimpleTestCase):
def test_empty_component(self):
@ -32,7 +32,6 @@ class ComponentRegistryTest(SimpleTestCase):
comp = SimpleComponent("simple_component")
context = Context(comp.context(variable="test"))
comp.compile_instance_template({})
self.assertHTMLEqual(comp.render_dependencies(), dedent("""
<link href="style.css" type="text/css" media="all" rel="stylesheet">
@ -71,7 +70,6 @@ class ComponentRegistryTest(SimpleTestCase):
comp = FilteredComponent("filtered_component")
context = Context(comp.context(var1="test1", var2="test2"))
comp.compile_instance_template({})
self.assertHTMLEqual(comp.render(context), dedent("""
Var1: <strong>test1</strong>

View file

@ -1,8 +1,9 @@
from django.template import Context, Template
from .django_test_setup import * # NOQA
from django_components import component
from .django_test_setup import * # NOQA
from .testutils import Django111CompatibleSimpleTestCase as SimpleTestCase

View file

@ -1,5 +1,6 @@
import unittest
from .django_test_setup import * # NOQA
from django_components import component

View file

@ -2,9 +2,9 @@ from textwrap import dedent
from django.template import Context, Template
from .django_test_setup import * # NOQA
from django_components import component
from .django_test_setup import * # NOQA
from .testutils import Django111CompatibleSimpleTestCase as SimpleTestCase

View file

@ -1,3 +1,4 @@
from django import setup
from django.test import SimpleTestCase
@ -5,3 +6,5 @@ class Django111CompatibleSimpleTestCase(SimpleTestCase):
def assertHTMLEqual(self, left, right):
left = left.replace(' type="text/javascript"', '')
super(Django111CompatibleSimpleTestCase, self).assertHTMLEqual(left, right)
setup()