1111from plone import api
1212from plone .app .testing import setRoles
1313from plone .app .testing import TEST_USER_ID
14+ from zope .schema .interfaces import WrongContainedType
1415
1516import unittest
1617
@@ -143,7 +144,7 @@ def test_add_custom_view_returns_true(self):
143144 if existing_views :
144145 # Test with existing view - function should still work
145146 result = add_custom_view (
146- existing_views [ 0 ][ "row_type" ] ,
147+ "cs_dynamicpages-some-custom-view" ,
147148 ["title" , "description" ],
148149 has_button = False ,
149150 icon = "star" ,
@@ -153,10 +154,26 @@ def test_add_custom_view_returns_true(self):
153154 else :
154155 self .skipTest ("No existing views to test with" )
155156
157+ def test_add_custom_view_returns_false (self ):
158+ # Use an existing view name
159+ existing_views = get_available_views_for_row ()
160+ if existing_views :
161+ # Test with existing view - function should still work
162+ result = add_custom_view (
163+ existing_views [0 ]["row_type" ],
164+ ["title" , "description" ],
165+ has_button = False ,
166+ icon = "star" ,
167+ )
168+ # Function returns True even if view already exists
169+ self .assertFalse (result )
170+ else :
171+ self .skipTest ("No existing views to test with" )
172+
156173 def test_add_custom_view_structure (self ):
157174 """Test that add_custom_view creates correct structure."""
158175 # Test using slider-view which is registered
159- view_name = "cs_dynamicpages-slider -view"
176+ view_name = "cs_dynamicpages-some-custom -view"
160177 original_len = len (api .portal .get_registry_record (self .record_name ))
161178
162179 add_custom_view (view_name , ["title" ], has_button = True , icon = "heart" )
@@ -175,7 +192,7 @@ def test_add_custom_view_structure(self):
175192
176193 def test_add_custom_view_default_icon_is_bricks (self ):
177194 """Test that default icon is 'bricks'."""
178- view_name = "cs_dynamicpages-featured -view"
195+ view_name = "cs_dynamicpages-some-custom -view"
179196
180197 add_custom_view (view_name , ["title" ])
181198
@@ -185,6 +202,13 @@ def test_add_custom_view_default_icon_is_bricks(self):
185202 last_match = matching [- 1 ] # Get the last added one
186203 self .assertEqual (last_match ["row_type_icon" ], "bricks" )
187204
205+ def test_add_not_available_custom_view_fails (self ):
206+ """try to add a view that is not registered"""
207+ view_name = "cs_dynamicpages-this-view-does-not-exist"
208+
209+ with self .assertRaises (WrongContainedType ):
210+ add_custom_view (view_name , ["title" ])
211+
188212
189213class EnableBehaviorIntegrationTest (unittest .TestCase ):
190214 """Integration tests for enable_behavior function."""
0 commit comments