
    BhV                     r    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  G d d	e      Zy
)    )Text)
add_plugincreate_page)Page)Placeholder)	CMSPlugin)PluginsTestBaseCase)copy_plugins_to_placeholderc                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)NestedPluginsTestCasec           	         d}|j                         }t        ||      D ]  \  }}d}| j                  |j                  |d   |d|d   |j                  fz         | j                  |j                  ||d||j                  fz         | j                  |j
                  |d   |d|d   |j
                  fz         |dz  } y )N   zExpected %s %s. Got %s instead.r   idpositionparent)get_pluginszipassertEqualpkr   	parent_id)selftreeplaceholdercounterpluginsplugindatamsgs           M/home/dcms/DCMS/lib/python3.12/site-packages/cms/tests/test_nested_plugins.pycompare_plugin_treez)NestedPluginsTestCase.compare_plugin_tree   s    ))+. 	LFD3CVYYQd1gvyy7Q1QRV__gsj'SYSbSb=c7cdV--tAwxaRXRbRb>c8cdqLG	    c                    |D ]t  }|j                         }t        j                  j                  |j                        }t        |j                         |       |j                         }| j                  |j                         |j                                t        ||      D ]  \  }}| j                  t        j                  j                  |j                        j                  t        j                  j                  |j                        j                         | j                  |j                  |j                         | j                  |j                         |j                                 w S )a7  
        This function is not itself a test; rather, it can be used by any test
        that has created placeholders. It will check that whatever the plugin
        structure in the placeholder, it will be copied accurately when they are
        copied.

        placeholders is a list of placeholders
        slotr   r   )r   r   objectscreater$   r
   r   countr   r   getr   bodyr   _get_descendants_count)r   placeholdersoriginal_placeholderoriginal_pluginscopied_placeholdercopied_pluginsoriginalcopys           r   #copy_placeholders_and_check_resultsz9NestedPluginsTestCase.copy_placeholders_and_check_results   sK    %1 	   4??A "-!4!4!;!;AUAZAZ!;!['$002.
 0;;=N  &&($$& #&&6"G 	$  LL$$$499LL$$$055   !2!2DMMB  335//1	+	@ "!r!   c                 &$   t        d      }|j                          t        |ddd      }t        |ddd|      }| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      g       t        |ddd
|      }| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      g       t        |ddd|      }| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      g       | j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      g       t        |ddd      }t        |ddd|      }| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      g       t        |ddd|      }| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      g       | j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      g       | j                  |      }t        |ddd|      }	| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      t        j
                  j                  |	j                  	      g       t        |ddd| j                  |            }
| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |
j                  	      g       t        |ddd| j                  |            }| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      g       |j                         }| j                  |j                         d       t        |ddd|d      }| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      g       t        |ddd| j                  |      d      }| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      t        j
                  j                  |	j                  	      g       t        |ddd| j                  |      d      }| j                  t        j
                  j                  |j                  	      j                         t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      g       t        |ddd      }| j                  t        j
                  j                  d      t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      t        j
                  j                  |j                  	      g       |j                  df|j                  df|j                  |j                  f|j                  |j                  f|j                  |j                  f|j                  |j                  f|	j                  |j                  f|j                  |j                  f|
j                  |j                  f|j                  df|j                  |j                  f|j                  |j                  f|j                  |j                  f|j                  dfg}| j                  |g       | j!                  ||       |j                  df|j                  |j                  f|j                  |j                  f|j                  |j                  f|	j                  |j                  f|j                  df|j                  df|j                  |j                  f|
j                  |j                  f|j                  df|j                  |j                  f|j                  |j                  f|j                  |j                  f|j                  dfg}|j#                  | j                  |      d       | j!                  ||       | j                  |g       |j                  df|j                  |j                  f|j                  |j                  f|j                  |j                  f|	j                  |j                  f|j                  df|j                  df|j                  |j                  f|
j                  |j                  f|j                  df|j                  |j                  f|j                  |j                  f|j                  |j                  f|j                  dfg}| j                  |      }|j#                  | j                  |      |j$                  |j&                         | j!                  ||       | j                  |g       |j                  df|
j                  |j                  f|j                  df|j                  |j                  f|j                  |j                  f|j                  |j                  f|	j                  |j                  f|j                  df|j                  df|j                  df|j                  |j                  f|j                  |j                  f|j                  |j                  f|j                  dfg}|j#                  | j                  |      dd       | j!                  ||       | j                  |g       |j                  df|j                  |j                  f|
j                  |j                  f|j                  |j                  f|j                  |j                  f|j                  |j                  f|	j                  |j                  f|j                  df|j                  df|j                  df|j                  |j                  f|j                  |j                  f|j                  |j                  f|j                  dfg}|j#                  | j                  |      d | j                  |             | j!                  ||       | j                  |g       |j                  df|j                  |j                  f|j                  |j                  f|
j                  |j                  f|j                  |j                  f|j                  |j                  f|j                  |j                  f|	j                  |j                  f|j                  df|j                  df|j                  df|j                  |j                  f|j                  |j                  f|j                  dfg}| j                  |      }|j#                  | j                  |      |j$                  dz   |       | j!                  ||       | j                  |g       y)!a  
        Create a deeply-nested plugin structure, tests its properties, and tests
        that it is copied accurately when the placeholder containing them is
        copied.

        The structure below isn't arbitrary, but has been designed to test
        various conditions, including:

        * nodes four levels deep
        * multiple successive level increases
        * multiple successive level decreases
        * successive nodes on the same level followed by level changes
        * multiple level decreases between successive nodes
        * siblings with and without children
        * nodes and branches added to the tree out of sequence

        First we create the structure:

             11
             1
                 2
                     12
                     4
                          10
                     8
                 3
                     9
             5
                 6
                 7
                 13
             14

        and then we move it all around.
        	some_slotr#   
TextPluginen01r+   02)r+   targetr&   0304050607080910
   11left)r+   r<   r   1213right14T)parent__isnullNr   )r   target_position)r   rM   target_plugin   )r   saver   assertSequenceEqualr   r'   r*   r   get_childrenget_descendantsreloadr   r   r)   filterr4   r    move_pluginr   r   )r   r   plugin_1plugin_2plugin_3plugin_4plugin_5plugin_6plugin_7plugin_8plugin_9	plugin_10r/   	plugin_11	plugin_12	plugin_13	plugin_14r   s                     r   $test_plugin_deep_nesting_and_copyingz:NestedPluginsTestCase.test_plugin_deep_nesting_and_copyingC   s   H "{3 t
 t
 	  !!X[[!1>>@""hkk"23	
 t
 	  !!X[[!1>>@!!%%%5!!%%%5	 t
 	  !!X[[!1>>@""hkk"23	5
 	  !!X[[!1AAC !!%%%5!!%%%5!!%%%5		
 k<DI t
 	  !!X[[!1>>@""hkk"23	5
 t
 	  !!X[[!1>>@!!%%%5!!%%%5	 	  !!X[[!1AAC!!%%%5!!%%%5	 ;;x(t
 	  !!X[[!1>>@!!%%%5!!%%%5	 t;;x(
 	  !!X[[!1>>@""hkk"23	5
 t;;x(
	 	  !!X[[!1>>@""ill"34	6 '224)//126 t	
	 	  !!X[[!1>>@!!%%%5!!%%%5	 t;;x(	
	 	  !!X[[!1>>@!!%%%6!!%%%5!!%%%5	 t;;x(	
	 	  !!X[[!1>>@!!%%%5!!%%%5!!%%%6	 t$
	 	  $$D$9!!%%%6!!%%%5!!%%%5!!%%%6		 \\4 [[$[[(++&\\8;;'[[(++&\\8;;'[[(++&[[(++&[[(++&[[$[[(++&[[(++&\\8;;'\\4 
  	00+?  {3 [[$\\8;;'[[(++&\\8;;'[[(++&\\4 [[$[[(++&[[(++&[[$[[(++&[[(++&\\8;;'\\4 
  	t{{8'<aP  {300+? [[$\\8;;'[[(++&\\8;;'[[(++&\\4 [[$[[(++&[[(++&[[$[[(++&[[(++&\\8;;'\\4 
  ;;x(;;x($--"// 	  	

 	  {300+? [[$[[(++&[[$\\8;;'[[(++&\\8;;'[[(++&\\4 [[$[[$[[(++&[[(++&\\8;;'\\4 
  	;;x( 	  	

 	  {300+? [[$[[(++&[[(++&\\8;;'[[(++&\\8;;'[[(++&\\4 [[$[[$[[(++&[[(++&\\8;;'\\4 
  	;;x(++h/ 	  	

 	  {300+? [[$[[(++&[[(++&[[(++&\\8;;'[[(++&\\8;;'[[(++&\\4 [[$[[$[[(++&\\8;;'\\4 
  ;;x(;;x($--1" 	  	

 	  {300+?r!   c                    | j                  d      5  t        ddddd      }|j                  d      j                  d	
      }d}t	        |dd|      }| j                  |      }| j                  |      }t	        |dd|      }d|_        d|_        | j                  |      }| j                  |      }d}| j                  |j                  |j                  dz   k(  |       d}| j                  |j                  du |       d}|j                   d||j                  z   d}||_        |j                          | j                  |      }| j                  |j!                         j#                  |j$                        j'                         d       t(        j*                  j'                         }	| j                  |	d       ddd       y# 1 sw Y   yxY w)z
        Validate a textplugin with a nested link plugin
        mptt values are correctly showing a parent child relationship
        of a nested plugin
        FCMS_PERMISSIONThree Placeholdercol_three.htmlr8   
last-childTr   in_navigationcol_leftr#   0<p>the nested text plugin with a link inside</p>r7   r:   
LinkPluginr<   django-cms Linkhttps://www.django-cms.orgz@parent plugin right is not updated, child not inserted correctlyr   r   zlink has no parentNz]<img id="plugin_obj_%s" title="Link" alt="Link" src="/static/cms/img/icons/plugins/link.png"><p></p>r%   r   rO   )settingsr   get_placeholdersr*   r   rT   nameexternal_link
assertTruer   assertFalser   r+   r   rP   r   rS   excluder   r)   r   r'   )
r   page_onepage_one_ph_twopre_nesting_bodytext_pluginlink_pluginr   in_txtnesting_bodypost_add_plugin_counts
             r   test_nested_plugin_on_pagez0NestedPluginsTestCase.test_nested_plugin_on_page  s    ]]%]0 %	7"#68H$,8NH&77=AAzARO  R$_lDO_`K"kk/:O++k2K$_lDQ\]K0K(DK% ++k2K++k2K UCOOK00K4H4H14LLRUOV&C[//47SA uF)../s6[^^3L2MTRL+K++k2K[88:BB{OfOfBgmmoqrs$-$5$5$;$;$=!2A6K%	7 %	7 %	7s   F5GGc                    | j                  d      5  t        ddddd      }|j                  d      j                  d	
      }|j                  d      j                  d
      }|j                  d      j                  d
       t	        |ddd      }| j                  |j                  t        j                  j                         d   j                         | j                  |j                         j                         d       t        j                  j                         }| j                  |d       d}t	        |dd|      }| j                  |      }| j                  |      }| j                  |      }t	        |dd|      }d|_        d|_        ||_        |j!                          | j                  |      }| j                  |      }d}	|j"                   d|	|j                  z   d}
|
|_        |j!                          | j                  |      }| j                  |j                         j                         d       t        j                  j                         }| j                  |d       |j!                          | j                  |      }|j                  d      j                  d	
      }|j                  d      j                  d
      }|j                  d      j                  d
      }|j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       | j                  |j                  d      j                         d       t(        j                  j                         }| j                  |d       | j                  t        j                  j                         d       t        ddddd      }t*        j                  j                         }t(        j                  j                         }| j                  |d       | j-                         }| j/                  |      5  | j1                  ||      }ddd       t        j                  j                         }| j                  |d       t*        j                  j                         }t(        j                  j                         }| j3                  ||d       | j3                  ||d        | j3                  ||d!       | j                  |dd       | j                  |      }|j                  d      j                  d	
      }|j                  d      j                  d
      }|j                  d      j                  d
      }|r|j4                  nd}| j                  ||       |r|j4                  nd}| j                  ||       |r|j4                  nd}| j                  ||       | j                        }|j                  d      j                  d	
      }|j                  d      j                  d
      }|j                  d      j                  d
      }|r|j4                  nd}| j                  ||       |r|j4                  nd}| j                  ||       |r|j4                  nd}| j                  ||       d"|j6                   d#|j6                   d$|j6                   d%}| j9                  |j6                  |j6                  |       d"|j6                   d#|j6                   d$|j6                   d%}| j9                  |j6                  |j6                  |       d"|j6                   d#|j6                   d$|j6                   d%}| j9                  |j6                  |j6                  |       |j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       |j%                         } | j                  t'        |       d       t'        |      }!t'        |      }"d&|! d'|" d(}| j                  |!|"|       t'        |      }!t'        |      }"d&|! d'|" d)}| j                  |!|"|       t'        |       }!t'        |      }"d&|! d'|" d*}| j                  |!|"|       d}#|D ]D  }$|$j:                  dk(  s|$j=                         d   }%|%j"                  j?                  |      sB|%}# n d}&|D ]D  }$|$j:                  dk(  s|$j=                         d   }%|%j"                  j?                  |      sB|%}& n d+}| j9                  |#d|,       d-}| j9                  |&d|,       |#j                         d   }'|&j                         d   }(d.}| jA                  |'j                  |(j                  k7  |       d/})d0}| jA                  |#j"                  jC                  |)|'j                  z        d1k7  |       d2}| jA                  |&j"                  jC                  |)|(j                  z        d1k7  |       d3}| jA                  |#j"                  jC                  |)|(j                  z        d1k(  |       d4}| jA                  |&j"                  jC                  |)|'j                  z        d1k(  |       |'jD                  }*|(jD                  }+d5}|*j                  |+j                  k7  },| jA                  |,|       ddd       y# 1 sw Y   XxY w# 1 sw Y   yxY w)6af  
        Test to verify that page copy with a nested plugin works
        page one - 3 placeholder
                    col_sidebar: 1 text plugin
                    col_left: 1 text plugin with nested link plugin
                    col_right: no plugin
        page two (copy target)
        Verify copied page, placeholders, plugins and body text
        Frg   ri   rj   r8   rk   Trl   col_sidebarr#   rn   	col_rightr7   Hello Worldr:   r   r   ro   rp   rq   rr   rs   9<cms-plugin id="%s" title="Link" alt="Link"></cms-plugin>ru   rv      rO   $Three Placeholder - page copy target   Nno new page after copyplugin count is not grownplaceholder count is not grownplacehoder ids copy: org: copied page  are identical - tree brokenplugin count   for placeholder one not equal for placeholder two not equal  for placeholder three not equal%original nested text plugin not foundrt   #copied nested text plugin not found)org plugin and copied plugin are the same%s)child plugin id differs to parent in bodyz/copy: child plugin id differs to parent in body+child link plugin id differs to parent body1copy: child link plugin id differs to parent bodyAplaceholder of the original plugin and copied plugin are the same)#rw   r   rx   r*   r   r   r   r   r'   allrR   r)   rT   ry   rz   r   rP   r+   r   lenr   r   get_superuserlogin_user_context	copy_pageassertGreaterpager   assertNotEqualplugin_typeget_plugin_instance
startswithr{   findr   )-r   r~   page_one_ph_oner   text_plugin_enpre_add_plugin_countr   text_plugin_twor   r   r   r   page_one_ph_threeorg_placeholder_one_pluginsorg_placeholder_two_pluginsorg_placeholder_three_pluginsplaceholder_countpage_copy_targetall_page_countpre_copy_placeholder_count	superuserpage_twoafter_copy_page_plugin_countafter_copy_page_countafter_copy_placeholder_count
found_pagepage_two_ph_onepage_two_ph_twopage_two_ph_threer   copied_placeholder_one_pluginscopied_placeholder_two_plugins copied_placeholder_three_pluginscount_plugins_copiedcount_plugins_orgorg_nested_text_pluginxinstancecopied_nested_text_pluginorg_link_child_plugincopied_link_child_pluginneedleorg_placeholderr0   oks-                                                r   test_copy_page_nested_pluginz2NestedPluginsTestCase.test_copy_page_nested_plugin  s{    ]]%]0 {	%"#68H$,8NH&77=AA}AUO&77=AAzARO%%d+//[/A'tR_`N^..	0A0A0E0E0G0J0M0MN^88:@@BAF#,#4#4#:#:#< 115  R(,ScdO"kk/:O"kk/:O"kk/:O$_lDQ`aK0K(DK%!0K++k2K"kk/:OTF-2233v7P6QQUVL#/O   ""kk/:O_99;AACQG$-$5$5$;$;$=!2A6MMO{{8,H&77=AA}AUO&77=AAzARO ( 9 9$ ? C C C U*9*E*E*G'S!<=qA*9*E*E*G'S!<=qA,=,I,I,K)S!>?CX66t<BBDaH + 3 3 9 9 ;.2Y..446:  ++QScei4@PT V!\\//1N)4)<)<)B)B)D&7;**,I((3 F>>(4DEF ,5+<+<+B+B+D(91=$(LL$6$6$8!+6+>+>+D+D+F(4nF^_;=RTop;=W?A2A7OP{{8,H&77=AA}AUO&77=AAzARO ( 9 9$ ? C C C U1@--dJZ21@--dJZ23D*//$JZ2{{8,H&77=AA}AUO&77=AAzARO ( 9 9$ ? C C C U1@--dJZ21@--dJZ23D*//$JZ2(););(<E/BTBTAUUbckcncnbo  pL  MC 2 2O4F4FL(););(<E/BTBTAUUbckcncnbo  pL  MC 2 2O4F4FL():)=)=(>eDUDXDXCYYfgogrgrfs  tP  QC 1 4 46G6J6JCP*9*E*E*G'S!<=qA*9*E*E*G'S!<=qA,=,I,I,K)S!>?C-<-H-H-J*S!?@!D-<-H-H-J*S!?@!D/@/L/L/N,S!ABAF $''E#F  #$? @!"6!7q9J8KKijC13DcJ#&'E#F  #$? @!"6!7q9J8KKijC13DcJ#&'G#H  #$A B!"6!7q9J8KKklC13DcJ &*" 1 ==L0 446q9H}}//0@A19. )-%3 ==L0 446q9H}}//0@A4<1 :C 6#F7C 94SI %;$G$G$I!$L!'@'M'M'OPQ'R$=COO1448P8S8SSUXYF=COO277<<VG\G_G_=`aeggilmCCOO5::??JbJeJe@fgkmmors?COO277<<VG_GbGb=cdhjjlopECOO5::??J_JbJb@cdhjjlop3??O!9!E!EUC!$$(:(=(==BOOB$w{	% {	%FF FG{	% {	%s>   Q8po4Tp4.p#p?.p.F=p4o>	9pp
c           	         | j                  d      5  t        ddddd      }|j                  d      j                  d	
      }|j                  d      j                  d
      }|j                  d      j                  d
       t	        |ddd      }| j                  |j                  t        j                  j                         d   j                         | j                  |j                         j                         d       t        j                  j                         }| j                  |d       d}t	        |dd|      }| j                  |      }| j                  |      }| j                  |      }t	        |dd|      }d|_        d|_        ||_        |j!                          | j                  |      }| j                  |      }d}	|j"                   d|	|j                  z   d}
|
|_        |j!                          | j                  |      }| j                  |j                         j                         d       t        j                  j                         }| j                  |d       |j!                          | j                  |      }|j                  d      j                  d	
      }|j                  d      j                  d
      }|j                  d      j                  d
      }|j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       | j                  |j                  d      j                         d       t(        j                  j                         }| j                  |d       | j                  t        j                  j                         d       t        ddddd      }t*        j                  j                         }t(        j                  j                         }| j                  |d       | j-                         }| j/                  |      5  |j                  |j                  d|j1                  dd      d d!}| j3                  |      }| j4                  j7                  ||      }| j                  |j8                  d"       | j                  |      }| j                  |       |j                  d      j                  d	
      }|j                  d      j                  d
      }|j                  d      j                  d
      }|j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       | j;                  ||      }d#d#d#       t        j                  j                         }| j                  |d       t*        j                  j                         }t(        j                  j                         }| j=                  ||d$       | j=                  ||d%       | j=                  ||d&       | j                  |dd$       | j                  |      }|j                  d      j                  d	
      }|j                  d      j                  d
      }|j                  d      j                  d
      }|r|j>                  nd#}| j                  ||       |r|j>                  nd#}| j                  ||       |r|j>                  nd#}| j                  ||       | j                        }|j                  d      j                  d	
      }|j                  d      j                  d
      }|j                  d      j                  d
      }|r|j>                  nd#}| j                  ||       |r|j>                  nd#}| j                  ||       |r|j>                  nd#}| j                  ||       d'|j@                   d(|j@                   d)|j@                   d*} | jC                  |j@                  |j@                  |        d'|j@                   d(|j@                   d)|j@                   d*} | jC                  |j@                  |j@                  |        d'|j@                   d(|j@                   d)|j@                   d*} | jC                  |j@                  |j@                  |        |j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       |j%                         }| j                  t'        |      d       |j%                         }!| j                  t'        |!      d       |j%                         }"| j                  t'        |"      d       |j%                         }#| j                  t'        |#      d       t'        |!      }$t'        |      }%d+|$ d,|% d-} | j                  |$|%|        t'        |"      }$t'        |      }%d+|$ d,|% d.} | j                  |$|%|        t'        |#      }$t'        |      }%d+|$ d,|% d/} | j                  |$|%|        d#}&|D ]D  }'|'jD                  dk(  s|'jG                         d   }(|(j"                  jI                  |      sB|(}& n d#})|#D ]D  }'|'jD                  dk(  s|'jG                         d   }(|(j"                  jI                  |      sB|(}) n d0} | jC                  |&d#| 1       d2} | jC                  |)d#| 1       |&j                         d   }*|)j                         d   }+d3} | jC                  |*j                  |+j                  |        d4},d5} | jK                  |&j"                  jM                  |,|*j                  z        d6k7  |        d7} | jK                  |)j"                  jM                  |,|+j                  z        d6k7  |        d8} | jK                  |&j"                  jM                  |,|+j                  z        d6k(  |        d9} | jK                  |)j"                  jM                  |,|*j                  z        d6k(  |        |*jN                  }-|+jN                  }.d:} | jC                  |-j                  |.j                  |        d#d#d#       y## 1 sw Y   RxY w# 1 sw Y   y#xY w);a  
        Test to verify that page copy with a nested plugin works
        when a plugin with child got moved to another placeholder
        page one - 3 placeholder
                    col_sidebar:
                        1 text plugin
                    col_left: 1 text plugin with nested link plugin
                    col_right: no plugin
        page two (copy target)
        step2: move the col_left text plugin to col_right
                    col_sidebar:
                        1 text plugin
                    col_left: no plugin
                    col_right: 1 text plugin with nested link plugin
        verify the copied page structure
        Frg   ri   rj   r8   rk   Trl   r   r#   rn   r   r7   r   r:   r   r   ro   rp   rq   rr   rs   r   ru   rv   r   rO   r   r   last)insert_order )placeholder_id	plugin_idtarget_languagerM   plugin_parent   Nr   r   r   r   r   r   r   r   r   r   r   r   r   rt   r   r   r   r   r   z=copy: child plugin id differs to parent in body plugin_obj_idr   r   r   )(rw   r   rx   r*   r   r   r   r   r'   r   rR   r)   rT   ry   rz   r   rP   r+   r   r   r   r   r   r   get_next_plugin_positionget_move_plugin_uriclientpoststatus_coder   r   r   r   r   r   r   r   r{   r   r   )/r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	post_dataedit_urlresponser   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r0   s/                                                  r   0test_copy_page_nested_plugin_moved_parent_pluginzFNestedPluginsTestCase.test_copy_page_nested_plugin_moved_parent_plugin  s   " ]]%]0 Q	P"#68H$,8NH&77=AA}AUO&77=AAzARO%%d+//[/A'tR_`N^..	0A0A0E0E0G0J0M0MN^88:@@BAF#,#4#4#:#:#< 115Q(,ScdO"kk/:O"kk/:O"kk/:O$_lDQ`aK0K(DK%!0K++k2K"kk/:OTF-2233v7P6QQUVL#/O   ""kk/:O_99;AACQG$-$5$5$;$;$=!2A6MMO{{8,H&77=AA}AUO&77=AAzARO ( 9 9$ ? C C C U*9*E*E*G'S!<=qA*9*E*E*G'S!<=qA,=,I,I,K)S!>?CX66t<BBDaH + 3 3 9 9 ;.2Y..446:*+QScei4@PT V!\\//1N)4)<)<)B)B)D&7;**,I((3 F '8&:&:!0!3!3'+'8'Q'QRVek'Q'l%'	  33OD;;++Hi@  !5!5s;;;x0O,"*";";D"A"E"E="E"Y"*";";D"A"E"E:"E"V$,$=$=d$C$G$G[$G$Y!.=.I.I.K+  %@!A1E.=.I.I.K+  %@!A1E0A0M0M0O-  %B!CQG>>(4DE9F< ,5+<+<+B+B+D(91=$(LL$6$6$8!+6+>+>+D+D+F(4nF^_;=RTop;=W?A2A7OP {{8,H&77=AA}AUO&77=AAzARO ( 9 9$ ? C C C U1@--dJZ21@--dJZ23D*//$JZ2{{8,H&77=AA}AUO&77=AAzARO ( 9 9$ ? C C C U1@--dJZ21@--dJZ23D*//$JZ2(););(<E/BTBTAUUbckcncnbo  pL  MC 2 2O4F4FL(););(<E/BTBTAUUbckcncnbo  pL  MC 2 2O4F4FL():)=)=(>eDUDXDXCYYfgogrgrfs  tP  QC 1 4 46G6J6JCP*9*E*E*G'S!<=qA*9*E*E*G'S!<=qA,=,I,I,K)S!>?C-<-H-H-J*S!?@!D-<-H-H-J*S!?@!D/@/L/L/N,S!ABAF $''E#F  #$? @!"6!7q9J8KKijC13DcJ#&'E#F  #$? @!"6!7q9J8KKijC13DcJ#&'G#H  #$A B!"6!7q9J8KKklC13DcJ &*" 3 ==L0 446q9H}}//0@A19. )-%5 ==L0 446q9H}}//0@A4<1 :C 6#F7C 94SI %;$G$G$I!$L!'@'M'M'OPQ'R$=C 5 8 8:R:U:UWZ[F=COO277<<VG\G_G_=`aeggilmQCOO5::??JbJeJe@fgkmmors?COO277<<VG_GbGb=cdhjjlopECOO5::??J_JbJb@cdhjjlop3??O!9!E!EUC 2 24F4I4I3OcQ	P Q	P@F FAQ	P Q	Ps?   Q8u7Fu*Tu70.u7u7;.u7*F7u7*u4	/u77v c                    t        ddddd      }|j                  d      j                  d      }t        |d	dd
      }| j	                         }| j                  |      5  ddd}| j                  |d|      }| j                  j                  ||      }| j                  |j                  d       | j                  |d       d d d        t        j                  j                  |j                        }| j                  |j                  |j                         | j                  |j                   |j                   dz          y # 1 sw Y   xY w)Nri   rj   r8   rk   Trl   r   r#   r7   r   r:   testzhttp://www.example.org/)ry   rz   rp   )r   r   z'admin/cms/page/plugin/confirm_form.html)r   r   )r   rx   r*   r   r   r   get_add_plugin_urir   r   r   r   assertTemplateUsedr   r'   r   r   r   )	r   r~   r   r   r   r   add_urlr   r   s	            r   test_add_child_pluginz+NestedPluginsTestCase.test_add_child_plugin  s>   24Dd(4DJ"33D9====Q#O\4m\&&(	$$Y/ 	!:I --o|Tb-cG{{'';HX1137##9	  ''++n6G6G+H..0A0AB--~/F/F/JK	 	s   "A$EEc                 r   t        d      }|j                          t        |ddd      }t        |ddd      }t        |ddd      }|j                  d	f|j                  d	f|j                  d	fg}| j	                  |g       | j                  ||       ||_        |j                          | j                  |       | j                  |       |j                  d	f|j                  |j                  f|j                  d	fg}|j                  d       | j	                  |g       | j                  ||       y	)
a  
        Captures an edge case issue where plugins have been seen to have a higher
        position than their parent. When the placeholder is
        copied the parent defaults to None because the plugin is not yet created / remapped.

        Plugins first created in this order:

            Plugin 1 (pk1, position 1)
            Plugin 2 (pk2, position 2)
            Plugin 3 (pk3, position 3)

        Then a top level plugin is made a child of another.
        The result is a child with a lower id and higher position that it's parent.

            Plugin 1 (pk1, position 1)
            Plugin 3 has children (pk3, position 3)
                Plugin 2 (pk2, position 2)
        r6   r#   r7   r8   r9   r:   r;   r=   N)	r   rP   r   r   r4   r    r   rT   _recalculate_plugin_positions)r   r   rW   rX   rY   expected_trees         r   Ltest_plugin_deep_nesting_and_copying_issue_position_parent_child_discrepencyzbNestedPluginsTestCase.test_plugin_deep_nesting_and_copying_issue_position_parent_child_discrepency  s"   & "{3k<DIk<DIk<DI [[$[[$[[$
 	00+?  <"HH [[$[[(++&[[$
 	11$700+?  <r!   c                 \   ddl }t        d      }|j                          d}d}t        |j	                  t        d|dz         |            }|t        |j	                  t        ||z   dz   |d|z  z   d	z         |            z  }d
D ]B  }t        |      D ]2  \  }}t        j                  j                  t        |      |||d       4 D |j                  d       |j                  d      j                  d      }	t        |	d      D ]!  \  }}
| j                  |
j                  |       # y)z
        Test to verify that the plugin positions are recalculated correctly
        when a plugin is moved to another placeholder.
        r   Nr6   r#   rE   2   r   r   rO   )r8   it)r   r   languager   r   r8   r   )start)randomr   rP   listsamplerange	enumerater   r'   r(   strr   r   order_byr   r   )r   r   r   n0norderlangiposr   r   s              r   !test_recalculate_plugin_positionsz7NestedPluginsTestCase.test_recalculate_plugin_positions  s(   
 	!{3V]]5BF#3R89fmmE"q&1*b1q5j1n$EqIJJ  	D#E* 3!!(( #A +!  ) 	 	11$7))$/88D"7!4 	1IAvV__a0	1r!   c                     t        d      }|j                          |j                  d       t        |j	                  d            }| j                  |g        y)z
        Test to verify that recalculating plugin positions on an empty placeholder
        doesn't error and leaves the plugin list empty for a given language.
        
empty_slotr#   r8   )r   N)r   rP   r   r   r   r   )r   r   r   s      r   3test_recalculate_plugin_positions_empty_placeholderzINestedPluginsTestCase.test_recalculate_plugin_positions_empty_placeholder  sT     "|4 	11$7 {...=>"%r!   N)__name__
__module____qualname__r    r4   re   r   r   r   r   r   r  r   r!   r   r   r      s@    	)"V{@z+7ZE%NbPHL.2=h1<&r!   r   N)djangocms_text_ckeditor.modelsr   cms.apir   r   
cms.modelsr   cms.models.placeholdermodelr   cms.models.pluginmodelr   cms.tests.test_pluginsr	   cms.utils.pluginsr
   r   r	  r!   r   <module>r     s)    / +  3 , 6 9E&/ E&r!   