refactor: add tests to ensure we add component path on template errors (#1448)
Some checks failed
Docs - build & deploy / docs (push) Has been cancelled
Run tests / build (ubuntu-latest, 3.10) (push) Has been cancelled
Run tests / build (ubuntu-latest, 3.11) (push) Has been cancelled
Run tests / build (ubuntu-latest, 3.12) (push) Has been cancelled
Run tests / build (ubuntu-latest, 3.13) (push) Has been cancelled
Run tests / build (ubuntu-latest, 3.8) (push) Has been cancelled
Run tests / build (ubuntu-latest, 3.9) (push) Has been cancelled
Run tests / build (windows-latest, 3.10) (push) Has been cancelled
Run tests / build (windows-latest, 3.11) (push) Has been cancelled
Run tests / build (windows-latest, 3.12) (push) Has been cancelled
Run tests / build (windows-latest, 3.13) (push) Has been cancelled
Run tests / build (windows-latest, 3.8) (push) Has been cancelled
Run tests / build (windows-latest, 3.9) (push) Has been cancelled
Run tests / test_docs (3.13) (push) Has been cancelled
Run tests / test_sampleproject (3.13) (push) Has been cancelled

This commit is contained in:
Juro Oravec 2025-10-08 18:48:58 +02:00 committed by GitHub
parent 49afdb49d6
commit a080ac959b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,7 +10,7 @@ from typing import Any, List, Literal, NamedTuple, Optional
import pytest
from django.conf import settings
from django.http import HttpRequest, HttpResponse
from django.template import Context, RequestContext, Template
from django.template import Context, RequestContext, Template, TemplateSyntaxError
from django.template.base import TextNode
from django.test import Client
from django.urls import path
@ -1471,6 +1471,48 @@ class TestComponentRender:
):
Root.render()
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_prepends_exceptions_on_template_compile_error(self, components_settings):
@register("simple_component")
class SimpleComponent(Component):
template = "hello"
class Other(Component):
template = """
{% load component_tags %}
{% component "simple_component" %}
{% endif %}
"""
with pytest.raises(
TemplateSyntaxError,
match=re.escape(
"An error occured while rendering components Other:\n"
"Invalid block tag on line 4: 'endif', expected 'endcomponent'",
),
):
Other.render()
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_prepends_exceptions_on_template_compile_error2(self, components_settings):
@register("simple_component")
class SimpleComponent(Component):
template = "hello"
class Other(Component):
template = """
{% load component_tags %}
{% component "simple_component" %}
"""
with pytest.raises(
TemplateSyntaxError,
match=re.escape(
"An error occured while rendering components Other:\nUnclosed tag on line 3: 'component'",
),
):
Other.render()
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_pydantic_exception(self, components_settings):
from pydantic import BaseModel, ValidationError