mirror of
https://github.com/django-components/django-components.git
synced 2025-08-03 22:08:17 +00:00
Add support for - and / in component names in middleware
- Fix the COMPONENT_COMMENT_REGEX to find component names with special symbols.
- Fix the test to catch the error.
Follow-up of e0c29e5
and ref: #262
This commit is contained in:
parent
c0fc6c0a12
commit
a919b648b3
2 changed files with 20 additions and 17 deletions
|
@ -399,18 +399,21 @@ class ComponentMediaRenderingTests(SimpleTestCase):
|
|||
request = Mock()
|
||||
self.assertEqual(response, middleware(request=request))
|
||||
|
||||
def test_middleware_response_with_components_with_slash_and_dash(self):
|
||||
component.registry.register(
|
||||
name="test-component", component=SimpleComponent
|
||||
)
|
||||
component.registry.register(
|
||||
name="test/component", component=SimpleComponent
|
||||
)
|
||||
|
||||
template = Template(
|
||||
"{% load component_tags %}{% component_js_dependencies %}"
|
||||
"{% component 'test-component' variable='variable' %}"
|
||||
"{% component 'test/component' variable='variable' %}"
|
||||
)
|
||||
rendered = create_and_process_template_response(template)
|
||||
self.assertNotIn("_RENDERED", rendered)
|
||||
def test_middleware_response_with_components_with_slash_dash_and_underscore(self):
|
||||
component_names = ["test-component", "test/component", "test_component"]
|
||||
for component_name in component_names:
|
||||
component.registry.register(
|
||||
name=component_name, component=SimpleComponent
|
||||
)
|
||||
template = Template(
|
||||
"{% load component_tags %}"
|
||||
"{% component_js_dependencies %}"
|
||||
"{% component_css_dependencies %}"
|
||||
f"{{% component '{component_name}' variable='value' %}}"
|
||||
)
|
||||
rendered = create_and_process_template_response(template)
|
||||
self.assertEqual((
|
||||
'<script src="script.js"></script>'
|
||||
'<link href="style.css" media="all" rel="stylesheet">'
|
||||
"Variable: <strong>value</strong>\n"
|
||||
), rendered)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue