mirror of
https://github.com/django-components/django-components.git
synced 2025-12-23 11:12:57 +00:00
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
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:
parent
49afdb49d6
commit
a080ac959b
1 changed files with 43 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue