refactor: use typevar defaults + raise on conflicting extensions (#1125)

* refactor: use typevar defaults + raise on conflicting extensions

* refactor: fix linter errors
This commit is contained in:
Juro Oravec 2025-04-14 10:00:18 +02:00 committed by GitHub
parent 61528ef0ad
commit 06cad2ec64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 321 additions and 93 deletions

View file

@ -1,6 +1,7 @@
import gc
from typing import Any, Callable, Dict, List, cast
import pytest
from django.http import HttpRequest, HttpResponse
from django.template import Context
from django.test import Client
@ -108,6 +109,10 @@ class DummyNestedExtension(ComponentExtension):
]
class RenderExtension(ComponentExtension):
name = "render"
def with_component_cls(on_created: Callable):
class TempComponent(Component):
template = "Hello {{ name }}!"
@ -151,6 +156,22 @@ class TestExtension:
del TestAccessComp
gc.collect()
def test_raises_on_extension_name_conflict(self):
@djc_test(components_settings={"extensions": [RenderExtension]})
def inner():
pass
with pytest.raises(ValueError, match="Extension name 'render' conflicts with existing Component class API"):
inner()
def test_raises_on_multiple_extensions_with_same_name(self):
@djc_test(components_settings={"extensions": [DummyExtension, DummyExtension]})
def inner():
pass
with pytest.raises(ValueError, match="Multiple extensions cannot have the same name 'test_extension'"):
inner()
@djc_test
class TestExtensionHooks: