""" Tests for template_partials integration with django-components. See https://github.com/django-components/django-components/issues/1327 and https://github.com/django-components/django-components/issues/1323. This file can be deleted after Django 5.2 reached end of life. See https://github.com/django-components/django-components/issues/1323#issuecomment-3163478287. """ from typing import NamedTuple import pytest from django.shortcuts import render from django.http import HttpRequest from django_components import Component, register from django_components.testing import djc_test from .testutils import setup_test_config try: from template_partials.templatetags.partials import TemplateProxy except ImportError: TemplateProxy = None setup_test_config(components={"autodiscover": False}) # See https://github.com/django-components/django-components/issues/1323#issuecomment-3156654329 @djc_test( django_settings={"INSTALLED_APPS": ("template_partials", "django_components", "tests.test_app")} ) class TestTemplatePartialsIntegration: @pytest.mark.skipif(TemplateProxy is None, reason="template_partials not available") def test_render_partial(self): @register("calendar") class Calendar(Component): template = """
Today's date is {{ date }}
""" css = """ .calendar-component { width: 200px; background: pink; } .calendar-component span { font-weight: bold; } """ js = """ (function(){ if (document.querySelector(".calendar-component")) { document.querySelector(".calendar-component").onclick = function(){ alert("Clicked calendar!"); }; } })() """ # noqa: E501 class Kwargs(NamedTuple): date: str def get_template_data(self, args, kwargs: Kwargs, slots, context): return { "date": kwargs.date, } # NOTE: When a full template is rendered (without the `#` syntax), the output should be as usual. request = HttpRequest() result = render(request, "integration_template_partials.html") content = result.content assert b"