
    Bh,                         d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ  G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    )deque)Context)override_settings)
add_plugincreate_page)	CMSPlugin)ContentRendererLegacyRendererStructureRenderer)CMSTestCase)override_placeholder_conf)
CMSToolbar)get_object_edit_urlc                   0    e Zd ZeZddZd Zd Zd Zd Z	y)TestStructureRendererNc                 v    |r||j                  |      }| j                  |||      }| j                  |      S )Npage)get_absolute_urlget_requestrenderer_class)selfpathlanguager   requests        O/home/dcms/DCMS/lib/python3.12/site-packages/cms/tests/test_plugin_renderers.pyget_rendererz"TestStructureRenderer.get_renderer   sA    DL((2D""4"=""7++    c                    t        d      }| j                         }|j                  |      }| j                  d|j                         | j                  |j                  d       | j                  |j                  d   |       y )NMultiColumnPlugin)plugin_type)r   r   get_plugin_classassertIn_cached_plugin_classesassertEqual__name__)r   pluginrendererplugin_classs       r   test_get_plugin_class_cachez1TestStructureRenderer.test_get_plugin_class_cache   ss    ':;$$&008)8+J+JK..0CD889LM|\r   c                 8   t        ddd      }| j                         }|j                  d      j                  d      }| j	                  |      5  | j                         }|j                  |      }d}| j                  ||v        d d d        y # 1 sw Y   y xY w)Nr   nav_playground.htmlenbodyslotzU<div class="cms-submenu-item cms-submenu-item-title"><span>Multi Columns</span></div>)r   get_superuserget_placeholdersgetlogin_user_contextr   get_placeholder_plugin_menu
assertTrue)r   cms_page	superuserplaceholder_1r(   plugin_menuexpecteds          r    test_get_placeholder_plugin_menuz6TestStructureRenderer.test_get_placeholder_plugin_menu$   s    v'<dC&&(	 11$7;;;H$$Y/ 	5((*H">>}MKnHOOH34		5 	5 	5s   7BBc                     t        ddd      }| j                         }|j                  d      j                  d      }|j	                  ||      }dddd	|j
                   d
g}|D ]  }| j                  ||        y )Nr   r,   r-   r.   r/   "MultiColumnPlugin"z:"addPluginHelpTitle": "Add plugin to placeholder \"Body\""z"name": "Body""placeholder_id": "")r   r   r2   r3   get_placeholder_toolbar_jspkr#   )r   r7   r(   placeholdercontentexpected_bitsbits          r   "test_render_placeholder_toolbar_jsz8TestStructureRenderer.test_render_placeholder_toolbar_js/   s    v'<dC$$&//599v9F55k8L "J!+..!13	
 ! 	(CMM#w'	(r   c                 `   t        ddd      }| j                         }|j                  d      j                  d      }|j                  ddii}t        |      5  |j                  ||      }d d d        d	d
dd|j                   dg}|D ]  }| j                  |        y # 1 sw Y   7xY w)Nr   r,   r-   r.   r/   namezContent-with-dash)CMS_PLACEHOLDER_CONFr>   zG"addPluginHelpTitle": "Add plugin to placeholder \"Content-with-dash\""z"name": "Content-with-dash"r?   r@   )	r   r   r2   r3   r0   r   rA   rB   r#   )r   r7   r(   rC   confrD   rE   rF   s           r   +test_render_placeholder_toolbar_js_escapingzATestStructureRenderer.test_render_placeholder_toolbar_js_escaping?   s    v'<dC$$&//599v9F  6+>"?@&DA 	Q99+xPG	Q "W)!+..!13	
 ! 	(CMM#w'	(	Q 	Qs   B$$B-)Nr-   N)
r&   
__module____qualname__r   r   r   r*   r<   rG   rL    r   r   r   r      s!    &N,]	5( (r   r   c                   R    e Zd ZeZ ed      d        Z ed      d        Zd Zy)TestContentRendererTCMS_PLACEHOLDER_CACHEc                     t        ddd      }|j                  d      }| j                  ||      }| j                  |j	                                y )Nr   r,   r-   r   )r   r   r   r6   placeholder_cache_is_enabled)r   r7   request_pathr(   s       r   test_placeholder_cache_enabledz2TestContentRenderer.test_placeholder_cache_enabledW   sK    v'<dC006$$\$A==?@r   c                 j   t        d      5  | j                         }| j                  |j                                d d d        | j	                  | j                               5  | j                         }| j                  |j                                d d d        y # 1 sw Y   axY w# 1 sw Y   y xY w)NFrR   )r   r   assertFalserU   r4   "get_staff_user_with_no_permissions)r   r(   s     r   test_placeholder_cache_disabledz3TestContentRenderer.test_placeholder_cache_disabled^   s    U; 	F((*HXBBDE	F
 $$T%L%L%NO 	F((*HXBBDE	F 	F	F 	F
	F 	Fs   0B$0B)B&)B2c                    t        ddd      }|j                  d      j                  d      }t        |dddd	      }t        |ddd
d	      }|j                  d      j                  d      }t        |dddd	      }| j	                  |      }|j                  |       | j                  |j                  |j                         | j                  |j                  |j                  |j                            | j                  |j                  |j                  |j                            |j                  |j                     }| j                  ||j                     |       | j                  ||j                     j                  t        ||g             | j                  ||j                     |       | j                  ||j                     j                  t        |g             y )Nr   r,   r-   r.   r/   
LinkPluginLink #1https://www.django-cms.orgr!   r   rI   external_linkzLink #2right-columnLink #3r   )r   r2   r3   r   r   _preload_placeholders_for_pager#   rB   _placeholders_by_page_cacher0   r%   _plugins_cacher   )	r   r7   r9   placeholder_1_plugin_1placeholder_1_plugin_2placeholder_2placeholder_2_plugin_1r(   caches	            r   3test_preload_placeholders_for_page_with_inherit_offzGTestContentRenderer.test_preload_placeholders_for_page_with_inherit_offj   s   v'<dC 11$7;;;H!+$6"
 ",$6"
 !11$7;;;P!+$6"
 $$($3//9hkk8#G#GHm(((*N*Nx{{*[\m(((*N*Nx{{*[\44X[[A}112MB-$$%44e=SUk<l6m	
 	}112MB}112AA5J`IaCbcr   N)	r&   rM   rN   r	   r   r   rW   r[   rl   rO   r   r   rQ   rQ   T   sA    $NT2A 3A T2	F 3	F'dr   rQ   c                   X    e Zd ZeZd Zd Zd Zd Zd Z	d Z
d Z ed	      d
        Zy)TestExceptionCatchersc                    | j                         | _        t        ddd      | _        | j                  j	                  d      j                  d      | _        t        | j                  dddd	       t        | j                  d
d       | j                  j	                  d      j                  d      | _        t        | j                  dddd	      | _	        | j                  t        | j                  j                  d            d| j                        | _        t        | j                        | j                  _        | j!                  | j                        | _        y )Nr   r,   r-   r.   r/   r]   r^   r_   r`   BuggyPlugin)r!   r   rb   rc   r   )r1   userr   r7   r2   r3   r9   r   ri   rj   r   r   get_admin_contentr   r   toolbarr   r(   )r   s    r   setUpzTestExceptionCatchers.setUp   s.   &&(	#F,A4H!]];;DAEE6ER$6	
 	%	

 "]];;DAEE>EZ&0$6'
# '' ? ? EF ( 

  *$,,7++DLL9r   c                    d| j                   _        | j                   j                          | j                  dd      5 }t	               }| j
                  j                  | j                  |d       | j                  t        |j                        d       | j                  d|j                  d          d d d        d	| j                   _        | j                   j                          y # 1 sw Y   5xY w)
NNonExistingPluginzcms.utils.pluginsERRORlevelr-      z'Plugin not installed: NonExistingPluginr   r]   )rj   r!   save
assertLogsr   r(   render_placeholderri   r%   lenoutputr#   r   logsplugin_contexts      r   =test_non_existent_plugins_creates_error_log_and_does_not_failzSTestExceptionCatchers.test_non_existent_plugins_creates_error_log_and_does_not_fail   s    2E##/##((*__0_@ 	UD$YNMM,,T-?-?QUVS-q1MMCT[[QR^T		U
 3?##/##((*	U 	Us   A6C))C2c                 >   | j                  dd      5 }t               }| j                  j                  | j                  |d       | j                  t        |j                        d       | j                  d|j                  d          d d d        y # 1 sw Y   y xY w)Ncms.plugin_renderingrw   rx   r-   rz   z#ZeroDivisionError: division by zeror   )	r|   r   r(   r}   r9   r%   r~   r   r#   r   s      r   Ctest_exception_in_plugin_render_creates_error_log_and_does_not_failzYTestExceptionCatchers.test_exception_in_plugin_render_creates_error_log_and_does_not_fail   s    __37_C 	Qt$YNMM,,T-?-?QUVS-q1MM?QP		Q 	Q 	Qs   A6BBc                    ddl m} |j                  }d|_        | j                  dd      5 }t	               }| j
                  j                  | j                  |d       | j                  t        |j                        d       | j                  d	|j                  d          | j                  d
|j                  d          d d d        ||_        y # 1 sw Y   ||_        y xY w)Nr   )r]   zpluginapp/link/bugs.htmlr   rw   rx   r-   rz   TemplateSyntaxErrorzInvalid block tag on line 1)9cms.test_utils.project.pluginapp.plugins.link.cms_pluginsr]   render_templater|   r   r(   r}   r9   r%   r~   r   r#   )r   r]   link_templater   r   s        r   Htest_exception_in_template_rendering_creates_error_log_and_does_not_failz^TestExceptionCatchers.test_exception_in_template_rendering_creates_error_log_and_does_not_fail   s    	
 #22%?
"__37_C 	It$YNMM,,T-?-?QUVS-q1MM/Q@MM7QH	I &3
"	I &3
"s   BCC"c                    t               }| j                  dd      5  | j                  j                  | j                  |dd      }d d d        | j                  | j                  j                  j                         | j                  d       | j                  d|       | j                  d	|       y # 1 sw Y   oxY w)
Nr   rw   rx   r-   Teditablez%<div class="cms-rendering-exception">ZeroDivisionErrorzdivision by zero)	r   r|   r(   r}   r9   r6   rs   edit_mode_activer#   r   r   markups      r   8test_exception_in_plugin_render_shows_error_in_edit_modezNTestExceptionCatchers.test_exception_in_plugin_render_shows_error_in_edit_mode   s     __37_C 	o]]55d6H6H.Z^im5nF	o-->>?=vF)62(&1	o 	os   *B66B?c                     t               }| j                  dd      5  | j                  j                  | j                  |dd      }d d d        | j                  d       y # 1 sw Y   xY w)Nr   rw   rx   r-   Fr    )r   r|   r(   r}   r9   r%   r   s      r   9test_exception_in_plugin_render_is_silent_in_preview_modezOTestExceptionCatchers.test_exception_in_plugin_render_is_silent_in_preview_mode   sh     __37_C 	p]]55d6H6H.Z^in5oF	pV$	p 	ps   *A##A,c                 <   t               }| j                  | j                  j                  d      d| j                        | _        t        | j                        | j                  _        | j                  | j                        | _        | j                  dd      5  | j                  j                  | j                  |dd      }d d d        | j                  | j                  j                  j                         | j                  d       y # 1 sw Y   KxY w)	Nr-   r   r   rw   rx   Fr   r   )r   r   r7   r   r   r   rs   r   r(   r|   r}   r9   rY   r   r%   r   s      r   6test_exception_in_plugin_render_is_silent_in_live_modezLTestExceptionCatchers.test_exception_in_plugin_render_is_silent_in_live_mode   s     ''MM**40 ( 

  *$,,7++DLL9__37_C 	p]]55d6H6H.Z^in5oF	p..??@V$	p 	ps   *DDF)CMS_CATCH_PLUGIN_500_EXCEPTIONc                    t               }| j                  | j                  j                  d      d| j                        | _        t        | j                        | j                  _        | j                  | j                        | _        | j                  t              5  | j                  dd      5  | j                  j                  | j                  |dd       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr-   r   r   rw   rx   Fr   )r   r   r7   r   r   r   rs   r   r(   assertRaisesr   r|   r}   r9   )r   r   s     r   7test_exception_in_plugin_render_is_raised__in_live_modezMTestExceptionCatchers.test_exception_in_plugin_render_is_raised__in_live_mode   s     ''MM**40 ( 

  *$,,7++DLL901 	k!7wG k001C1C^UYdi0jk	k 	kk k	k 	ks$    C;4*C/C;/C8	4C;;DN)r&   rM   rN   r	   r   rt   r   r   r   r   r   r   r   r   rO   r   r   rn   rn      sG    $N :D	+Q32%% e<k =kr   rn   c                       e Zd ZeZy)TestLegacyRendererNr&   rM   rN   r
   r   rO   r   r   r   r         #Nr   r   c                       e Zd ZeZy)"TestLegacyRendererExceptionCatcherNr   rO   r   r   r   r     r   r   r   N)collectionsr   django.templater   django.test.utilsr   cms.apir   r   
cms.modelsr   cms.plugin_renderingr	   r
   r   cms.test_utils.testcasesr   $cms.test_utils.util.context_managersr   cms.toolbar.toolbarr   cms.toolbar.utilsr   r   rQ   rn   r   r   rO   r   r   <module>r      st     # / +   
 1 J * 1>(K >(B=d/ =d@pkK pkf$, $$)> $r   