mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 15:39:08 +00:00
feat: add decorator for writing component tests (#1008)
* feat: add decorator for writing component tests * refactor: udpate changelog + update deps pins * refactor: fix deps * refactor: make cached_ref into generic and fix linter errors * refactor: fix coverage testing * refactor: use global var instead of env var for is_testing state
This commit is contained in:
parent
81ac59f7fb
commit
7dfcb447c4
62 changed files with 4428 additions and 3661 deletions
|
@ -2,27 +2,28 @@ from django.template import Context, Template
|
|||
|
||||
from django_components import Component, cached_template, types
|
||||
|
||||
from .django_test_setup import setup_test_config
|
||||
from .testutils import BaseTestCase
|
||||
from django_components.testing import djc_test
|
||||
from .testutils import setup_test_config
|
||||
|
||||
setup_test_config({"autodiscover": False})
|
||||
|
||||
|
||||
class TemplateCacheTest(BaseTestCase):
|
||||
@djc_test
|
||||
class TestTemplateCache:
|
||||
def test_cached_template(self):
|
||||
template_1 = cached_template("Variable: <strong>{{ variable }}</strong>")
|
||||
template_1._test_id = "123"
|
||||
|
||||
template_2 = cached_template("Variable: <strong>{{ variable }}</strong>")
|
||||
|
||||
self.assertEqual(template_2._test_id, "123")
|
||||
assert template_2._test_id == "123"
|
||||
|
||||
def test_cached_template_accepts_class(self):
|
||||
class MyTemplate(Template):
|
||||
pass
|
||||
|
||||
template = cached_template("Variable: <strong>{{ variable }}</strong>", MyTemplate)
|
||||
self.assertIsInstance(template, MyTemplate)
|
||||
assert isinstance(template, MyTemplate)
|
||||
|
||||
def test_component_template_is_cached(self):
|
||||
class SimpleComponent(Component):
|
||||
|
@ -42,4 +43,4 @@ class TemplateCacheTest(BaseTestCase):
|
|||
template_1._test_id = "123"
|
||||
|
||||
template_2 = comp._get_template(Context({}), component_id="123")
|
||||
self.assertEqual(template_2._test_id, "123")
|
||||
assert template_2._test_id == "123"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue