
    Bh                     t   d dl 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mZ 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! 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- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5 dZ6dZ7dZ8dZ9 G d de-      Z: G d d e-      Z;y)!    N)get_user_model)
Permission)Site)checks)cache)check_url_config)override_settings)NoReverseMatchclear_url_cachesresolvereverse)now)override)AdvancedSettingsForm)create_pagecreate_page_content)CMSApp)apphook_pool)applications_page_checkclear_app_resolversget_app_patterns)get_page)PageContent)Example1)CMSTestCase)DumbPageLanguageUrl)
CMSToolbar)	menu_pool)DefaultLanguageChanger	SampleAppNamespacedAppz)cms.test_utils.project.sampleapp.cms_appsz*cms.test_utils.project.sampleapp.cms_menusc                   f   e Zd Zd Zd Zd Zd?dZ ed      d        Z ee	 d	e
 g
      d        Z edgd      d        Zd Zd Z ed      d        Z ed      d        Z ed      d        Z ed      d        Z ed      d        Z ed      d        Zd Z ee	 d	e
 g
      d        Z ed      d        Z ed      d        Z ed      d        Z ed      d        Z ed      d         Z ed      d!        Z ed      d"        Z ed      d#        Z ed      d$        Z ed%d&'      d(        Z  ed)      d*        Z! ed)      d+        Z" ed,      d-        Z# ed      d.        Z$d/ Z% ed      d0        Z& ed      d1        Z' ed      d2        Z( ed3      d4        Z) ed3      d5        Z* ed6gd37      d8        Z+d9 Z, ed      d:        Z- ed      d;        Z. ed<g
      d=        Z/ ed<g
      d>        Z0y)@ApphooksTestCasec                     t                t                t        t        j                  v rt        j                  t        = | j                          | j                          y Nr   r   
APP_MODULEsysmodulesreload_urlsapphook_clearselfs    G/home/dcms/DCMS/lib/python3.12/site-packages/cms/tests/test_apphooks.pysetUpzApphooksTestCase.setUp#   >    $J'    c                     t                t                t        t        j                  v rt        j                  t        = | j                          | j                          y r%   r&   r,   s    r.   tearDownzApphooksTestCase.tearDown-   r0   r1   c                     ddl m} dddt        |j                  g}t	                t                |D ]&  }|t        j                  v st        j                  |= ( y )Nr   settingscms.urls8cms.test_utils.project.second_cms_urls_for_apphook_tests-cms.test_utils.project.urls_for_apphook_tests)django.confr6   r'   ROOT_URLCONFr   r   r(   r)   r-   r6   url_modulesmodules       r.   r*   zApphooksTestCase.reload_urls7   s[    ( 
 G;!!

 	! 	(F$KK'	(r1   Nc           	      N   | j                          t               j                  j                  ddd      }|| _        t        ddd|      }t        d|j                         |       t        ddd||	      }t        d|j                         |       t        d
dd||||      }t        d|j                         |       | j                  |      }t        |t              r|j                  |      }n|D 	cg c]  }	|j                  |	       }}	| j                          |S c c}	w )Nadminadmin@admin.comhomenav_playground.htmlen
created_byde
child_pagerF   parentchild_child_pagerF   rJ   apphookapphook_namespace)r+   r   objectscreate_superuser	superuserr   r   	get_titlereload
isinstancestrget_content_objr*   )
r-   rM   content_langs	namespacerQ   pagerH   rK   contentslangs
             r.   create_base_structurez&ApphooksTestCase.create_base_structureM   s   "$,,==gGXZab	"6#8$&/1D$.."2D9 /Dd,5dD
D*"6"6"8*E&'9;P'+	*^e9BD 	D"2"<"<">@PQ;;'78mS)'77FHKXY4(88>YHY	 Zs   6D"z4cms.test_utils.project.fourth_urls_for_apphook_testsr;   c                 p    | j                          t        d      }| j                  t        |      d       y)z-
        Test for urls config check.
        Nr   )r+   r   assertEquallen)r-   results     r.   test_check_url_configz&ApphooksTestCase.test_check_url_configg   s.    
 	!$'Va(r1   .)CMS_APPHOOKSc                     | j                          t        j                         }|D cg c]  }|d   	 }}| j                  t	        |      d       | j                  |t
        g       | j                          yc c}w )zN
        Test explicit apphook loading with the CMS_APPHOOKS setting.
        r      N)r+   r   get_apphooksr_   r`   APP_NAMEr-   hookshook	app_namess       r.   test_explicit_apphooksz'ApphooksTestCase.test_explicit_apphooksp   sl    
 	))+)./T!W/	/UQ'XJ/ 0s   A: cms.test_utils.project.sampleappr9   )INSTALLED_APPSr;   c                 (   | j                          t        j                         }|D cg c]  }|d   	 }}| j                  t	        |      d       | j                  t        |       | j                  t        |       | j                          yc c}w )zO
        Test implicit apphook loading with INSTALLED_APPS cms_apps.py
        r   	   N)r+   r   rg   r_   r`   assertInNS_APP_NAMErh   ri   s       r.   test_implicit_apphooksz'ApphooksTestCase.test_implicit_apphooks|   sv     	))+)./T!W/	/UQ'k9-h	*	 0s   Bc                    | j                          t               j                  j                  ddd      }| j	                  ddd|d      }t        ddd|d	d
       |j                  j                         d   }| j                  |j                  d       t        dd|       t        d      5  | j                  j                  | j                               }d d d        | j                  d       | j!                  |d       | j                  j                  d      }| j                  |d       | j                          y # 1 sw Y   kxY w)Nr@   rA   apphooked-pagerC   rD   r    rF   rM   znot-apphooked-page blankapp)rF   rM   slugr   rG   aphooked-page-desampleapp/home.htmlz<--noplaceholder-->z/en/blankapp/)r+   r   rO   rP   create_homepager   pagecontent_setallr_   languager   force_languageclientgetget_pages_rootassertTemplateUsedassertContains)r-   rQ   rY   english_titleresponses        r.   test_apphook_on_homepagez)ApphooksTestCase.test_apphook_on_homepage   s-   "$,,==gGXZab	##$46KT/8+ $ O(*?(":	G,,00215//6D"4d;D! 	>{{t':':'<=H	>*?@H&;<;;???3*?@	> 	>s   .*EEc                 
   ddl m} ddlm} ddlm} d}| j                  |dgd      \  }|j                  j                  dd	
      } |d|j                  |j                  f      }| j                  ||j                         y)ztest rendering the apphook without landing page.

        tests for https://github.com/django-cms/django-cms/issues/7765
        r   )ContentType)views)admin_reverseSampleAppWithoutLandingPagerD   zapphook-without-landingcmspagecontent)	app_labelmodel"cms_placeholder_render_object_edit)argsN)"django.contrib.contenttypes.modelsr   r   r   cms.utils.urlutilsr   r\   rO   r   pkassertIsNotdetails)r-   r   r   r   rh   contentcontent_typeendpoints           r.   !test_apphook_without_landing_pagez2ApphooksTestCase.test_apphook_without_landing_page   s    
 	C40..tf7
	 #**..m.T !E\__^e^h^hLjk 	5==1r1   c                     | j                          t               j                  j                  ddd      }t	        ddd|d       | j                          t        j                          | j                          y )Nr@   rA   rv   rC   rD   r    rw   )r+   r   rO   rP   r   r*   r   
run_checksr-   rQ   s     r.   )test_apphook_does_not_crash_django_checksz:ApphooksTestCase.test_apphook_does_not_crash_django_checks   sh     	"$,,==gGXZab	$&;T(+	?r1   c                 :   | j                          t               j                  j                  ddd      }t	        ddd|d      }t        dd	|       | j                          | j                  t        d
      j                  d             | j                          y )Nr@   rA   rv   rC   rD   r    rw   rG   r{   sample-settingsz//)
r+   r   rO   rP   r   r   r*   assertFalser   
startswith)r-   rQ   rY   s      r.   test_apphook_on_root_reversez-ApphooksTestCase.test_apphook_on_root_reverse   s    "$,,==gGXZab	+-BD&/FD"4d;!23>>tDEr1   c           	         | j                          t        j                  j                  d      \  }}t        j                  j                  d      \  }}t	               j                  j                  ddd      }| j                         }||_        t        ddd||	      }t        ddd
||	      }t        ddd||t        d      }t        ddd
||      }	t        ddd
|||      }
t        dt        j                  t        fi       } t        t              dt        f|||d      } ||      }| j                  |j                  d              ||	      }| j!                  |j                  d              t        t              dt        f|||d      } ||
      }| j                  |j                  d             | j                          y )Nrf   r      r@   rA   rB   rC   rD   )rF   siterG   rv   instancerL   rI   )rF   rJ   r   Metar   )r   _site_request)r   )r+   r   rO   get_or_creater   rP   get_requestuserr   rs   typer   r   objectr    _check_unique_namespace_instance
assertTrue)r-   site1_site2rQ   requesthome_site_1home_site_2page_a_1page_a_2page_b_1r   	formClassforms                 r.   test_multisite_apphooksz(ApphooksTestCase.test_multisite_apphooks   s   <<---3q<<---3q"$,,==gGXZab	""$ !)4IE
 ")4IE
 3TiXc:
 3TiXc
 3TiXc
 F166?D.D-."!#Ew?
	
 (+>>zJK(+==jIJ.D-."!#Ew?
	
 (+>>zJKr1   z4cms.test_utils.project.second_urls_for_apphook_testsc                    | j                  t        ddg      \  }}t        d      5  t        d      }| j	                  |      }d|_        t        |      }d d d        | j                  j                  |j                  j                         | j                  j                        }| j                  |j                  d       | j                  |d       | j                  ||j                         t        d      5  t        d      }| j	                  |      }d|_        t        |      }d d d        | j                  |j                  |j                  j                         | j                  j                  |      }| j                  |j                  d       | j                  |d       | j                  ||j                         | j!                          y # 1 sw Y   xY w# 1 sw Y   xY w)NrD   rG   r      r|   )r\   rh   r   r   r   LANGUAGE_CODEr   r_   r   rY   r   r   status_coder   r   titler+   )r-   en_titlede_titlepathr   attached_to_pager   s          r.   test_get_page_for_apphookz*ApphooksTestCase.test_get_page_for_apphook   s   !774,O(D! 	@,-D&&t,G$(G!6w?		@
 	),,hmm.>.>?;;??4(--s3*?@Hhnn5D! 	@,-D&&t,G$(G!6w?		@
 	),,hmm.>.>?;;??4(--s3*?@Hhnn5/	@ 	@	@ 	@s   /G>/G(G%(G1c                    | j                  t        ddg      \  }}t        d      5  t        d      }d d d        | j                  j                        }| j                  |j                  d       |j                  j                  d       | j                  j                  |      }| j                  |j                  d       | j                          y # 1 sw Y   xY w)NrD   rG   r   r   Tlogin_required.  )r\   rh   r   r   r   r   r_   r   rY   updater+   )r-   r   r   r   r   s        r.   test_apphook_permissionsz)ApphooksTestCase.test_apphook_permissions  s    !774,O(D! 	.,-D	. ;;??4(--s3D1;;??4(--s3	. 	.s   CCc                    | j                  t        ddg       d}t        d      5  |D ]A  \  }}t        |      }t	        |      }| j                  |j                  j                  |       C 	 d d d        y # 1 sw Y   y xY w)NrD   rG   ))r   sample_view)zsample-class-view	ClassView)zsample-class-based-viewview)r\   rh   r   r   r   r_   func__name__)r-   
view_namesurl_name	view_namer   matchs         r.   ,test_apphook_permissions_preserves_view_namez=ApphooksTestCase.test_apphook_permissions_preserves_view_name+  s    ""8dD\:

 D! 	A'1 A#)x(  !4!4i@A	A 	A 	As   AA77B c                    | j                  dd      }t        d      5  t        d      }t        d      }d d d        |j                  j	                  d       | j
                  j                        }| j
                  j                        }| j                  |j                  d       | j                  |j                  d       | j                          y # 1 sw Y   xY w)	N SampleAppWithExcludedPermissionsrD   zexcluded:exampleznot_excluded:exampleTr   r   r   )
r\   r   r   rY   r   r   r   r_   r   r+   )r-   r   excluded_pathnot_excluded_pathexcluded_responsenot_excluded_responses         r.   'test_apphooks_with_excluded_permissionsz8ApphooksTestCase.test_apphooks_with_excluded_permissions<  s    --.PRVWD! 	@#$67M '(> ?	@ 	D1 KKOOM: $0A B*66<.::C@	@ 	@s   CC!c                 N   t         j                   G d dt                     }t         j                   G d dt                     }t        j                         }t	        |      }| j                  |j                  d      d       | j                  |j                  d      d       y)zQ
        Test that an apphook without a name defaults to the class name.
        c                       e Zd ZddZy)YApphooksTestCase.test_apphook_without_name_defaults_to_class_name.<locals>.AppWithoutNameNc                     dgS Nzsampleapp.urls r-   rY   r   kwargss       r.   get_urlszbApphooksTestCase.test_apphook_without_name_defaults_to_class_name.<locals>.AppWithoutName.get_urlsR      ())r1   NN)r   
__module____qualname__r   r   r1   r.   AppWithoutNamer   P  s    *r1   r   c                       e Zd ZdZddZy)VApphooksTestCase.test_apphook_without_name_defaults_to_class_name.<locals>.AppWithNameCustom nameNc                     dgS r   r   r   s       r.   r   z_ApphooksTestCase.test_apphook_without_name_defaults_to_class_name.<locals>.AppWithName.get_urlsY  r   r1   r   )r   r   r   namer   r   r1   r.   AppWithNamer   U  s     D*r1   r   r   N)r   registerr   rg   dictr_   r   )r-   r   r   rj   
hook_namess        r.   0test_apphook_without_name_defaults_to_class_namezAApphooksTestCase.test_apphook_without_name_defaults_to_class_nameK  s    
 
			*V 	* 
	* 
			*& 	* 
	* ))+%[
(89;KL6Fr1   zcms.test_utils.project.urls_3c                    t               j                  dk(  r&t               j                  j                  ddd      }n%t               j                  j                  ddd      }t	        ddd|t
              }t        d|j                         |       t        d      5  t        d	      }| j                  |      }d|_        t        |      }| j                  |j                  |j                         d d d        t        d      5  t        d	      }| j                  |      }d|_        t        |      }| j                  |j                  |j                         d d d        | j                  |      5  t        d      5  t        d	      }| j                  |      }d|_        t        |      }| j                  |j                  |j                         d d d        t        d      5  t        d	      }| j                  |      }d|_        t        |      }| j                  |j                  |j                         d d d        d d d        y # 1 sw Y   ]xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   8xY w# 1 sw Y   y xY w)
Nemailr@   rA   rB   rC   rD   rw   rG   r   )r   USERNAME_FIELDrO   rP   r   rh   r   rR   r   r   r   r   r   r_   r   login_user_context)r-   rQ   rY   r   r   r   s         r.   ,test_get_page_for_apphook_on_preview_or_editz=ApphooksTestCase.test_get_page_for_apphook_on_preview_or_edita  sA   **g5&(00AA'K\^opI&(00AA'K\^efI6#8$&/CD$.."2D9D! 	;,-D&&t,G$(G!6w?-00$'':	; D! 	;,-D&&t,G$(G!6w?-00$'':	; $$Y/ 	?% ?01**40(,%#:7#C   !1!4!4dgg>?  % ?01**40(,%#:7#C   !1!4!4dgg>?	? 	?	; 	;	; 	;? ?? ?	? 	?sX   AIAI3I??AI'I?'AI3<I?II$'I0	,I?3I<	8I??Jc                    | j                  t        dd      }| j                          t        d      5  t	        d       t	        d       t	        d       t	        d      }t	        d      }d d d        | j                         | j                  |      }d|_        t        |      }| j                  |j                  |j                  j                         | j                          y # 1 sw Y   xY w)NrD   instance_nszexample_app:examplezexample1:examplezexample2:exampleznamespaced_app_ns:sample-rootzinstance_ns:sample-root)r\   rs   r*   r   r   r_   r   r   r   r   rY   r+   )r-   r   r   path_instancer   r   s         r.   6test_get_root_page_for_apphook_with_instance_namespacezGApphooksTestCase.test_get_root_page_for_apphook_with_instance_namespace  s    --k4OD! 	?)*&'&':;D#$=>M	? 	}-""4( $27;),,hmm.>.>?	? 	?s   8C))C2c                    | j                  t        dd      }t        d      5  t        d      }t        d      }t        dd      }d d d        | j	                         | j	                  |       | j                  |      }d|_        t        |      }| j	                  |j                  |j                         | j                          y # 1 sw Y   xY w)NrD   r  !namespaced_app_ns:sample-settingszinstance_ns:sample-settingscurrent_app)r\   rs   r   r   r_   r   r   r   r   page_idr+   )r-   r   r   path_instance1path_instance2r   r   s          r.   7test_get_child_page_for_apphook_with_instance_namespacezHApphooksTestCase.test_get_child_page_for_apphook_with_instance_namespace  s    --k4OD! 	e>?D$%BCN$%HVcdN	e 	~.~.""4( $27;),,h.>.>?	e 	es   $CCc                 (   | j                  t        dd      }t        d      5  t        d      }d d d        | j	                        }d|_        t        |      }| j                  |j                  |j                  j                         | j                  j                  |      }| j                  |j                  d       | j                  |d       | j                  |d       | j                  ||       | j                          y # 1 sw Y   xY w)NrD   namespaced_app_nsnamespaced_app_ns:current-appr   sampleapp/app.htmlr\   rs   r   r   r   r   r   r_   r   rY   r   r   r   r   r   r+   r-   r   r   r   r   r   s         r.   7test_get_sub_page_for_apphook_with_implicit_current_appzHApphooksTestCase.test_get_sub_page_for_apphook_with_implicit_current_app  s    --k4ATUD! 	<:;D	<""4( $27;),,hmm.>.>?;;??4(--s3*>?H&9:Hd+	< 	<   DDc                    | j                  t        ddgd       | j                          t        d      5  t	        d      }d d d        | j                        }d|_         t        |      d      }| j                  ||        t        |      d      }| j                  |d|dd  j                  dd      z         | j                          y # 1 sw Y   xY w)	NrD   rG   r  z namespaced_app_ns:translated-urlz/de%s   z/pagez/Seite)r\   rs   r*   r   r   r   r   r   r_   replacer+   )r-   r   r   urls       r.   7test_default_language_changer_with_implicit_current_appzHApphooksTestCase.test_default_language_changer_with_implicit_current_app  s    "";t>QRD! 	?=>D	?""4( $-$W-d3d#-$W-d3gQR(8(8((KKL	? 	?s   CCc           	      N   | j                          | j                  t        ddgd      }|d   }t        j                  j                  |j                  d      }| j                          | j                          t        ddd| j                  |j                  j                  t        d	      }t        dd
|d       t                t                t        t        j                   v rt        j                   t        = | j                          t#        d      5  t%        dd       t%        dd       t%        d       d d d        t#        d      5  t%        dd       t%        dd       t%        d       d d d        | j                          y # 1 sw Y   SxY w# 1 sw Y   &xY w)NrD   rG   
instance_1rf   )rY   r   page2rC   
instance_2)r   rF   rJ   rM   rN   r   rz   rz   r  r  )r+   r\   rs   r   rO   r   rY   r*   r   rQ   rJ   r   r   r   r'   r(   r)   r   r   )r-   titlespublic_de_titler   r  s        r.   /test_get_i18n_apphook_with_explicit_current_appz@ApphooksTestCase.test_get_i18n_apphook_with_explicit_current_app  s\   ++K$|T )&&**0D0Dt*TG1%)'+~~#+==#7#7$/.:< 	D*e&A$J'D! 	53N3N34	5 D! 	53N3N34	5 		5 	5	5 	5s   &F&FFF$c                 r   | j                  t        ddgd       t        d      5  t        d      }d d d        | j	                        }d|_        | j                  j                  |      }| j                  |j                  d       | j                  |d       | j                  |d       y # 1 sw Y   }xY w)NrD   rG   r  znamespaced_app_ns:extra_secondr   sampleapp/extra.htmlsomeopts)r\   rs   r   r   r   r   r   r   r_   r   r   r   )r-   r   r   r   s       r.   %test_apphook_include_extra_parametersz6ApphooksTestCase.test_apphook_include_extra_parameters  s    "";tlKD! 	=;<D	=""4( $;;??4(--s3*@AHj1	= 	=s   B--B6c                 (   | j                  t        dd      }t        d      5  t        d      }d d d        | j	                        }d|_        t        |      }| j                  |j                  |j                  j                         | j                  j                  |      }| j                  |j                  d       | j                  |d       | j                  |d       | j                  ||       | j                          y # 1 sw Y   xY w)NrD   r  r  r   r  r  r  s         r.   7test_get_sub_page_for_apphook_with_explicit_current_appzHApphooksTestCase.test_get_sub_page_for_apphook_with_explicit_current_app  s    --k4OD! 	<:;D	< ""4( $27;),,hmm.>.>?;;??4(--s3*>?Hm4Hd+	< 	<r  c                     | j                  t        d       t        d      }| j                  j	                  |      }| j                  |j                  d       | j                  |d       | j                  |d       t        d      }| j                  j	                  |      }| j                  |j                  d       | j                  |d       | j                  |d       t        d      5  t        d      }d d d        | j                  j	                  |      }| j                  |j                  d       | j                  |d       | j                  |d       t        d      5  t        d      }d d d        | j                  j	                  |      }| j                  |j                  d       | j                  |d       | j                  |d       | j                          y # 1 sw Y   xY w# 1 sw Y   xY w)	NrD   extra_secondr   r#  test included urlconfextra_firstztest urlconfrG   )r\   rh   r   r   r   r_   r   r   r   r   r+   r-   r   r   s      r.   test_include_urlconfz%ApphooksTestCase.test_include_urlconf  s   ""8T2~&;;??4(--s3*@AH&=>}%;;??4(--s3*@AHn5D! 	*=)D	*;;??4(--s3*@AHn5D! 	+>*D	+;;??4(--s3*@AH&=>	* 	*	+ 	+s   .G((G4(G14G=Fzcms.test_utils.project.urls_2)CMS_PERMISSIONr;   c                 J   | j                  ddd      }t        ddd|      }t        ddd|      }t        ddd|d	       t        d      5  | j                          t	               }|d
   }|j                  d      }| j                  |d       d d d        y # 1 sw Y   y xY w)NrB   rC   rD   child)rJ   znot-homesubchildr    )rJ   rM   r   sample-rootzchild/not-home/subchild/)r}   r   r   r*   r   r   r_   )r-   rB   r0  not_homeurlpatternsresolverr  s          r.   6test_apphook_breaking_under_home_with_new_path_cachingzGApphooksTestCase.test_apphook_breaking_under_home_with_new_path_caching.  s    ##F,A4HG%:DNz+@$uUJ 5tHVabD! 	>*,K"1~H""=1CS"<=	> 	> 	>s   ABB"cms.test_utils.project.urlsc                     | j                  t        d       t        d      }| j                  j	                  |      }| j                  |j                  d       | j                  |d       | j                  |d       y )NrD   r)  r   r#  r*  )	r\   rh   r   r   r   r_   r   r   r   r,  s      r.   test_apphook_urlpattern_orderz.ApphooksTestCase.test_apphook_urlpattern_order<  sh    
 	""8T2~&;;??4(--s3*@AH&=>r1   c                    | j                  t        d       t        dt        d            }| j                  j                  |      }| j                  |j                  d       | j                  |d       | j                  |d       y )	NrD   zsample-paramsz.is-my-param-really-in-the-context-QUESTIONMARK)	my_paramsr   r   r|   z9my_params: is-my-param-really-in-the-context-QUESTIONMARK)
r\   rh   r   r   r   r   r_   r   r   r   r,  s      r.    test_apphooks_receive_url_paramsz1ApphooksTestCase.test_apphooks_receive_url_paramsH  sp     	""8T2t>n/op;;??4(--s3*?@H&abr1   z3cms.test_utils.project.third_urls_for_apphook_testsc                    | j                          t               j                  j                  ddd      }t	        ddd|       t	        ddd|d	       t	        d
dd|d	       t        d       t        d       | j                          y )Nr@   rA   rB   rC   rD   rE   zapphook1-pager    rw   zapphook2-page
SampleApp2r2  sample2-root)r+   r   rO   rP   r   r   r   s     r.   test_multiple_apphooksz'ApphooksTestCase.test_multiple_apphooksR  s     	"$,,==gGXZab	F14IPO%:D(+	?O%:D(,	@ 	r1   c                 v   | j                          t               j                  j                  ddd      }t	        ddd|d       | j                          t        d      }| j                  j                  |      }| j                  |j                  d	       | j                  |d
       | j                          y )Nr@   rA   zapphooked3-pagerC   rD   
SampleApp3rw   zsample3-rootr   zSample App 3 Response)r+   r   rO   rP   r   r*   r   r   r   r_   r   r   )r-   rQ   r   r   s       r.   "test_apphooks_return_urls_directlyz3ApphooksTestCase.test_apphooks_return_urls_directlya  s    "$,,==gGXZab	%'<d(,	@~&;;??4(--s3H&=>r1   c                    t         j                   G d dt                     }| j                  |       t         j                  j                  d       t         j                   G d dt                     }| j                  |       y )Nc                       e Zd ZdZy)LApphooksTestCase.test_apphook_pool_register_returns_apphook.<locals>.TestAppzTest AppNr   r   r   r   r   r1   r.   TestApprG  p  s    Dr1   rI  fooc                       e Zd ZdZy)MApphooksTestCase.test_apphook_pool_register_returns_apphook.<locals>.TestApp2z
Test App 2NrH  r   r1   r.   TestApp2rL  x  s    Dr1   rM  )r   r   r   assertIsNotNoneapphooksappend)r-   rI  rM  s      r.   *test_apphook_pool_register_returns_apphookz;ApphooksTestCase.test_apphook_pool_register_returns_apphooko  sr    				f 	 
	W% 	$$U+				 v 	  
	 X&r1   c                    | j                  t        dd       | j                  d      }t        d      5  t	        d      }d d d        |j                        }| j                  |j                  d       t        d      5  t	        d      }d d d        |j                  |      }| j                  |j                  d       y # 1 sw Y   xY w# 1 sw Y   CxY w)	NrD   r  T)enforce_csrf_checksnamespaced_app_ns:sample-exemptr   z namespaced_app_ns:sample-accounti  )r\   rs   client_classr   r   postr_   r   )r-   r   r   r   s       r.   !test_apphook_csrf_exempt_endpointz2ApphooksTestCase.test_apphook_csrf_exempt_endpoint}  s    "";mD""t"<D! 	><=D	> ;;t$ 	--s3D! 	?=>D	? ;;t$ 	--s3	> 	>	? 	?s   CCCCc                 4   | j                  t        dd       t        d      5  t        d      }d d d        | j	                        }t        |      }| j                  |j                  d   j                         | j                  |j                  d   j                         t        d      5  t        d      }d d d        | j	                  |      }t        |      }| j                  |j                  d   j                  d       | j                  |j                  d   j                         | j                  |j                  d   j                  d       | j                  |j                  d   j                         y # 1 sw Y   TxY w# 1 sw Y   xY w)NrD   r  r  =cms.test_utils.project.sampleapp.cms_toolbars.CategoryToolbarNcms.test_utils.project.extensionapp.cms_toolbars.MyPageContentExtensionToolbarrT  rn   )r\   rs   r   r   r   r   r   toolbarsis_current_appr   r_   app_pathr-   r   r   toolbars       r.   "test_toolbar_current_app_namespacez3ApphooksTestCase.test_toolbar_current_app_namespace  s}   "";mDD! 	@>?D	@""4(W%\]ll	
 	`n	
 D! 	><=D	>""4(W%\]ff.	
 	\]ll	
 	`h.		
 	`n	
?	@ 	@	> 	>s   F.FFFc                    | j                  t        dd       t        d      5  t        d      }d d d        | j	                        }t        |      }| j                  |j                  d   j                  d       | j                  |j                  d   j                         | j                  |j                  d   j                  d       | j                  |j                  d   j                         y # 1 sw Y   xY w)NrD   r  r  rY  rn   rZ  )r\   rs   r   r   r   r   r_   r[  r]  r   r\  r   r^  s       r.   :test_toolbar_current_app_apphook_with_implicit_current_appzKApphooksTestCase.test_toolbar_current_app_apphook_with_implicit_current_app  s    "";6IJD! 	<:;D	<""4(W%\]ff.	
 	\]ll	
 	`h.		
 	`n	
#	< 	<s   C66C?*cms.test_utils.project.placeholderapp_urlsc                 v   | j                  t        d       t        dddi      }| j                  |      }t	        |      }| j                  |j                  d   j                         | j                  |j                  d   j                         | j                  |j                  d   j                         y )	NrD   detailid   r<  rY  rZ  Bcms.test_utils.project.placeholderapp.cms_toolbars.Example1Toolbar)	r\   rh   r   r   r   r   r[  r\  r   r^  s       r.   test_toolbar_no_namespacez*ApphooksTestCase.test_toolbar_no_namespace  s     	""8T2xr
3""4(W%\]ll	
 	`n	

 	abqq	
r1   c                    | j                  t        d       t        dddi      }| j                  |      }t	        |      }| j                  |j                  d   j                  d       | j                  |j                  d   j                         | j                  |j                  d   j                  d       | j                  |j                  d   j                         | j                  |j                  d	   j                  d       | j                  |j                  d	   j                         | j                  |j                  d
   j                  d       | j                  |j                  d
   j                         y )NrD   re  rf  rg  r<  rY  z%cms.test_utils.project.placeholderapprZ  zGcms.test_utils.project.extensionapp.cms_toolbars.MyPageExtensionToolbarrh  )r\   rh   r   r   r   r_   r[  r]  r   r\  r   r^  s       r.   $test_toolbar_multiple_supported_appsz5ApphooksTestCase.test_toolbar_multiple_supported_apps  sm    	""8T2xr
3""4(W%))*ijss@	B\]ll	
 	`bX3		
 	`n	

 	fgpp3	
 	fgvv	
 	abkk3	
 	abqq	
r1   :cms.test_utils.project.placeholderapp.cms_apps.Example1Apprd   r;   c           	      
   d}d}| j                  |d      5  | j                  dd       t        j                  j	                  ddd	d
t                     }t        dd|j                  i      }| j                  ddd      | _	        | j                  | j                        5  | j                  j                  |dz         }d d d        j                  d   }|j                  }|j                         }|D 	cg c]  }	t!        |	dd      |k(  r|	j"                    }
}	| j%                  t'        |
      d       | j                  ddd      | _	        | j                  | j                        5  | j                  j                  |dz         }d d d        |j                  d   }t)               j                  j                  | j                  j                        |_	        |j                  }|j                         }|D 	cg c]  }	t!        |	dd      |k(  r|	j"                    }
}	| j%                  t'        |
      d       | j                  j*                  j-                  t.        j                  j                  d             | j                  | j                        5  | j                  j                  |dz         }d d d        |j                  d   }t)               j                  j                  | j                  j                        |_	        |j                  }|j                         }|D 	cg c]  }	t!        |	dd      |k(  r|	j"                    }
}	| j%                  t'        |
      d       | j                  j*                  j-                  t.        j                  j                  d             | j                  | j                        5  | j                  j                  |dz         }d d d        |j                  d   }t)               j                  j                  | j                  j                        |_	        |j                  }|j                         }|D 	cg c]  }	t!        |	dd      |k(  r|	j"                    }
}	| j%                  t'        |
      d       d | _	        d d d        y # 1 sw Y   xY wc c}	w # 1 sw Y   :xY wc c}	w # 1 sw Y   xY wc c}	w # 1 sw Y   xY wc c}	w # 1 sw Y   y xY w)N)rl  zMode Switcherrc  rm  Example1ApprD   1234)char_1char_2char_3char_4
date_fieldexample_detailr   r<  admin_staffTz?editr   
identifierrx   rf   staffFr   r   change_example1)codenameuse_structure)r6   r\   r   rO   creater   r   r   _create_userr   r   r   r   contextr_  get_right_itemsgetattrr{  r_   r`   r   user_permissionsaddr   )r-   rO  switcher_idex1r   r   r   r_  itemsitem	switcherss              r.   test_toolbar_staffz#ApphooksTestCase.test_toolbar_staff  sR   
 &]]?k]l 4	&&}d;""))SUXehej)kC+T366NCD))-tDDI((3 ;;;??4'>:; &&y1GooG++-E5: LT#D,;{J  LI LS^Q/))'4?DI((3 ;;;??4'>:; &&y1G)+3377499<<7HGLooG++-E5: LT#D,;{J  LI LS^Q/II&&**:+=+=+A+AK\+A+]^((3 ;;;??4'>:; &&y1G)+3377499<<7HGLooG++-E5: LT#D,;{J  LI LS^Q/II&&**:+=+=+A+A?+A+[\((3 ;;;??4'>:; &&y1G)+3377499<<7HGLooG++-E5: LT#D,;{J  LI LS^Q/DIi4	 4	; ;L
; ;L
; ;L
; ;La4	 4	s   BS8#R17S89#R>AS8,SA4S8?#S"A;S8S<A4S80#S"A;S8S'-A4S8!#S3$S81R;	6S8S	S8S	S8'S0	,S88Tc           	      |   | j                  d      5  | j                          t               j                  j	                  ddd      }t        ddd|       t        d	dd|d
      }t        ddd||d       t        dddi      }t        dddi      }| j                  |d       | j                  |d       | j                  j                  |      }| j                  |dd       | j                  j                  |      }| j                  |dd       | j                          d d d        y # 1 sw Y   y xY w)Nr7  r]   r@   rA   rB   rC   rD   rE   zparent-apphook-page	ParentApprw   zchild-apphook-pageChildApp)rJ   rF   rM   parentapp_viewr   zparent/path/r<  childapp_viewzchild-path/z$/en/parent-apphook-page/parent/path/z6/en/parent-apphook-page/child-apphook-page/child-path/zparent app contentr   )r   zchild app content)r6   r+   r   rO   rP   r   r   r_   r   r   r   )r-   rQ   parent_pageparent_app_pathchild_app_pathr   s         r.   test_nested_apphooks_urlsz*ApphooksTestCase.test_nested_apphooks_urlsP  s9   ]](E]F 	! &(00AA'K\^efI 5t	T%&;=RTX1:KQK,.CTR]#,jB &&6?WXO$_fm=TUN _.TU^-ef {{7H*>CP{{~6H*=3O 1	! 	! 	!s   DD22D;c           	         | j                  dddg      }d|d   j                  _        |d   j                  j                          | j	                          t        d      5  t        d       | j                  t              5  t        d       ddd       ddd       | j	                          | j                          t        d	d
d| j                  |d   j                  j                  dd	      }t        dd|d       | j	                          t        d      5  t        d       t        d       ddd       | j                          y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   2xY w)z~
        Check that urlconf are dynamically loaded according to the different page the apphook is
        attached to
        VariableUrlsApprD   rG   page1r   r+  r@  Nr  rC   )rF   rJ   rM   
reverse_idr   rz   r  )r\   rY   r  saver*   r   r   assertRaisesr
   r+   r   rQ   rJ   r   )r-   r  r  s      r.   test_get_appszApphooksTestCase.test_get_appsl  s=    ++,=d|L$+q	!q	 D! 	(M""">2 ('(	(
 	G%: T^^#)!9>>#8#8$5'K 	D*e&AD! 	#N#M"	# 	%( (	( 	( 	# 	#s0   !!EEEE#E	EE #E,c           
         | j                  dddg      }d|d   j                  _        |d   j                  j                          t	        j
                          | j                          t        j                          t	        j
                          | j                  d      }t        j                  |      }|j                         }|D cg c]  }|j                   }}| j                  t        d      |v        | j                  d|v        | j                          | j!                          t	        j
                          | j                          t#        d	d
d| j$                  |d   j                  j&                  ddd	      }t)        dd|d       | j                  d      }t        j                  |      }|j                         }|D cg c]  }|j                   }}| j                  t        d      |v        | j                  t        d      |v        | j                  d|v        | j!                          yc c}w c c}w )z|
        Check that menus are dynamically loaded according to the different page the apphook is
        attached to
        r  rD   rG   r  r   /zsample-accountz/en/child_page/page2/r  rC   T)rF   rJ   in_navigationrM   r  r   rz   r  z/page2/r@  z/static/fresh/N)r\   rY   r  r  r   clearr*   r   discover_menusr   get_renderer	get_nodesr  r   r   r   r+   r   rQ   rJ   r   )r-   r  r   renderernodesnode
nodes_urlsr  s           r.   test_get_menuszApphooksTestCase.test_get_menus  s    ++,=d|L$+q	!q	  """3'))'2""$+014dhh1
1 01Z?@0J>?G%: T^^#)!9>>#8#8*.$5'	K
 	D*e&A""9-))'2""$+014dhh1
1 01Z?@/:=>(J671 2& 2s   IIz7cms.test_utils.project.sampleapp.cms_apps.AppWithNoMenuc                 @   dddd}t        di |}|j                          t        dddd|}| j                  d      }t        |      |_        t        j                  |      j                         }| j                  t        |      d	       | j                  |d
   j                  |j                         | j                  |d
   j                  d       | j                  |d   j                  |j                         | j                  |d   j                  d       y)z}
        If a user requests a page with an apphook,
        the menu should mark the node for that page as selected.
        rD   TrC   r   r  templateAppWithNoMenuapp_with_no_menurM   rN   z
/en/en-p2/r   r   Frf   NzEN-P1zEN-P2r   set_as_homepager   r   current_pager   r  r  r_   r`   rf  r   selectedr-   defaultshomepageapp_rootr   
menu_nodess         r.   &test_menu_node_is_selected_on_app_rootz7ApphooksTestCase.test_menu_node_is_selected_on_app_root  s    !-

 3(3  "rSeriqr ""<0'0++G4>>@
Z!,A))8;;7A//7A))8;;7A//6r1   c                 @   dddd}t        di |}|j                          t        dddd|}| j                  d      }t        |      |_        t        j                  |      j                         }| j                  t        |      d	       | j                  |d
   j                  |j                         | j                  |d
   j                  d       | j                  |d   j                  |j                         | j                  |d   j                  d       y)z
        If a user requests a path belonging to an apphook,
        the menu should mark the node for the apphook page as selected.
        rD   TrC   r  r  r  r  z/en/en-p2/settings/r   r   Frf   Nr  r  r  r  s         r.   *test_menu_node_is_selected_on_app_sub_pathz;ApphooksTestCase.test_menu_node_is_selected_on_app_sub_path  s     !-

 3(3  "rSeriqr""#89'0++G4>>@
Z!,A))8;;7A//7A))8;;7A//6r1   r%   )1r   r   r   r/   r3   r*   r\   r	   rb   r'   rh   rm   rt   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r!  r%  r'  r-  r6  r9  r=  rA  rD  rQ  rW  r`  rb  ri  rk  r  r  r  r  r  r  r   r1   r.   r#   r#   "   s   (,4 $Z[) \) 
|1XJ%?$@A	 B	 :;D
	
&2( $ST U $ST
 U
 $ST1 U1f $Z[ \6 $Z[ \ $Z[A \A  
|1XJ%?$@AG BG* $CD$? E$?L $Z[ \& $Z[ \ $Z[ \" $Z[ \ $Z[  \ D $Z[	2 \	2 $Z[ \$ $Z[ \: e:YZ> [> $AB	? C	? $ABc Cc $YZ [ $Z[ \' $Z[4 \4* $Z[%
 \%
N $Z[
 \
2 $PQ
 R
$ $PQ#
 R#
J RSA<	<|!8 $Z[  \ D $Z[( \(T OP770 OP77r1   r#   c                   $    e Zd Zd Zd Zd Zd Zy)ApphooksPageLanguageUrlTestCasec                     t                t                t        t        j                  v rt        j                  t        = | j                          y r%   )r   r   r'   r(   r)   r*   r,   s    r.   r/   z%ApphooksPageLanguageUrlTestCase.setUp  s2    $J'r1   c                     t                t                t        t        j                  v rt        j                  t        = | j                          y r%   )r   r   r'   r(   r)   r+   r,   s    r.   r3   z(ApphooksPageLanguageUrlTestCase.tearDown  s2    $J'r1   c                     ddl m} dd|j                  g}t                t	                |D ]&  }|t
        j                  v st
        j                  |= ( y )Nr   r5   r7   r8   )r:   r6   r;   r   r   r(   r)   r<   s       r.   r*   z+ApphooksPageLanguageUrlTestCase.reload_urls  sR    ( F!!
 	! 	(F$KK'	(r1   c                    | j                          t               j                  j                  ddd      }| j	                  ddd|      }t        d|j                         |       t        ddd||	      }t        d|j                         |       |j                          t        d
dd||d      }t        d|j                          d|       |j                          t        d      5  t        d      }d d d        | j                        }d|_        ||_        d|i}t               }|j                  |d      }	|	d   }
| j!                  |
d       |j                  |d      }	|	d   }
| j!                  |
d       |j                  |d      }	|	d   }
| j!                  |
d       | j                          y # 1 sw Y   xY w)Nr@   rA   rB   rC   rD   rE   rG   rH   rI   rK   r    )rF   rJ   rM   _der+  r   r   z(/en/child_page/child_child_page/extra_1/z+/de/child_page/child_child_page_de/extra_1/fr)r+   r   rO   rP   r}   r   rR   r   refresh_from_dbr   r   r   r   r  r   get_contextr_   )r-   rQ   rY   rH   rK   r   r   fake_contexttagoutputr  s              r.   "test_page_language_url_for_apphookzBApphooksPageLanguageUrlTestCase.test_page_language_url_for_apphook  s   "$,,==gGXZab	##F,A4T]#^D$.."2D9 /Dd,5dD
D*"6"6"8*E""$&'9;P'+	*^ikD%5%?%?%A$B#"FHXY((*D! 	*=)D	* ""4( $/!7+!#t4YHIt4YKLt4YHI1	* 	*s   +F88GN)r   r   r   r/   r3   r*   r  r   r1   r.   r  r    s    ( )r1   r  )<r(   django.contrib.authr   django.contrib.auth.modelsr   django.contrib.sites.modelsr   django.corer   django.core.cacher   django.core.checks.urlsr   django.test.utilsr	   django.urlsr
   r   r   r   django.utils.timezoner   django.utils.translationr   r   cms.admin.formsr   cms.apir   r   cms.app_baser   cms.apphook_poolr   cms.appresolverr   r   r   cms.middleware.pager   
cms.modelsr   ,cms.test_utils.project.placeholderapp.modelsr   cms.test_utils.testcasesr   cms.tests.test_menu_utilsr   cms.toolbar.toolbarr   menus.menu_poolr   menus.utilsr   rh   rs   r'   MENU_MODULEr#   r  r   r1   r.   <module>r     s    
 . 1 ,  # 4 / J J % ? 0 4  ) Z Z ( " A 0 9 * % .8
:L7{ L7^Jk Jr1   