
    Bh                    f   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 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 d dl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l(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0m1Z1 d dl2m3Z3 d dl4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z>m?Z?m@Z@ d dlAmBZBmCZCmDZDmEZEmFZFmGZG d dlHmIZI d ZJd  ZK G d! d"e6      ZL G d# d$e)e5      ZM ed%&       G d' d(e<e5             ZN G d) d*e      ZO G d+ d,e5      ZP G d- d.eP      ZQ G d/ d0eQ      ZRy1)2    )settings)get_user_model)ImproperlyConfigured)TemplateTemplateSyntaxError)get_template)TestCase)override_settings)	force_str)format)SekizaiContext)	constants)
add_plugincreate_pagecreate_page_content)DuplicatePlaceholderWarningPlaceholderNotFound)PlaceholderField)Placeholder)	CMSPlugin)UserSettings)plugin_pool)FakemlngFixtures)Translations)	FancyPoll)DynamicPlaceholderSlotExampleExample1TwoPlaceholderExample)Category)CMSTestCaseTransactionCMSTestCase)override_placeholder_confAttributeObject)ToolbarTestBase)get_object_edit_urlget_object_structure_urlget_toolbar_from_request)MLNGPlaceholderActionsPlaceholderNoAction_get_nodelist_scan_placeholdersget_placeholder_confget_placeholders)admin_reversec                 R    t        |       D cg c]  }|j                   c}S c c}w N)r.   slot)templatepls     J/home/dcms/DCMS/lib/python3.12/site-packages/cms/tests/test_placeholder.py_get_placeholder_slotsr6   3   s    .x89BGG999s   $c                 b    |d   }t        |      }|j                  } |j                  | |fi |S )Nrequest)r(   content_rendererrender_placeholder)placeholdercontextkwargsr8   toolbarr9   s         r5   _render_placeholderr?   7   s=    i G&w/G//...{GNvNN    c                      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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  e!d       d!        Z" e!d       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/ Z0d0 Z1d1 Z2d2 Z3d3 Z4d4 Z5 e!d56      d7        Z6 e!d56      d8        Z7d9 Z8d: Z9d; Z:d< Z;d= Z<y>)?PlaceholderTestCasec                     | j                  ddd      }| j                  |      | _        | j                  j                          y )NtestT)_create_userlogin_user_context_login_context	__enter__)selfus     r5   setUpzPlaceholderTestCase.setUp?   s;    fdD1"55a8%%'r@   c                 >    | j                   j                  d d d        y r1   )rG   __exit__rI   s    r5   tearDownzPlaceholderTestCase.tearDownE   s    $$T46r@   c                 f    t        d      }| j                  t        |      t        g d             y )Nzplaceholder_tests/test_one.htmlnew_onetwothreer6   assertEqualsortedrI   placeholderss     r5    test_placeholder_scanning_extendz4PlaceholderTestCase.test_placeholder_scanning_extendH   s(    -.OP-v6Q/RSr@   c                 B    t        d      }| j                  |g d       y )Nz,placeholder_tests/test_variable_extends.htmlonerS   rT   fourr6   rV   rX   s     r5   )test_placeholder_scanning_variable_extendz=PlaceholderTestCase.test_placeholder_scanning_variable_extendL   s    -.\]'FGr@   c                 B    t        d      }| j                  |g d       y )Nz9placeholder_tests/test_inherit_from_variable_extends.htmlr\   r_   rX   s     r5   6test_placeholder_scanning_inherit_from_variable_extendzJPlaceholderTestCase.test_placeholder_scanning_inherit_from_variable_extendP   s    -.ij'FGr@   c                 f    t        d      }| j                  t        |      t        g d             y )Nz'placeholder_tests/test_one_sekizai.htmlrQ   rU   rX   s     r5   (test_placeholder_scanning_sekizai_extendz<PlaceholderTestCase.test_placeholder_scanning_sekizai_extendT   s(    -.WX-v6Q/RSr@   c                 f    t        d      }| j                  t        |      t        ddg             y )Nzplaceholder_tests/test_two.htmlchildrT   rU   rX   s     r5   !test_placeholder_scanning_includez5PlaceholderTestCase.test_placeholder_scanning_includeX   s,    -.OP-vw6H/IJr@   c                 f    t        d      }| j                  t        |      t        g d             y )Nz!placeholder_tests/test_three.htmlrR   rS   	new_threerU   rX   s     r5   'test_placeholder_scanning_double_extendz;PlaceholderTestCase.test_placeholder_scanning_double_extend\   s(    -.QR-v6U/VWr@   c                 f    t        d      }| j                  t        |      t        g d             y )Nz)placeholder_tests/test_three_sekizai.htmlri   rU   rX   s     r5   /test_placeholder_scanning_sekizai_double_extendzCPlaceholderTestCase.test_placeholder_scanning_sekizai_double_extend`   s(    -.YZ-v6U/VWr@   c                 f    t        d      }| j                  t        |      t        g d             y )Nz placeholder_tests/test_four.html)rR   rf   r^   rU   rX   s     r5   !test_placeholder_scanning_complexz5PlaceholderTestCase.test_placeholder_scanning_complexd   s(    -.PQ-v6R/STr@   c                 f    t        d      }| j                  t        |      t        g d             y )Nz placeholder_tests/test_five.html)r]   	extra_onerS   rT   rU   rX   s     r5   test_placeholder_scanning_superz3PlaceholderTestCase.test_placeholder_scanning_superh   s(    -.PQ-v6Z/[\r@   c                 f    t        d      }| j                  t        |      t        g d             y )Nzplaceholder_tests/test_six.html)rR   new_tworj   rU   rX   s     r5    test_placeholder_scanning_nestedz4PlaceholderTestCase.test_placeholder_scanning_nestedl   s(    -.OP-v6Y/Z[r@   c                     | j                  t        dt        d      }| j                  t	        |      t	        dg             y )NzPDuplicate {% placeholder "one" %} in template placeholder_tests/test_seven.html.z!placeholder_tests/test_seven.htmlr]   )failUnlessWarnsr   r6   rV   rW   rX   s     r5   #test_placeholder_scanning_duplicatez7PlaceholderTestCase.test_placeholder_scanning_duplicatep   s;    ++'^"/	
 	-vug?r@   c                 f    t        d      }| j                  t        |      t        g d             y )Nzplaceholder_tests/outside.htmlrR   rS   base_outsiderU   rX   s     r5   .test_placeholder_scanning_extend_outside_blockzBPlaceholderTestCase.test_placeholder_scanning_extend_outside_blocky   s(    -.NO-v6X/YZr@   c                 f    t        d      }| j                  t        |      t        g d             y )Nz&placeholder_tests/outside_sekizai.htmlrz   rU   rX   s     r5   6test_placeholder_scanning_sekizai_extend_outside_blockzJPlaceholderTestCase.test_placeholder_scanning_sekizai_extend_outside_block}   s(    -.VW-v6X/YZr@   c                 f    t        d      }| j                  t        |      t        g d             y )Nz%placeholder_tests/outside_nested.htmlrz   rU   rX   s     r5   5test_placeholder_scanning_extend_outside_block_nestedzIPlaceholderTestCase.test_placeholder_scanning_extend_outside_block_nested   s(    -.UV-v6X/YZr@   c                 f    t        d      }| j                  t        |      t        g d             y )Nz-placeholder_tests/outside_nested_sekizai.htmlrz   rU   rX   s     r5   =test_placeholder_scanning_sekizai_extend_outside_block_nestedzQPlaceholderTestCase.test_placeholder_scanning_sekizai_extend_outside_block_nested   s(    -.]^-v6X/YZr@   c                 6   t        d      }t        d t        |j                        D              }| j	                  |t        dg             t        d      }t        d t        |j                        D              }| j	                  |t        g d             y )NzE{%load cms_tags %}{% include name %}{% placeholder "a_placeholder" %}c              3   P   K   | ]  }|j                         j                     y wr1   get_declarationr2   .0nodes     r5   	<genexpr>zDPlaceholderTestCase.test_placeholder_scanning_var.<locals>.<genexpr>        \TT))+00\   $&a_placeholderz={% include "placeholder_tests/outside_nested_sekizai.html" %}c              3   P   K   | ]  }|j                         j                     y wr1   r   r   s     r5   r   zDPlaceholderTestCase.test_placeholder_scanning_var.<locals>.<genexpr>   r   r   )rS   rR   r{   )r   rW   r,   nodelistassertListEqual)rI   tphss      r5   test_placeholder_scanning_varz1PlaceholderTestCase.test_placeholder_scanning_var   s    \]\=OPQPZPZ=[\\S&/):";<TU\=OPQPZPZ=[\\S&)K"LMr@   c                     t               }| j                  dd      }t        |      }|j                         }| j	                  t
              5  |j                  d|d       ddd       y# 1 sw Y   yxY w)zWPlaceholder scanning for a template without a toolbar object raises PlaceholderNotFoundenNlanguagepagesomeslotF)r   get_requestr(   get_content_rendererassertRaisesr   render_obj_placeholder)rI   r<   r8   r>   renderers        r5   #test_placeholder_scanning_no_objectz7PlaceholderTestCase.test_placeholder_scanning_no_object   ss     !"""Dt"<*73//123 	H++JG	H 	H 	Hs   A++A4c                    | j                   j                  t        d            }| j                  |j                  d       | j                   j                  t        d            }| j                  |j                  d       y )Nplaceholderapp_example1_add   (placeholderapp_twoplaceholderexample_add)clientgetr/   rV   status_code)rI   responses     r5   test_fieldsets_requestsz+PlaceholderTestCase.test_fieldsets_requests   s^    ;;??=1N#OP--s3;;??=1[#\]--s3r@   c                     t        dddd      }|j                          | j                  j                  t	        d|j
                  f            }| j                  |j                  d       | j                  |d	       y )
Nr]   rS   treer^   char_1char_2char_3char_4placeholderapp_example1_change)argsr   InheritPagePlaceholderPlugin)	r   saver   r   r/   pkrV   r   assertNotContains)rI   exr   s      r5   test_page_only_pluginsz*PlaceholderTestCase.test_page_only_plugins   sf    U5O
	;;??=1QY[Y^Y^X`#ab--s3x)GHr@   c                    t        dddd      }|j                          |j                  }|j                  }t	        |ddd	      j
                  }t	        |ddd
	      j
                  }t	        |ddd	      j
                  }t	        |ddd	      j
                  }t	        |ddd	      j
                  }t	        |ddd	      j
                  }	| j                  |      }
t        |	j                        ddd}| j                  j                  |
|      }| j                  |j                  d       | j                  |	||gt        |j                  j                  d                   t        |j                        t        |j                        d|j!                  dd      d}| j                  j                  |
|      }| j                  |j                  d       | j                  ||gt        |j                  j                  d                   | j                  |	|||gt        |j                  j                  d                   y )Nr]   rS   r   r^   r   
TextPluginr   zph1 plugin1bodyzph1 plugin2zph1 plugin3zph2 plugin1zph2 plugin2zph2 plugin3   )	plugin_idtarget_languagetarget_positionr   positionlast)insert_order)placeholder_idr   r   r   )r   r   placeholder_1placeholder_2r   cmsplugin_ptrget_move_plugin_uristrr   r   postrV   r   listcmsplugin_setorder_byget_next_plugin_position)rI   r   ph1ph2ph1_pl1ph1_pl2ph1_pl3ph2_pl1ph2_pl2ph2_pl3endpointdatar   s                r5   "test_inter_placeholder_plugin_movez6PlaceholderTestCase.test_inter_placeholder_plugin_move   s   "%fU[\
	S,=IWWS,=IWWS,=IWWS,=IWWS,=IWWS,=IWW++G4 WZZ# 
 ;;##Hd3--s3'7G4d3;L;L;U;UV`;a6bc "#&&kWZZ#";;Dv;V	
 ;;##Hd3--s3'7+T#2C2C2L2LZ2X-YZ'7GW=tCDUDUD^D^_iDj?klr@   c                    d}dD ]  \  }}t               }|j                          |j                  }|j                  }i }i }i }	i }
|D ]  }t	        |d|d      j
                  ||<   g |	|<   t        |      D ]4  }|	|   j                  t	        |d|||   d|       j
                         6 t	        |d|d      j
                  ||<   g |
|<   t        |      D ]4  }|
|   j                  t	        |d|||   d	|       j
                         6  |j                  ||d
      ||d
      d|       ||d
      ||d
      g|
|d
      z   |	|d
      z   }t        |j                  j                  |d
         j                  d            }| j                  ||       |j                          |j                           y )Nr   deitz	de-formal))r   
   )r   r   )   r   r   z
ph1 parentr   z	ph1 child)targetr   z
ph2 parentz	ph2 childr      )target_pluginr   target_placeholderr   r   )r   r   r   r   r   r   rangeappendmove_pluginr   r   filterr   rV   delete)rI   language_funn1n2r   r   r   	ph1parent	ph2parentph1childrenph2childrenlangileftrights                  r5   )test_inter_placeholder_nested_plugin_movez=PlaceholderTestCase.test_inter_placeholder_nested_plugin_move   s    7
 1 1	FB&(BGGI""C""CIIKK$ ",S,<"X"f"f	$$&D!r A%,,"3d9T?[defdgYhiww #-S,<"X"f"f	$$&D!r A%,,"3d9T?[defdgYhiww& OO,q/*'Q8 !#&	   <?+Y|A-GHl1o./l1o./  **11<?1KTTU_`aET5)JJLJJLc1	r@   c           	         d}t               }|j                          |j                  }d }d}|D ci c]  }|g  }}t        j	                  |      }t        |      D ]?  }|D ]8  }t        |d|||         j                  ||<   ||   j                  ||          : A |D ]  }| j                  |j                  |      |       ||   D ]2  }| j                  |j                  ||      |||   d   k7  r|nd        4 t        |d|d        | j                  |j                  |      |dz          ||   D ]2  }| j                  |j                  ||      |||   d   k7  r|nd        4  y c c}w )Nr      r   )r   parentr   )r   r   r;   dictfromkeysr   r   r   r   rV   get_last_plugin_position)	rI   r   r   phr   nr   pluginsr   s	            r5   test_get_last_plugin_positionz1PlaceholderTestCase.test_get_last_plugin_position  s    7Z
	^^(454855|,q 	3A$ 3)"lDPTVddt$$VD\23	3
 ! 	DR88>B!$-    //V/D74=#44A$ r<d;R88>AF!$-    //V/D74=#44A$	 6s   
E/c                     d}t               }|j                          |j                  }d}t        |      D ]!  }|D ]  }t	        |d|d      j
                    # | j                  |j                  d      |       y )N)r   r   r   zen-US   r   zfirst-childr   )r   r   r;   r   r   r   rV   r   )rI   r   r   r   r   r   r   s          r5   #test_get_last_plugin_position_orderz7PlaceholderTestCase.test_get_last_plugin_position_orderA  s~     3Z
	^^q 	TA( T2|X}ESST	T
 	44T:A>r@   c                 6   | j                         }t        ddd      }|j                  d      j                  d      }t	        |dddd	      }| j                  |      }t        j                  j                  d|t        j                  j                         
      }|j                  |j                  |j                  d|j                  j                  d}| j                  |      5  | j                  j                  ||      }| j!                  |j"                  d       d d d        |j                  j%                         }	| j'                  |	j)                  d      j+                                | j!                  t-        |	      d       y # 1 sw Y   nxY w)NCopyPluginTestPage (EN)nav_playground.htmlr   r   r2   
LinkPluginA Linkhttps://www.django-cms.orgnameexternal_linkr   user	clipboardsource_plugin_idsource_placeholder_idsource_languager   target_placeholder_idr   plugin_typer   get_superuserr   r.   r   r   get_copy_plugin_urir   objectscreater   r   r   r  rF   r   r   rV   r   get_plugins
assertTruer   existslen
rI   	superuserpage_en	ph_sourcepluginr   user_settingsr   r   clipboard_pluginss
             r5   test_copy_pluginz$PlaceholderTestCase.test_copy_plugin[  sg   &&(	79NPTU,,T266F6C	I|TXtu++F3$,,33!))002 4 
 !'		%.\\%#%2%<%<%?%?
 $$Y/ 	8{{''$7HX1137	8
 *33??A)00\0JQQST./3	8 	8s   )9FFc                 0   | j                         }t        ddd      }|j                  d      j                  d      }t	        |dd      }| j                  |      }t        j                  j                  d|t        j                  j                               }|j                  |j                  |j                  d|j                  j                  d}| j                  |      5  | j                  j                  ||      }| j!                  |j"                  d	       d d d        |j                  j%                         }	| j'                  |	j)                  d
      j+                                | j!                  t-        |	      d       y # 1 sw Y   nxY w)Nr  r  r   r   r  NoCustomModelr  r  r   r  r   r  r!  s
             r5   %test_copy_plugin_without_custom_modelz9PlaceholderTestCase.test_copy_plugin_without_custom_modelw  sb   &&(	79NPTU,,T266F6C	I=++F3$,,33!))002 4 
 !'		%.\\%#%2%<%<%?%?
 $$Y/ 	8{{''$7HX1137	8
 *33??A)00_0MTTVW./3	8 	8s   &9FFc                     | j                         }t        ddd      }|j                  d      j                  d      }t	        |dddd	       t
        j                  j                  d|t        j                  j                         
      }t	        |j                  dddd      }| j                  |      }|j                  ddd|j                  d}| j                  |      5  | j                  j                  ||      }| j                  |j                   d       d d d        |j#                  d      }	| j%                  |	j'                  d      j)                                | j                  t+        |	      d       |j#                  d      j                  d      }
|j                  ddd|
j                  |j                  d}| j                  |      5  | j                  j                  ||      }| j                  |j                   d       d d d        |j#                  d      }	| j%                  |	j'                  d      j)                                | j                  t+        |	      d       y # 1 sw Y   [xY w# 1 sw Y   rxY w)Nr  r  r   r   r  r  r	  r
  r  r  )r   r  r  Tr   )r   move_a_copyr   r   r   r   r  r   r   )r   r-  r   r   plugin_parentr      )r  r   r.   r   r   r   r  r  r   r  r   r   rF   r   r   rV   r   r  r  r   r  r   )rI   r"  r#  	ph_targetr&  r%  r   r   r   r   r   s              r5    test_paste_plugin_from_clipboardz4PlaceholderTestCase.test_paste_plugin_from_clipboard  sI   &&(	79NPTU,,T266F6C	9lDxOkl$,,33!))002 4 

 ##6
 ++F3  # 'll
 $$Y/ 	8{{''$7HX1137	8
 ''-<@GGIJWq) &&t,00!0<# #YY'll
 $$Y/ 	8{{''$7HX1137	8
 ''-<@GGIJWq)7	8 	8(	8 	8s   %9I79J7JJc                 `   t        ddd      }|j                  d      j                  d      }t        j                  j                  ddd|d	       t        |ddd
d       t               }| j                  d|      |d<   t        ||      }| j                  |j                         d       y)zB
        Tests a placeholder won't render a ghost plugin.
        r#  col_two.htmlr   col_leftr  r  r   Nr   r  r   r;   r   r  http://example.com/r  r   r8   z&<a href="http://example.com/">name</a>r   r.   r   r   r  r  r   r   r   r?   rV   strip)rI   r#  placeholder_en
context_en
content_ens        r5   $test_placeholder_render_ghost_pluginz8PlaceholderTestCase.test_placeholder_render_ghost_plugin  s     i> 11$7;;;L  $& 	! 	
 	/	
 $%
 $ 0 0$W 0 M
9(D
))+-UVr@   c                    t        ddd      }|j                  d      j                  d      }t        j                  j                  ddd|d	      }t        |dd|d
d       t        |dddd       t               }| j                  d|      |d<   t        ||      }| j                  |j                         d       y)zZ
        Tests a placeholder won't render a ghost plugin or any of it's children.
        r#  r4  r   r5  r  r  r   Nr6  invalidr7  )r   r  r  validr  r   r8   z'<a href="http://example.com/">valid</a>r8  )rI   r#  r:  r%  r;  r<  s         r5   /test_placeholder_render_ghost_plugin_with_childzCPlaceholderTestCase.test_placeholder_render_ghost_plugin_with_child  s     i> 11$7;;;L""))$& * 
 	/	
 	/	
 $%
 $ 0 0$W 0 M
9(D
))+-VWr@   FCMS_PERMISSIONc                 R   t        dddd      }|j                          |j                  }t        |dd      }|j                          | j	                  |      }| j
                  j                  |i       }| j                  |d       | j                  |d	|j                   d
       y)z
        Checks #1366 error condition.
        When adding/editing a plugin whose icon_src() method returns a URL
        containing a hyphen, the hyphen is escaped by django escapejs resulting
        in a incorrect URL
        r]   rS   r   r^   r   EmptyPluginr   1<script id="data-bridge" type="application/json">title=\"EmptyPlugin ID: \"N)	r   r   r;   r   get_change_plugin_urir   r   assertContainsr   )rI   r   r   test_pluginr   r   s         r5    test_databridge_contains_changesz4PlaceholderTestCase.test_databridge_contains_changes  s     U5O
	nn !mT:--k:;;##Hb1H&YZH(A+..AQQT&UVr@   c                 X   t        ddd      }|j                  d      j                  d      }t        |dd      }|j	                          | j                  |      }| j                  j                  |i       }| j                  |d       | j                  |d|j                   d	       y
)zu
        Sibling test of the above, on a page.
        #1366 does not apply to placeholder defined in a page
        r   r4  r   r5  r  rE  rF  rG  rH  N)
r   r.   r   r   r   rI  r   r   rJ  r   )rI   r   r   rK  r   r   s         r5    test_nested_plugin_escapejs_pagez4PlaceholderTestCase.test_nested_plugin_escapejs_page&  s     6>48##D)--:-> !mT:--k:;;##Hb1H&YZH(A+..AQQT&UVr@   c                 :    | j                  t        t        d       y )Nz"placeholder_tests/test_eleven.html)r   r   r6   rN   s    r5   test_placeholder_scanning_failz2PlaceholderTestCase.test_placeholder_scanning_fail9  s    -/EGklr@   c                    | j                  dt        j                  d   d         }d}| j                  |i |      }| j	                  |d       t
        j                  j                  d      }| j                  |d|i|      }| j	                  |d       | j	                  |j                         j                         d       t        |d	t        j                  d   d   d
       | j	                  |j                         j                         d       | j                  |      }| j                  |d|i|      }| j	                  |d       y )N/r   r   z7{% load cms_tags %}{% render_placeholder placeholder %} rD   r  r;   r   r   r   )r   r   	LANGUAGESrender_template_objrV   r   r  r  r  countr   reload)rI   r8   r3   outputr;   s        r5   test_placeholder_tagz(PlaceholderTestCase.test_placeholder_tag<  s-   ""31C1CA1Fq1I"JL))(B@$!))00f0=))(]K4PRYZ$00288:A>;h.@.@.CA.FVT00288:A>kk+.))(]K4PRYZ(r@   c                    d}t         j                  j                  d      }t        |ddd       t        |ddd	       | j	                  d
      }| j                  ||dd|      }| j                  |j                         d       |`| j                  ||dd|      }| j                  |j                         d	       y )NzI{% load cms_tags %}{% render_placeholder placeholder language language %}rD   r  r   r   Englishr   r   DeutschrR  )r;   r   )	r   r  r  r   r   rU  rV   r9  _plugins_cache)rI   r3   r;   r8   rX  s        r5   test_placeholder_tag_languagez1PlaceholderTestCase.test_placeholder_tag_languageN  s    ^!))00f0=;dC;dC""3'))(K]a4bdkl3&))(K]a4bdkl3r@   c                    dddgdddidgddg d	d
ddidddi dgddddgi dd}t        |      5  t        dd
      }| j                  ||d
   d          t        dd
d      }| j                  ||d   d          t        dd
d      }| j                  ||d   d          t        dd
d      }| j                  ||d   d          t        dd
d      }| j                  ||d
   d          t        dd      }| j                  ||d    d          t        dd      }| j                  ||d
   d          d d d        y # 1 sw Y   y xY w)Nzmain contentr   r  r   z<p>Some default text</p>r  values)r  r   default_pluginsz,main content with FilerImagePlugin and limit)r   FilerImagePluginr  mainglobalr   )r  r   inheritlimitsz/main content with FilerImagePlugin and no limitlayout/home.html main)r  rf  rg  excluded_pluginsAllrc  )r  r   rg  )rd  rh  layout/other.html mainNCMS_PLACEHOLDER_CONFr   zlayout/home.htmlzlayout/other.htmlri  rk  rb  	something)r"   r-   rV   )rI   	TEST_CONFreturneds      r5   test_get_placeholder_confz-PlaceholderTestCase.test_get_placeholder_conf]  s    '(,7 (4#)+E"F$	 GK!#Q-	& J2%1N	' .=/
	< 'IF 	M+Iv>HXy'8'CD+Iv?QRHXy1H'I)'TU+Iv?RSHXy1H'I)'TU+,>H[\HXy1I'JK]'^_+,=vGZ[HXy'89J'KL+I{CHXyy'AB+,=?WXHXy'89J'KL+	M 	M 	Ms   DD??Ec                 n   t        ddd      }|j                  d      j                  d      }t        j                  j                  d      }t        j                  j                  d      }ddidd	idd
id}t        |      5  | j                  t        |j                               d	       | j                  t        |j                               d       | j                  t        |j                               d
       d d d        |d = t        |      5  | j                  t        |j                               d	       | j                  t        |j                               d       | j                  t        |j                               d       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr#  r4  r   r5  r  no_namer  zrenamed left columnzleft columnfallback)r5  col_two.html col_leftNrl  No_Name)
r   r.   r   r   r  r  r"   rV   r   	get_label)rI   r#  r   r   placeholder_3ro  s         r5   test_placeholder_name_confz.PlaceholderTestCase.test_placeholder_name_conf  s   i>006::
:K#++22
2C#++22	2B - & 


	 'IF 	OY}'>'>'@A=QY}'>'>'@ACXYY}'>'>'@A:N	O
 dO&IF 	NY}'>'>'@A=QY}'>'>'@ACXYY}'>'>'@A9M	N 	N	O 	O	N 	Ns   A<FA<F+F(+F4c                 B    t        d      }| j                  |g d       y )Nz&placeholder_tests/test_with_block.htmlr\   r_   rX   s     r5   #test_placeholders_from_blocks_orderz7PlaceholderTestCase.test_placeholders_from_blocks_order  s    -.VW'FGr@   c                 f    t        d      }| j                  t        |      t        g d             y )Nz*placeholder_tests/nested_super_level1.html)level1level2level3level4rU   rX   s     r5   &test_placeholder_scanning_nested_superz:PlaceholderTestCase.test_placeholder_scanning_nested_super  s(    -.Z[-v6^/_`r@   c                 >    | j                  t        t        dd       y )Nr;   +)related_name)r   
ValueErrorr   rN   s    r5   &test_placeholder_field_no_related_namez:PlaceholderTestCase.test_placeholder_field_no_related_name  s    *&6TWXr@   c                     t         j                  j                  ddd      }| j                  |j                  j                         t                y)zY
        Test for leaking Model._meta.db_table monkeypatching on SQLite (#3891).
        categoryNr   )r  r   depth)r   r  r  rV   description_get_attached_model)rI   examples     r5   test_placeholder_field_db_tablez3PlaceholderTestCase.test_placeholder_field_db_table  sI     "")) * 

 	,,@@BHMr@   c                 :    | j                  t        t        d       y )Nr   )r   r   r   rN   s    r5   %test_placeholder_field_valid_slotnamez9PlaceholderTestCase.test_placeholder_field_valid_slotname  s    .0@"Er@   c                    t         j                  j                  dd      }| j                  |j                  |j
                  j                         | j                  |j                  |j                  j                         y Nslot1slot2)r   r   )	r   r  r  rV   r   r   r2   r   r   )rI   instances     r5   .test_placeholder_field_dynamic_slot_generationzBPlaceholderTestCase.test_placeholder_field_dynamic_slot_generation  s^    088??wW^?_(*@*@*E*EF(*@*@*E*EFr@   c                 l   t         j                  j                  dd      }t        |j                  j                               }t        |j                  j                               }|j                  |j                  c|_        |_        |j                  j                  }|j                  j                  }|j                          t        |j                  j                               }t        |j                  j                               }| j                  |j                  d       | j                  |j                  d       | j                  |j                  j                  |       | j                  |j                  j                  |       | j                  ||       | j                  ||       y r  )r   r  r  r   r   r  r   r   r   r   r   rV   )rI   r  old_placeholder_1_plugin_countold_placeholder_2_plugin_countplaceholder_1_idplaceholder_2_id"current_placeholder_1_plugin_count"current_placeholder_2_plugin_counts           r5   *test_placeholder_field_dynamic_slot_updatez>PlaceholderTestCase.test_placeholder_field_dynamic_slot_update  s[   088??wW^?_ *-X-C-C-O-O-Q)R&),X-C-C-O-O-Q)R& ,4??HOO( $1144#1144 	-01G1G1S1S1U-V*-01G1G1S1S1U-V* 	'2'2//224DE//224DE79[\79[\r@   c                 B   dddddiddddidgii}t        |      5  t        d	d
d      }|j                  d      j                  d      }t	               }| j                  d|      |d<   t        ||      }| j                  |d       ddd       y# 1 sw Y   yxY w)z+Tests prepopulate placeholder configurationr5  rb  r   r   z<p>en default body 1</p>r`  z<p>en default body 2</p>rl  r#  r4  r   r  r   r8   z5^<p>en default body 1</p>\s*<p>en default body 2</p>$N)r"   r   r.   r   r   r   r?   assertRegex)rI   confr   r;   r<   contents         r5   test_plugins_prepopulatez,PlaceholderTestCase.test_plugins_prepopulate  s     !'3#)+E"F
 (4#)+E"F	$
 'DA 	`y.$?D//599z9JK$&G!%!1!14d!1!KGI)+w?GW&^_	` 	` 	`s   A-BBc                 @   ddiddiddid}| j                  t              5  t        |      5  t        ddd	      }|j	                  d	      j                  d
      }t        |j                                d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nrf  slot_bslot_cslot_a)r  r  r  rl  circular_pager4  r   r  )r   r   r"   r   r.   r   r   rw  )rI   circular_confr   r;   s       r5   4test_circular_inheritance_in_placeholder_conf_raiseszHPlaceholderTestCase.test_circular_inheritance_in_placeholder_conf_raises  s     (+ (+ (+

 34 	3*N 3"?NDI"33D9==8=L+//123	3 	33 3	3 	3s#   BAB7BB	BBc           	         dddddidddd	d
dddd	d
gdgii}t        |      5  t        ddd      }|j                  d      j                  d      }t	               }| j                  d|      |d<   t        ||       |j                         }| j                  t        |      d       | j                  |d   j                  d       | j                  |d   j                  d       | j                  |d   j                  d       | j                  |d   j                  |d   j                  k(  xr |d   j                  |d   k(         ddd       y# 1 sw Y   yxY w)zQ
        Validate a default textplugin with a nested default link plugin
        r5  rb  r   r   z1<p>body %(_tag_child_1)s and %(_tag_child_2)s</p>r  djangozhttps://www.djangoproject.com/r  r`  z
django-cmsr
  )r  ra  childrenrl  r#  r4  r   r  r   r8   r0  r   r   r   N)r"   r   r.   r   r   r   r?   get_plugins_listrV   r   r  r  r   )rI   r  r   r;   r<   r   s         r5   !test_plugins_children_prepopulatez5PlaceholderTestCase.test_plugins_children_prepopulate  s    !'3#)+^"_ 0<3;Nn*o
 0<3?Rn*o	%$
* 'DA 	hy.$?D//599z9JK$&G!%!1!14d!1!KGIW5!224GS\1-WQZ33\BWQZ33\BWQZ33\BOOGAJ--1B1BBfwqzGXGX\cde\fGfg	h 	h 	hs   D(EE"c                    t        ddd      }|j                  d      }|j                  d      D ]]  }|j                  j	                  |       |xj
                  dz  c_        |j                          |j                  j                  |       _ |j                          |j                  d      D ]  }t        |ddd        | j                  dd	      5  | j                         }| j                  j                  t        |t               j                         t        |t               j                         
       t#        |      }| j                  j%                  |      }|j                  d      D ]  }| j'                  |d|j
                  z         | j)                  |dt+        |j
                  ddd      z         | j)                  |dt+        |j
                  ddd      z         | j)                  |dt+        |j,                  d   j.                  j0                  j
                  ddd      z          	 d d d        y # 1 sw Y   y xY w)Nr   r  r   i  r   r   r   T)USE_THOUSAND_SEPARATORUSE_L10N)usernamepasswordz"placeholder_id": "%s".r0  ,)groupingthousand_sepz"plugin_id": "%s"z"clipboard": "%s"r8   )r   get_content_objr.   rY   remover   r   addrW  r   r   r  r   logingetattrr   USERNAME_FIELDr&   r   rJ  r   r   r<   r>   r  )rI   r   titler;   r  r   r   s          r5   $test_placeholder_pk_thousands_formatz8PlaceholderTestCase.test_placeholder_pk_thousands_format<  s   6#8$?$$T*006 	0K%%k2NNd"N"";/		0
 	006 	EK{L$VD	E]]$]F 	%%'DKK ~'7'F'FG ~'7'F'FG   +51H{{x0H#44T: ##H.F.WX&&6PS^_nq9rr &&1F;>>3YZil4mm &&'X--i8@@JJMMs]^mpqr	 	 	s   E&IIc                 n   h d}t        dddd      }|j                          |D ]  }t        |j                  d|        t         j                  j                  |j                        }|j                  j                         D cg c]  }|d	   	 }}| j                  |t        |             y
c c}w )f
        Checks the retrieval of filled languages for a placeholder in a django
        model
        >   r   r   frr]   rS   r   r^   r   rE  r   codeN)
r   r   r   r;   r  r   r   get_filled_languagesrV   set)rI   avail_langsr   r   langss        r5    test_placeholder_languages_modelz4PlaceholderTestCase.test_placeholder_languages_model^  s    
 )U5O
	   	<Dr~~}d;	< !!RUU!+*,..*M*M*OP$fPPc%j1 Qs   B2c                    h d}t        ddd      }|D ]  }|dk7  s	t        |d|z  |        |j                  d      j                  d      }|D ]  }t	        |d|        |j                  d      j                  d      }|j                         D cg c]  }|d	   	 }}| j                  |t        |             y
c c}w )r  >   r   r   r  z	test pager4  r   ztest page %scol_sidebarr  rE  r  N)r   r   r.   r   r   r  rV   r  )rI   r  r   r   r;   r  s         r5   test_placeholder_languages_pagez3PlaceholderTestCase.test_placeholder_languages_pager  s    
 );= 	GDt|#D.4*?F	G ++D155=5I   	9D{M48	9 ++D155=5I*5*J*J*LM$fMMc%j1 Ns   C))z%django.template.loaders.cached.Loader)z)django.template.loaders.filesystem.Loaderz.django.template.loaders.app_directories.Loader)TEMPLATE_LOADERSc                 "   t        t        d            }| j                  d|d   j                  j	                         d       t        d       t        t        d            }| j                  d|d   j                  j	                         d       y)a  
        This is the test for the low-level code that caused the bug:
        the placeholder scan corrupts the nodelist of the extends node,
        which is retained by the cached template loader, and future
        renders of that template will render the super block twice.
        +placeholder_tests/test_super_extends_2.htmlr]   r   zNtest_super_extends_1.html contains a block called 'one', but _2.html does not.zftest_super_extends_1.html still should not contain a block called 'one' after rescanning placeholders.N)r+   r   assertNotInblockskeysr6   )rI   r   s     r5   6test_cached_template_not_corrupted_by_placeholder_scanzJPlaceholderTestCase.test_cached_template_not_corrupted_by_placeholder_scan  s    & !.[!\]QK##%_	
 	LM .[!\]QK##%:	
r@   c                 r   t        d      }|j                  i       }| j                  dg|j                  d      D cg c]	  }d|v s| c}       t	        d       t        d      }|j                  i       }| j                  dg|j                  d      D cg c]	  }d|v s| c}       yc c}w c c}w )a  
        This is the test for the symptom of the bug: because the block
        context now contains two copies of the inherited block, that block
        will be executed twice, and if it adds content to {{block.super}},
        that content will be added twice.
        r  Whee
N)r   renderrV   splitr6   )rI   r3   rX  os       r5   4test_super_extends_not_corrupted_by_placeholder_scanzHPlaceholderTestCase.test_super_extends_not_corrupted_by_placeholder_scan  s    $   MN$&v||D/A#Q!Vq[A#QRLM MN$&v||D/A#Q!Vq[A#QR $R $Rs   	B/
B/
	B4
#B4
c                 ^   t        ddd      }| j                  |      }| j                  t        j                  j                  |      |j                         d d       t        dd|      }| j                  t        j                  j                  |      |j                         d	 d       y
)z
        This tests when a title is created, the source field for the
        created placeholders are set to that title.
        ztest page enr4  r   c                     | S r1    xs    r5   <lambda>zLPlaceholderTestCase.test_sets_source_when_title_is_created.<locals>.<lambda>       r@   F	transformorderedr   ztest page dec                     | S r1   r  r  s    r5   r  zLPlaceholderTestCase.test_sets_source_when_title_is_created.<locals>.<lambda>  r  r@   N)r   get_pagecontent_objassertQuerySetEqualr   r  get_for_objr.   r   )rI   r   page_content_enpage_content_des       r5   &test_sets_source_when_title_is_createdz:PlaceholderTestCase.test_sets_source_when_title_is_created  s    
 >>4@ 2248  ++O<,,.!	 	! 	
 .dNDI  ++O<,,.!	 	! 	
r@   c                    t        ddd      }| j                  | j                               5  | j                  ||d      }ddd       | j	                  |      }| j	                        }t
        j                  j                  |      }t
        j                  j                  |      }| j                  |j                         |j                                y# 1 sw Y   xY w)z
        This tests when a title is copied, the source field for the
        created placeholders are set to the new title.
        zsource pager4  r   r   r.  N)
r   rF   r  	copy_pager  r   r  r  rV   rV  )rI   r   new_pagepage_contentnew_page_contentpage_content_plhsnew_page_content_plhss          r5   %test_sets_source_when_title_is_copiedz9PlaceholderTestCase.test_sets_source_when_title_is_copied  s    
 =.$?$$T%7%7%9: 	>~~dD1~=H	> //533H='//;;LI + 3 3 ? ?@P Q*0024I4O4O4QR	> 	>s   CC"c                    ddl m} t        j                  j	                  d      }| j
                  j                  |j                               }t        j                  j                  |      }| j                  |j                         d       | j                  | j                               5  | j
                  j                  t        |            }ddd       t        j                  j                  |      }| j                  |j                         d       | j                  | j                               5  | j
                  j                  t        |            }ddd       t        j                  j                  |      }| j                  |j                         d        ||      }| j                  t!        |      d       |D ];  }| j#                  |d|j                  |j$                        j&                  z         = d	|_        |j+                          | j                  | j                               5  | j
                  j                  t        |            }ddd       t        j                  j                  |      }t        j                  j                  |      }| j                  |j                         d
        ||      }| j                  t!        |      d       |D ];  }| j#                  |d|j                  |j$                        j&                  z         = y# 1 sw Y   \xY w# 1 sw Y   xY w# 1 sw Y   xY w)z
        This tests the implementation for external objects to use the {% placeholder %}
        template tag where placeholders are created with the source field
        set to the current object.
        r   )!get_declared_placeholders_for_objpoll 1r  r   NzM<template data-cms id="cms-plugin-child-classes-%s" type="text/cms-template">r  zfancy_poll_app/detail2.htmlr   r0  )cms.utils.placeholderr  r   r  r  r   r   get_absolute_urlr   r  rV   rV  rF   r  r&   r'   r   rJ  r2   r   r3   r   )rI   r  pollr   rY   declared_placeholdersr;   s          r5   1test_sets_source_when_external_object_is_renderedzEPlaceholderTestCase.test_sets_source_when_external_object_is_rendered  s    	L  ''X'6 ;;??4#8#8#:;"**66t<++-q1 $$T%7%7%9: 	B{{':4'@AH	B #**66t<++-q1 $$T%7%7%9: 	G{{'?'EFH	G #**66t<++-q1 A$ G23Q70 	K_""(8(8"9<<=	 6		 $$T%7%7%9: 	G{{'?'EFH	G #**66t< #**66t<++-q1 A$ G23Q70 	K_""(8(8"9<<=	M	B 	B	G 	G(	G 	Gs$   .%L-9%L:>%M-L7:MMc                    t         j                  j                  d      }| j                  | j	                               5  | j
                  j                  t        |             ddd       | j                  |j                  j                         t        j                  j                  |      d d       y# 1 sw Y   UxY w)z
        This tests the PlaceholderRelationField where it returns (does a reverse relation)
        the placeholders for the attached object.
        r  r  Nc                     | S r1   r  r  s    r5   r  zEPlaceholderTestCase.test_placeholder_relation_field.<locals>.<lambda>:  s    `a r@   Fr  )r   r  r  rF   r  r   r   r&   r  rY   allr   r  )rI   r  s     r5   test_placeholder_relation_fieldz3PlaceholderTestCase.test_placeholder_relation_field/  s    
   ''X'6$$T%7%7%9: 	7KKOO/56	7 	  !!#[%8%8%D%DT%JVakp 	! 	
	7 	7s    %B99Cc                 r   ddl m} t        j                  j	                  d      } ||j
                  d      }| j                  t        |t                     | j                  |j                  d       | j                  |j
                  j                         j                         d        ||j
                  d      }| j                  |j                  d       | j                  |j
                  j                         j                         d	       | j                  | ||j
                  d             y
)zL
        This tests the get slot method of PlaceholderRelationField
        r   )get_placeholder_from_slotr  r  slot_1r  r   slot_2r   N)r  r  r   r  r  rY   r  
isinstancer   rV   r2   r  rV  )rI   r  r  r  r  s        r5   (test_placeholder_relation_field_get_slotz<PlaceholderTestCase.test_placeholder_relation_field_get_slot=  s    
 	D  ''X'6*4+<+<8L
6;78h/**..0668!<*4+<+<hGh/**..0668!<!:4;L;Lh!WXr@   N)=__name__
__module____qualname__rK   rO   rZ   r`   rb   rd   rg   rk   rm   ro   rr   ru   rx   r|   r~   r   r   r   r   r   r   r   r   r   r  r(  r+  r2  r=  rA  r
   rL  rN  rP  rY  r^  rq  ry  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r@   r5   rB   rB   >   s   (7THHTKXXU]\@[[[[NH4I$mL?B/b?448487*rW<%XN e,W -W( e,W -W$m)$44MlN<HaY	NFG
]<`43%hN D2(2. 




2 

S
S"
2S ;z
Yr@   rB   c                   *    e Zd Zd Zd Zd Zd Zd Zy)PlaceholderActionTestsc                     t               }| j                  |j                         g        | j                  |j	                                y r1   )r*   rV   get_copy_languagesassertFalsecopy)rI   actionss     r5   test_placeholder_no_actionz1PlaceholderActionTests.test_placeholder_no_actionR  s7    %'335r:(r@   c                 T   t               }t        j                  j                  d      }t        j                  j                  d      }t        j                  j                  d      }d}|j	                  |j
                  t        |      }|j	                  |j
                  t        |      }|j	                  |j
                  t        |      }d}	d}
| j                  t        |      |	h       | j                  t        |      |	|
h       | j                  t        |      |
h       y )Nr  language_coder   r   r;   )r   r[  )r  French)r)   r   r  r   r  r;   rV   r  )rI   r  r  r   r   	fieldnamefr_copy_languagesde_copy_languagesen_copy_languagesENFRs              r5   0test_mlng_placeholder_actions_get_copy_languageszGPlaceholderActionTests.test_mlng_placeholder_actions_get_copy_languagesW  s    (*!!%%D%9!!%%D%9!!%%D%9!	#66r~~|U^_#66r~~|U^_#66r~~|U^_./"6./"b:./"6r@   c                    t               }t        j                  j                  d      }t        j                  j                  d      }| j	                  |j
                  j                         j                         d       | j	                  |j
                  j                         j                         d       |j                  |j
                  ddt        d      }| j	                  t        |      d       | j                  |      }| j                  |      }| j	                  |j
                  j                         j                         d       | j	                  |j
                  j                         j                         d       y Nr  r  r   r   r   r;   r)   r   r  r   rV   r;   r  rV  r  r   rW  rI   r  r  r   new_pluginss        r5   "test_mlng_placeholder_actions_copyz9PlaceholderActionTests.test_mlng_placeholder_actions_copyf     (*!!%%D%9!!%%D%9335;;=qA335;;=qAll2>>4VZ[[)1-[[_[[_335;;=qA335;;=qAr@   c                    t               }t        j                  j                  d      }t        j                  j                  d      }| j	                  |j
                  j                         j                         d       | j	                  |j
                  j                         j                         d       |j                  |j
                  ddt        d      }| j	                  t        |      d       | j                  |      }| j                  |      }| j	                  |j
                  j                         j                         d       | j	                  |j
                  j                         j                         d       y r  r  r   s        r5   (test_mlng_placeholder_actions_empty_copyz?PlaceholderActionTests.test_mlng_placeholder_actions_empty_copyv  r#  r@   c                    t               }t        j                  j                  d      j	                  d        t        j                  j                  d      }t        j                  j                  d      }| j                  |j                  d        | j                  |j                  j                         j                         d       |j                  |j                  ddt        d      }| j                  |d       | j                  |      }| j                  |      }t        j                  j                  d      }t        j                  j                  d      }y )Nnlr  r;   r   r   r;   F)r)   r   r  r   updater   rV   r;   r  rV  r  rW  )rI   r  r   r'  okays        r5   ,test_mlng_placeholder_actions_no_placeholderzCPlaceholderActionTests.test_mlng_placeholder_actions_no_placeholder  s   (*##$#7>>4>P!!%%D%9!!%%D%9.335;;=qA||BNND-tTu%[[_[[_!!%%D%9!!%%D%9r@   N)r  r  r	  r  r  r"  r%  r+  r  r@   r5   r  r  Q  s    )
7B B :r@   r  FrB  c                   P    e Zd Zd ZddZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)PlaceholderModelTestsc                     t        |d       S )Nc                      y)NFr  )strings    r5   r  z5PlaceholderModelTests.get_mock_user.<locals>.<lambda>  s    r@   )is_superuserhas_permr#   rI   r"  s     r5   get_mock_userz#PlaceholderModelTests.get_mock_user  s    ")
 	
r@   c                 :    t        || j                  |            S )N)r"  r  )r$   r4  r3  s     r5   get_mock_requestz&PlaceholderModelTests.get_mock_request  s    9K9KI9VWWr@   c                     t         j                  j                  dd      }| j                  d      }|j	                  |      }| j                  |       y )NrD   ,  r2   default_widthT)r   r  r  r4  has_change_permissionr  rI   r   r  results       r5   3test_check_placeholder_permissions_ok_for_superuserzIPlaceholderModelTests.test_check_placeholder_permissions_ok_for_superuser  sI      ''V3'G!!$'))$/r@   c                     t         j                  j                  dd      }| j                  d      }|j	                  |      }| j                  |       y )NrD   r8  r9  F)r   r  r  r4  r;  r  r<  s       r5   /test_check_placeholder_permissions_nok_for_userzEPlaceholderModelTests.test_check_placeholder_permissions_nok_for_user  sK      ''V3'G!!%())$/ r@   c                    ddl m} t        j                  j	                  dd      }| j                  d      }t        j                  j	                  dddd	
      }||_        |j                  |      }| j                  |       |j                  j                  d||       |j                  |      }| j                  |       y )Nr   )UserObjectPermissionrD   r8  r9  r]   rS   rT   r^   r   change_example1)2cms.test_utils.project.objectpermissionsapp.modelsrB  r   r  r  rE   r   sourcer;  r  assign_permr  )rI   rB  r   r  r   r=  s         r5   4test_check_placeholder_permissions_with_object_permszJPlaceholderModelTests.test_check_placeholder_permissions_with_object_perms  s    [  ''V3'G  ($$E%X^$_	 ))$/  	$$001BD"M))$/r@   c                     t         j                  j                  dd      }t        |      }| j	                  |d       y NrD   r8  r9  )r   r  r  r   rV   rI   r   r=  s      r5   test_check_unicode_renderingz2PlaceholderModelTests.test_check_unicode_rendering  s6      ''V3'G2(r@   c                     t         j                  j                  dd      }|j                         }| j	                  |d        y rI  )r   r  r  r  rV   rJ  s      r5   !test_excercise_get_attached_modelz7PlaceholderModelTests.test_excercise_get_attached_model  s;      ''V3'G'')&r@   c                 ~    t         j                  j                  dd      }| j                  |j                  d        y rI  )r   r  r  rV   rE  )rI   r   s     r5   !test_excercise_get_attached_fieldz7PlaceholderModelTests.test_excercise_get_attached_field  s1      ''V3'GD)r@   c                    t        dddd      }|j                          |j                  }|j                         }| j	                  |t                t        |ddd	       |j                         }| j	                  |t                y )
Nr]   rS   r   r^   r   r   r   zen bodyr   )r   r   r;   r  rV   r   )rI   r   r   r=  s       r5   -test_excercise_get_attached_models_notpluginszCPlaceholderModelTests.test_excercise_get_attached_models_notplugins  sn    U5O
	^^'')*2|T	:'')*r@   c                     t        dddd      }|j                          |j                  }| j                  |j                  |       y )Nr]   rS   r   r^   r   )r   r   r;   rV   rE  )rI   r   r   s      r5   %test_excercise_get_placeholder_sourcez;PlaceholderModelTests.test_excercise_get_placeholder_source  s@    	
 		^^B'r@   c                 f   t               }| j                  dt        |             | j                  dt        |             t         j                  j	                  d      }| j                  d|j
                   t        |             | j                  d|j                   dt        |             y )Nzid=Nonezslot=''rD   r  zid=zslot='')r   assertInreprr  r  r   r2   )rI   
unsaved_phsaved_phs      r5   	test_reprzPlaceholderModelTests.test_repr  s     ]
ij!12ij!12&&--6-:HKK=)4>:x}}oQ/h@r@   N)T)r  r  r	  r4  r6  r>  r@  rG  rK  rM  rO  rQ  rS  rZ  r  r@   r5   r-  r-    s;    
X ! ")
'
*+	(Ar@   r-  c                       e Zd Zd Zd Zy)PlaceholderConfTestsc                    t        ddd      }|j                  d      j                  d      }dddgiddgid	}t        j                  d      }t        |
      5  t        t        j                  ||            }| j                  t        |      d|       | j                  |d   |       d d d        y # 1 sw Y   y xY w)Nr   r4  r   r5  r  r   r   r  col_tworu  rl  r   r   )
r   r.   r   r   
get_pluginr"   r   get_all_pluginsrV   r   )rI   r   r;   r  r  r   s         r5    test_get_all_plugins_single_pagez5PlaceholderConfTests.test_get_all_plugins_single_page  s    6>48++D155:5F L,7 L>&	
 !++L9
&DA 	5;66{DIJGS\1g6WQZ4	5 	5 	5s   AB66B?c                    t        ddd      }t        dt        j                  d|      }|j                  d      j	                  d      }dd	d
gidd
gid}t        j                  d
      }t        |      5  t        t        j                  ||            }| j                  t        |      d|       | j                  |d   |       d d d        y # 1 sw Y   y xY w)Nr   r4  r   r   r   r5  r  r   r   r  r^  rl  r   r   )r   r   TEMPLATE_INHERITANCE_MAGICr.   r   r   r`  r"   r   ra  rV   r   )rI   r   r   r;   r  r  r   s          r5   test_get_all_plugins_inheritz1PlaceholderConfTests.test_get_all_plugins_inherit  s    X~t<69#G#GV\]++D155:5F L,7 L>&	
 !++L9
&DA 	5;66{DIJGS\1g6WQZ4	5 	5 	5s   9ACCN)r  r  r	  rb  re  r  r@   r5   r\  r\    s    5"5r@   r\  c                   \    e Zd ZddZddZd Zd Zd ZddZddZ	dd	Z
dd
Zd ZddZy)PlaceholderPluginTestsBasec                 B    t         j                  j                  |      S )Nr  )r   r  r  )rI   r2   s     r5   _create_placeholderz.PlaceholderPluginTestsBase._create_placeholder  s    ""))t)44r@   Nc                     t         j                  j                  dd|||      }|j                  j                  } |       }|j                  |       |j                          |S )Nr   StylePlugin)r   r  r   r   r;   )r   r  r  plugin_classmodelset_base_attrr   )rI   r;   r   r   baseplugin_modelr%  s          r5   _create_pluginz)PlaceholderPluginTestsBase._create_plugin  sb      ''%# ( 
 ((..6"r@   c              #      K   |j                   j                         D ])  }|j                   | j                  |      E d {    + y 7 wr1   )r   r  r   _unpack_descendants)rI   r   rf   s      r5   rs  z.PlaceholderPluginTestsBase._unpack_descendants$  sF     ))--/ 	7E((N//666	7 7s   A AA
Ac                 d    | j                         | _        | j                  | j                         y r1   )ri  r;   create_pluginsrN   s    r5   rK   z PlaceholderPluginTestsBase.setUp*  s'    335D,,-r@   c           	          t        dd      D ]J  }t        |xs | j                  dd      }t        d      D ]  }t        |xs | j                  ddd|       ! L y )Nr   	   rk  r   r0  z
last-child)r   r   r;   )rI   r;   r   r   js        r5   ru  z)PlaceholderPluginTestsBase.create_plugins.  se    q! 	gA ?t/?/?PTUF1X g;:$*:*:M4Q]_efg	gr@   c                 `    | j                  |      j                  d      j                         S NTparent__isnull)r  r   firstrI   r;   s     r5   get_first_root_pluginz0PlaceholderPluginTestsBase.get_first_root_plugin4  s*    ,3343HNNPPr@   c                 `    | j                  |      j                  d      j                         S rz  )r  r   r   r~  s     r5   get_last_root_pluginz/PlaceholderPluginTestsBase.get_last_root_plugin7  s*    ,3343HMMOOr@   c                 ^    || j                   }t        j                  j                  |      S )Nr(  )r;   r   r  r   r~  s     r5   r  z&PlaceholderPluginTestsBase.get_plugins:  s-    **K  ''K'@@r@   c                     i }| j                  |      j                  d      D ]   }| j                  |      ||j                  <   " |S rz  )r  r   get_plugin_descendantsr   )rI   r;   r   root_plugins       r5   get_plugin_treez*PlaceholderPluginTestsBase.get_plugin_tree?  sO    ++K8??t?T 	LK#'#>#>{#KD 	Lr@   c                 6    t        | j                  |            S r1   )r   rs  )rI   r%  s     r5   r  z1PlaceholderPluginTestsBase.get_plugin_descendantsF  s    D,,V455r@   c                     | j                  |      j                  dd      }t        |d      D cg c]	  \  }}||f }}}| j                  ||       yc c}}w )z7
        plugins should be ordered by position
        r   r   r   N)r  values_list	enumerateassertSequenceEqual)rI   r   r;   new_treeposr   expecteds          r5   assertPluginTreeEqualsz1PlaceholderPluginTestsBase.assertPluginTreeEqualsI  sY     ##K0<<T:N-6w-BC'#rRICC  84 Ds   A)rd  r1   )r  r  r	  ri  rq  rs  rK   ru  r  r  r  r  r  r  r  r@   r5   rg  rg    s=    57.gQPA
65r@   rg  c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)PlaceholderFlatPluginTestsc                 .   | j                         }t        | j                         j                  dd            }| j                         j	                  d      D ]  }|j
                  g||j
                     z   D ]  }|j                  |        |j                          | j                  j                  |       | j                         j                  dd      }t        |d      D cg c]	  \  }}||f }}}| j                  ||        yc c}}w )z
        Deletes all root plugins from the plugin tree,
        one by one, comparing plugin positions at every iteration.
        r   Tflatr{  r   r   Nr  r   r  r  r   r   r  refresh_from_dbr;   delete_pluginr  r  	rI   r   plugin_tree_allr%  r   r  r  r   r  s	            r5   test_deletez&PlaceholderFlatPluginTests.test_deleteS  s    
 ##%t//1==d=NO&&(//t/D 		9F$ii[4		?: 2	&&y12 ""$**62'')55dJGH1:?A1NOgc2S	OHO$$Xx8		9 P   +Dc                    | j                         }|j                  g| j                  |      z   }t        | j	                         j                  dd            }t        | j	                         j                  d      j                         j                  |j                        j                  dd            }|D ]  \  }}| j                  j                  ||       |j                          t        |      D ]9  \  }}|j                  |      }	|j                  |       |j                  |	|       ; | j!                  |        y)z
        Moves the last plugin in the tree to the left,
        one step at a time until it reaches the beginning of the tree.
        r   Tr  r{  r  r   N)r  r   r  r   r  r  r   reverseexcluder;   r   r  r  indexr  insertr  )
rI   r%  plugin_treer  	positionsr   r   edger   target_indexs
             r5   test_move_leftz)PlaceholderFlatPluginTests.test_move_leftf  s$   
 **,yykD$?$?$GGt//1==d=NOV4V(WYW		W"[z*
	 & 	9LB((:""$#,[#9 @i.44R8&&y1&&|Y?@ ''8	9r@   c                 t   i }| j                         j                  d      }|j                         }|j                         }||dz     }|j	                         }t        | j                         j                  dd            }|||fD ])  }t        | j                  |            ||j                  <   + ||fD ]  }	| j                  j                  ||	j                         |j                          t        |j                  g||j                     z         D ]C  \  }
}|j                  |	j                        }|j                  |       |j!                  ||       E | j                         j                  dd      }t        |d      D cg c]	  \  }}||f }}}| j#                  ||        y c c}}w NTr{  r   r   r  r   r   )r  r   rV  r}  r   r   r  rs  r   r;   r   r   r  r  r  r  r  r  )rI   r   	root_treerV  first_pluginmiddle_pluginlast_pluginr  r  r   r  r   r  r  r  r   r  s                    r5   test_move_left_middlez0PlaceholderFlatPluginTests.test_move_left_middle  s   $$&--T-B	! (!%1*-nn&t//1==d=NO(-E 	OK#'(@(@(M#ND 	O ,\: 	9M((m6L6LM'') $-knn-=[^^@T-T#U @i.44]5E5EF&&y1&&|Y?@ '')55dJGH1:?A1NOgc2S	OHO$$Xx8	9 Ps   F4c                 X   | j                         }| j                         j                         }t        | j                         j	                  dd            }t        | j                         j                  d      j                  |j                        j	                  dd            }|D ]  \  }}| j                  j                  ||       |j                          |j                  |      t        ||         z   }t        |j                  g||j                     z         D ](  \  }}	|j                  |	       |j                  ||	       * | j                         j	                  dd      }
t        |d      D cg c]	  \  }}||f }}}| j!                  |
|        y c c}}w )Nr   Tr  r{  r  r   r   )r  r  r}  r   r  r   r  r   r;   r   r  r  r   r  r  r  r  )rI   r   r%  r  r  r   r   r  r  r   r  r  r  s                r5   test_move_rightz*PlaceholderFlatPluginTests.test_move_right  s   ##%!!#))+t//1==d=NO%%T%:BBfiiBP\\]acmn
	 & 
	9LB((:""$*004s48}DL#,fii[4		?-J#K @i&&y1&&|Y?@ '')55dJGH1:?A1NOgc2S	OHO$$Xx8
	9 Ps    F&c                    i }| j                         j                  d      }|j                         }|j                         }||dz     }|j	                         }t        | j                         j                  dd            }|||fD ])  }t        | j                  |            ||j                  <   + ||fD ]  }	| j                  j                  ||	j                         |j                          |j                  |	j                        t        ||	j                           z   }
t        |j                  g||j                     z         D ](  \  }}|j!                  |       |j#                  |
|       * | j                         j                  dd      }t        |d      D cg c]	  \  }}||f }}}| j%                  ||        y c c}}w r  )r  r   rV  r}  r   r   r  rs  r   r;   r   r   r  r  r   r  r  r  r  )rI   r   r  rV  r  r  r  r  r  r   r  r  r   r  r  r   r  s                    r5   test_move_right_middlez1PlaceholderFlatPluginTests.test_move_right_middle  s   $$&--T-B	! (!%1*-nn&t//1==d=NO(-E 	OK#'(@(@(M#ND 	O ,[9 
	9M((}7M7MN((**001A1ABSmN^N^I_E``L#,loo->looAV-V#W @i&&y1&&|Y?@ '')55dJGH1:?A1NOgc2S	OHO$$Xx8
	9 Ps   (Gc                 h   i }| j                         j                  d      j                         }| j                         j                  d      j                         }t	        | j                         j                  dd            }||fD ])  }t	        | j                  |            ||j                  <   + | j                  j                  ||j                         |j                          t        |j                  g||j                     z         D ]C  \  }}|j                  |j                        }|j                  |       |j                  ||       E | j                         j                  dd      }	t        |d      D 
cg c]	  \  }
}||
f }}
}| j!                  |	|       yc c}}
w )zK
        Moves the last plugin in the tree to the top of the tree.
        Tr{  r   r  r   r   N)r  r   r}  r   r   r  rs  r   r;   r   r   r  r  r  r  r  r  )rI   r   r  r  r  r  r  r   r  r  r  r   r  s                r5   test_move_to_topz+PlaceholderFlatPluginTests.test_move_to_top  s    '')000EKKM&&(//t/DIIKt//1==d=NO(+6 	OK#'(@(@(M#ND 	O 	$$[,2G2GH##%(+..)9D<P)PQ 	<OD)*00AL""9-""<;	< ##%11$
C-6-JK'#rRIKK  84 Ls   
F.c                    | j                         j                  d      }| j                         }t        | j                         j	                  dd            }| j                  d      }| j                  |       t        | j                  |      j	                  dd            }|D ]  }|j                  g||j                     z   }|j                  dg       | j                  j                  |d|	       t        |      D ](  \  }}	|j                  |	       |j                  ||	       * | j                  |       | j                  ||
        y )NTr{  r   r  r   r   fieldsr   r   r(  )r  r   r  r   r  ri  ru  r   r  r;   r   r  r  r  r  )
rI   source_pluginssource_tree_by_rootsource_plugin_tree_allr   target_plugin_tree_allr%  r  r  r   s
             r5   test_move_to_placeholder_topz7PlaceholderFlatPluginTests.test_move_to_placeholder_top  sK   ))+22$2G"224!%d&6&6&8&D&DTPT&D&U!V))(3F#!%d&6&6v&>&J&J4VZ&J&[!\$ 		TF!99+(;FII(FFK"":,"7((v(N#,[#9 ?i&--i8&--dI>? ''(>?''(>F'S		Tr@   c                 Z   i }| j                         j                         }| j                         j                         }t        | j                         j	                  dd            }||fD ])  }t        | j                  |            ||j                  <   + | j                  j                  ||j                         |j                          |j                  |j                        t        ||j                           z   }t        |j                  g||j                     z         D ](  \  }}|j                  |       |j                  ||       * | j                         j	                  dd      }	t        |d      D 
cg c]	  \  }
}||
f }}
}| j!                  |	|       y c c}}
w )Nr   Tr  r   r   )r  r}  r   r   r  rs  r   r;   r   r   r  r  r   r  r  r  r  )rI   r   r  r  r  r  r  r  r   r  r  r   r  s                r5   test_move_to_bottomz.PlaceholderFlatPluginTests.test_move_to_bottom  s}   '')//1&&(--/t//1==d=NO(+6 	OK#'(@(@(M#ND 	O 	$$\;3G3GH$$&&,,[^^<s4CW?XX(,//):T,//=R)RS 	<OD)""9-""<;	< ##%11$
C-6-JK'#rRIKK  84 Ls   F'c                    | j                         j                  d      }| j                         }t        | j                         j	                  dd            }| j                  d      }| j                  |       t        | j                  |      j	                  dd            }t        |      dz   }|D ]  }|j                  g||j                     z   }|j                  dg       | j                  j                  |||	       t        |      D ]0  \  }	}
|dz
  |	z   }|j                  |
       |j                  ||
       2 |t        |      z  }| j                  |       | j                  ||
        y )NTr{  r   r  r   r   r   r  r  r(  )r  r   r  r   r  ri  ru  r   r   r  r;   r   r  r  r  r  )rI   r  r  r  r   r  r   r%  r  r  r   r  s               r5   test_move_to_placeholder_bottomz:PlaceholderFlatPluginTests.test_move_to_placeholder_bottom  s|   ))+22$2G"224!%d&6&6&8&D&DTPT&D&U!V))(3F#!%d&6&6v&>&J&J4VZ&J&[!\459$ 	TF!99+(;FII(FFK"":,"7((U[(\#,[#9 @i(1,4&--i8&--eY?	@
 s;//O''(>?''(>F'S	Tr@   N)r  r  r	  r  r  r  r  r  r  r  r  r  r  r@   r5   r  r  R  s1    9&94929(905.T&5(Tr@   r  c                   "    e Zd ZdZd Zd Zd Zy)PlaceholderNestedPluginTestsa=  
    Same tests as for PlaceholderFlatPluginTests but now with a different plugin tree:

    ::

        Parent 1
          Parent 2
            Child
        Parent 1
          Parent 2
            Child
        Parent 1
          Parent 2
            Child
        Parent 1
          Parent 2
            Child
    c                     t        ddd      D ]C  }| j                  ||      }| j                  |||dz         }| j                  |||dz          E y )Nr      r0  r.  )r   r   r   )r   rq  )rI   r;   r   r   parent_2s        r5   ru  z+PlaceholderNestedPluginTests.create_plugins/  sg    q"a 	NA((q(AF**;vPQTUPU*VHHq1uM	Nr@   c                    | j                         j                  d      j                         }| j                         }t	        | j                         j                  dd            }| j                  d      }| j                  |       t        ddd|	      }|j                  |      }t	        | j                  |      j                  dd            }|j                  g||j                     z   }|j                  d
g       | j                  j                  |d||       t        |      D ]+  \  }}	|j                  |	       |j!                  d|z   |	       - | j#                  |       | j#                  ||       y )NTr{  r   r  r   r   rk  r   )r   r  r   r;   r   r  r   )r   r   r(  )r  r   r}  r  r   r  ri  ru  r   r   r   r  r;   r   r  r  r  r  )
rI   r%  r  r  r   r   r  r  r  r   s
             r5   %test_move_to_placeholder_under_parentzBPlaceholderNestedPluginTests.test_move_to_placeholder_under_parent5  sl   !!#**$*?EEG"224!%d&6&6&8&D&DTPT&D&U!V))(3F#!4]UVdjk))-8!%d&6&6v&>&J&J4VZ&J&[!\yyk$7		$BBzl3$$VQ6Yf$g(5 	?OD)")))4"))!d(I>	? 	##$:;##$:#Or@   c                 .   | j                         }t        | j                         j                  dd            }| j                         j	                  d      D ]  }|j
                  g||j
                     z   D ]  }|j                  |        |j                          | j                  j                  |       | j                         j                  dd      }t        |d      D cg c]	  \  }}||f }}}| j                  ||        y c c}}w )Nr   Tr  r{  r   r   r  r  s	            r5   test_delete_singlez/PlaceholderNestedPluginTests.test_delete_singleI  s    ##%t//1==d=NO&&(//t/D 		9F$ii[4		?: 2	&&y12 ""$**62'')55dJGH1:?A1NOgc2S	OHO$$Xx8		9 Pr  N)r  r  r	  __doc__ru  r  r  r  r@   r5   r  r    s    &NP(9r@   r  N)Sdjango.confr   django.contrib.authr   django.core.exceptionsr   django.templater   r   django.template.loaderr   django.testr	   django.test.utilsr
   django.utils.encodingr   django.utils.numberformatr   sekizai.contextr   cmsr   cms.apir   r   r   cms.exceptionsr   r   cms.models.fieldsr   cms.models.placeholdermodelr   cms.models.pluginmodelr   cms.models.settingmodelsr   cms.plugin_poolr    cms.test_utils.fixtures.fakemlngr   &cms.test_utils.project.fakemlng.modelsr   <cms.test_utils.project.placeholder_relation_field_app.modelsr   ,cms.test_utils.project.placeholderapp.modelsr   r   r   'cms.test_utils.project.sampleapp.modelsr   cms.test_utils.testcasesr    r!   $cms.test_utils.util.context_managersr"   cms.test_utils.util.mockr$   cms.tests.test_toolbarr%   cms.toolbar.utilsr&   r'   r(   r  r)   r*   r+   r,   r-   r.   cms.utils.urlutilsr/   r6   r?   rB   r  r-  r\  rg  r  r  r  r@   r5   <module>r     s     . 7 9 /   / + , *  @ @ K . 3 , 1 ' = ? 
 = H J 4 2 
  -:OPY0 PYf D:-{ D:N %(QAO[ QA )QAh"58 "5J=5 =5@FT!; FTR;9#= ;9r@   