Skip to content

Commit 7ab4baf

Browse files
committed
Fix typing
1 parent 9cf117d commit 7ab4baf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

djangocms_frontend/component_pool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import defaultdict
22
import importlib
33
import os
4+
from collections.abc import Iterator
45
import warnings
56

67
from django import forms
@@ -71,7 +72,9 @@ def component_factory(module, component: tuple, fields: list[tuple], template: s
7172
},
7273
)
7374

74-
def scan_templates_for_component_declaration(self, templates: list[tuple[str, str]]) -> list[CMSFrontendComponent]:
75+
def scan_templates_for_component_declaration(
76+
self, templates: list[tuple[str, str]]
77+
) -> Iterator[CMSFrontendComponent]:
7578
from django.forms import fields
7679

7780
field_context = self.get_field_context()

tests/test_autocomponent.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from cms.api import add_plugin
22
from cms.test_utils.testcases import CMSTestCase
3+
from django.template import Template, TemplateSyntaxError
34

45
from tests.fixtures import TestFixture
56

@@ -69,3 +70,23 @@ def test_split_template_tag(self):
6970
self.assertEqual(split("Mixin1|Mixin2"), ["Mixin1", "Mixin2"])
7071
self.assertEqual(split("hero.html"), ["hero.html"])
7172
self.assertEqual(split("hero.html, Mixin1, Mixin2", ", "), ["hero.html", "Mixin1", "Mixin2"])
73+
74+
def test_invalid_cms_component_usage_missing_required_argument(self):
75+
# The {% cms_component %} tag requires a component name.
76+
invalid_template = "{% load cms_tags %}{% cms_component %}"
77+
with self.assertRaises(TemplateSyntaxError):
78+
Template(invalid_template)
79+
80+
def test_invalid_field_usage_invalid_argument(self):
81+
# The {% field %} tag requires valid arguments: a field name and a component instance.
82+
# Here we simulate invalid usage by providing an invalid component.
83+
invalid_template = "{% load cms_tags %}{% field 'nonexistent_field' component %}"
84+
with self.assertRaises(TemplateSyntaxError):
85+
Template(invalid_template)
86+
87+
def test_multiple_cms_component_tags_error(self):
88+
# Assuming only one {% cms_component %} tag is allowed per template.
89+
# This should raise an error if multiple tags are used.
90+
invalid_template = "{% load cms_tags %}{% cms_component 'Hero' %}{% cms_component 'Footer' %}"
91+
with self.assertRaises(TemplateSyntaxError):
92+
Template(invalid_template)

0 commit comments

Comments
 (0)