
    Bh                      4   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZmZmZ ed        Z G d de      Z G d de      Z  G d d      Z! G d de!e	      Z" G d de!e	      Z#y)    )contextmanager)deepcopy)settings)ImproperlyConfigured)TestCase)
TextPlugin)
add_plugin)Placeholder)	CMSPlugin)CMSPluginBase)plugin_pool)MyPageExtension)ArticlePluginModel)FileOutputWrapperFileSectionWrappercheckc               '      K   | D ]  }t        j                  |        	 d  | D ]  }t        j                  |        y # | D ]  }t        j                  |        w xY wwN)r   register_pluginunregister_plugin)pluginsplugins     D/home/dcms/DCMS/lib/python3.12/site-packages/cms/tests/test_check.pyregister_pluginsr      se      ,##F+,2 	2F))&1	2g 	2F))&1	2s   A"A A"AA"c                   *     e Zd Z fdZd Zd Z xZS )
TestOutputc                 <    t         |   d d        t        | _        y r   )super__init__TestSectionOutputsection_wrapper)self	__class__s    r   r   zTestOutput.__init__   s    t$0    c                      y r    r"   messages     r   writezTestOutput.write#       r$   c                      y r   r&   r'   s     r   write_stderrzTestOutput.write_stderr&   r*   r$   )__name__
__module____qualname__r   r)   r,   __classcell__)r#   s   @r   r   r      s    1r$   r   c                       e Zd Zd Zd Zy)r    c                      y r   r&   r'   s     r   r)   zTestSectionOutput.write+   r*   r$   c                      y r   r&   r'   s     r   r,   zTestSectionOutput.write_stderr.   r*   r$   N)r-   r.   r/   r)   r,   r&   r$   r   r    r    *   s    r$   r    c                       e Zd Zd Zy)CheckAssertMixinc                     t               }t        |       | j                  |j                  |       |j	                         D ]4  \  }}| j                  t        ||      || d| dt        ||              6 y)z
        asserts that checks are successful or not
        Assertions is a mapping of numbers to check (eg successes=5)
         z expected, got N)r   r   assertEqual
successfulitemsgetattr)r"   r9   
assertionsoutputkeyvalues         r   assertCheckzCheckAssertMixin.assertCheck3   s{    
 f**J7$**, 	qJCWVS15UG1SEY`agilYmXn:op	qr$   N)r-   r.   r/   r@   r&   r$   r   r5   r5   2   s    	qr$   r5   c                   f    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zy)
CheckTestsc                 ,    | j                  ddd       y )NTr   )errorswarnings)r@   r"   s    r   test_test_confszCheckTests.test_test_confs@   s    a!4r$   c                     t        t        j                        }|j                  d       | j                  |      5  | j	                  dd       d d d        y # 1 sw Y   y xY w)Nsekizai)INSTALLED_APPSF   rD   )listr   rJ   remover@   )r"   appss     r   test_no_sekizaizCheckTests.test_no_sekizaiC   sT    H++,I]]$]/ 	.U1-	. 	. 	.s   AA#c                     dt        t        j                        i}ddg|d   d   d   d<    | j                  d
i |5  | j                  dd	       d d d        y # 1 sw Y   y xY w)N	TEMPLATES"sekizai.context_processors.sekizai#cms.context_processors.cms_settingsr   OPTIONScontext_processorsFrK   rL   r&   r   r   rR   r@   r"   overrides     r   %test_no_django_i18n_context_processorz0CheckTests.test_no_django_i18n_context_processorJ   su    (*<*<!=>01E
a +,@A T]]&X& 	.U1-	. 	. 	.   AA$c                     dt        t        j                        i}ddg|d   d   d   d<    | j                  d
i |5  | j                  dd	       d d d        y # 1 sw Y   y xY w)NrR   rS   'django.template.context_processors.i18nr   rU   rV   FrK   rL   r&   rW   rX   s     r   &test_no_cms_settings_context_processorz1CheckTests.test_no_cms_settings_context_processorS   su    (*<*<!=>05E
a +,@A T]]&X& 	.U1-	. 	. 	.r[   c                     dt        t        j                        i}ddg|d   d   d   d<    | j                  d
i |5  | j                  dd	       d d d        y # 1 sw Y   y xY w)NrR   rT   r]   r   rU   rV   F   rL   r&   rW   rX   s     r   *test_no_sekizai_template_context_processorz5CheckTests.test_no_sekizai_template_context_processor\   su    (*<*<!=>15E
a +,@A T]]&X& 	.U1-	. 	. 	.r[   c                     | j                  dg      5  | j                  t        | j                  ddd       d d d        y # 1 sw Y   y xY w)N)enEnglish)CMS_LANGUAGESTrK   r   rE   rD   )r   assertRaisesr   r@   rF   s    r   test_old_style_i18n_settingsz'CheckTests.test_old_style_i18n_settingse   sO    ]]*;)<]= 	b2D4D4DdUV_`a	b 	b 	bs   %AAc                     g d}| j                  ddd       | j                  |      5  | j                  ddd       d d d        y # 1 sw Y   y xY w)N)z-django.middleware.cache.UpdateCacheMiddlewarez/django.middleware.http.ConditionalGetMiddlewarez4django.contrib.sessions.middleware.SessionMiddlewarez7django.contrib.auth.middleware.AuthenticationMiddlewarez4django.contrib.messages.middleware.MessageMiddlewarez)django.middleware.csrf.CsrfViewMiddlewarez)django.middleware.locale.LocaleMiddlewarez)django.middleware.common.CommonMiddlewarez)cms.middleware.page.CurrentPageMiddlewarez(cms.middleware.toolbar.ToolbarMiddlewarez0django.middleware.cache.FetchFromCacheMiddlewareTr   rf   )
MIDDLEWAREFr`   r@   r   )r"   rj   s     r   test_middlewareszCheckTests.test_middlewaresi   sX    

 	!4]]j]1 	:UQq9	: 	: 	:s   A		Ac                     | j                  ddd       t        j                  }t        `| j                  ddd       |t        _        y)zG
        this is ugly, feel free to come up with a better test
        Tr   rf   r`   N)r@   r   copy_relationsr"   copy_rels     r   test_copy_relations_fk_checkz'CheckTests.test_copy_relations_fk_check{   sH     	!4%44-!4,4)r$   c                     | j                  ddd       t        j                  }t        `| j                  ddd       |t        _        y)z3
        Agreed. It is ugly, but it works.
        Tr   rf   rK   N)r@   r   rn   ro   s     r   %test_copy_relations_on_page_extensionz0CheckTests.test_copy_relations_on_page_extension   sG     	!4"11*!4)1&r$   c                     | j                  ddd       | j                  d      5  | j                  ddd       d d d        y # 1 sw Y   y xY w)NTr   rf   broken)SITE_IDFrK   rk   rF   s    r   test_non_numeric_site_idz#CheckTests.test_non_numeric_site_id   sO    !4]]8], 	:UQq9	: 	: 	:s   AAc                     ddl m} ddlm}  G d d|      }|j	                  |      }| j                  ddd       |j                  j                  |j                         y )	Nr   )CMSApp)apphook_poolc                       e Zd ZddZy)5CheckTests.test_cmsapps_check.<locals>.AppWithoutNameNc                     dgS )Nzsampleapp.urlsr&   )r"   pagelanguagekwargss       r   get_urlsz>CheckTests.test_cmsapps_check.<locals>.AppWithoutName.get_urls   s    ())r$   )NN)r-   r.   r/   r   r&   r$   r   AppWithoutNamer|      s    *r$   r   TrK   rf   )	cms.app_basery   cms.apphook_poolrz   registerr@   rO   popr-   )r"   ry   rz   r   apps        r   test_cmsapps_checkzCheckTests.test_cmsapps_check   sS    '1	*V 	* ##N3!4cll+r$   c                      G d dt               } G d dt               }t        ||      5  | j                  dd       d d d        y # 1 sw Y   y xY w)Nc                       e Zd ZdZdZy)LCheckTests.test_validate_template_invalid_parent_class.<locals>.ParentPlugin	base.htmlTN)r-   r.   r/   render_templateallow_childrenr&   r$   r   ParentPluginr      s    )O!Nr$   r   c                       e Zd ZdZdZy)KCheckTests.test_validate_template_invalid_parent_class.<locals>.ChildPluginr   NonExistentPluginNr-   r.   r/   r   parent_classesr&   r$   r   ChildPluginr      s    )O3Nr$   r   TrK   rE   r   r   r@   r"   r   r   s      r   +test_validate_template_invalid_parent_classz6CheckTests.test_validate_template_invalid_parent_class   sN    	"= 	"	4- 	4 lK8 	/TA.	/ 	/ 	/   AAc                      G d dt               } G d dt               }t        ||      5  | j                  dd       d d d        y # 1 sw Y   y xY w)Nc                       e Zd ZdZdZdZy)KCheckTests.test_validate_template_invalid_child_class.<locals>.ParentPluginr   Tr   Nr-   r.   r/   r   r   child_classesr&   r$   r   r   r      s    )O!N2Mr$   r   c                       e Zd ZdZdZy)JCheckTests.test_validate_template_invalid_child_class.<locals>.ChildPluginr   r   Nr   r&   r$   r   r   r          )O.Nr$   r   TrK   r   r   r   s      r   *test_validate_template_invalid_child_classz5CheckTests.test_validate_template_invalid_child_class   sN    	3= 	3
	/- 	/ lK8 	/TA.	/ 	/ 	/r   c                      G d dt               } G d dt               }t        ||      5  | j                  dd       d d d        y # 1 sw Y   y xY w)Nc                       e Zd ZdZdZdZy)RCheckTests.test_validate_template_valid_parent_child_classes.<locals>.ParentPluginr   T)r   Nr   r&   r$   r   r   r      s    )O!N,Mr$   r   c                       e Zd ZdZdZy)QCheckTests.test_validate_template_valid_parent_child_classes.<locals>.ChildPluginr   r   Nr   r&   r$   r   r   r      r   r$   r   Tr   r   r   r   s      r   1test_validate_template_valid_parent_child_classesz<CheckTests.test_validate_template_valid_parent_child_classes   sN    	-= 	-
	/- 	/ lK8 	/TA.	/ 	/ 	/r   c                      G d dt               }t        |      5  | j                  dd       d d d        y # 1 sw Y   y xY w)Nc                       e Zd ZdZdZy)OCheckTests.test_plugin_parent_child_relations_empty_string.<locals>.ChildPluginr   ) Nr   r&   r$   r   r   r      s    )O"Nr$   r   Tr   r   r   )r"   r   s     r   /test_plugin_parent_child_relations_empty_stringz:CheckTests.test_plugin_parent_child_relations_empty_string   s@    	#- 	# k* 	/TA.	/ 	/ 	/s	   8AN)r-   r.   r/   rG   rP   rZ   r^   ra   rh   rl   rq   rs   rw   r   r   r   r   r   r&   r$   r   rB   rB   ?   sN    5....b:$52:
,
////r$   rB   c                       e Zd Zd Zy)CheckWithDatabaseTestsc                    | j                  ddd       t        j                  j                  d      }t	        |t
        dd       t	        |t
        dd       t	        |d	dd
d       t        dd      }|j                          | j                  ddd       t        dd      }|j                          | j                  ddd       y )NTr   rf   test)slotrc   zen body)body
LinkPluginzA Linkzhttps://www.django-cms.org)nameexternal_linkr   )r   plugin_typeFr`   BogusPlugin   )r@   r
   objectscreater	   r   r   save)r"   placeholderinstanceless_pluginbogus_plugins       r   test_check_plugin_instancesz2CheckWithDatabaseTests.test_check_plugin_instances   s    !4!))00f0=;
DyA;
DyA;dQmn (<P  "15 !$MJ15r$   N)r-   r.   r/   r   r&   r$   r   r   r      s    6r$   r   N)$
contextlibr   copyr   django.confr   django.core.exceptionsr   django.testr   #djangocms_text_ckeditor.cms_pluginsr   cms.apir	   cms.models.placeholdermodelr
   cms.models.pluginmodelr   cms.plugin_baser   cms.plugin_poolr   *cms.test_utils.project.extensionapp.modelsr   >cms.test_utils.project.pluginapp.plugins.manytomany_rel.modelsr   cms.utils.checkr   r   r   r   r   r    r5   rB   r   r&   r$   r   <module>r      s    %    7   :  3 , ) ' F ] H H 2 2	" 	* 
q 
qN/!8 N/b6-x 6r$   