
    Bhh                         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
mZ d dlmZmZmZ d dlmZ d dlmZ  G d	 d
e      Zy)    )ContentType)
connection)model_to_dict)CaptureQueriesContextoverride_settings)
add_plugincreate_page)	CMSPluginPlaceholderUserSettings)CMSTestCase)admin_reversec                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Z ed
ddgii      d        Z ed
ddgii      d        Zd Zy)PlaceholderAdminTestCasec                    | j                         }t        j                  j                  d      }|j	                  d      j                  d      }| j                  |dd      }| j                  |      5  ddd	}| j                  j                  ||      }d
d
d
       | j                  j                  d       | j                  |j                         d       y
# 1 sw Y   FxY w)zA
        The Placeholder admin add_plugin endpoint works
        testsloten
LinkPluginplugin_typeplaceholderr   languageA Linkhttps://www.django-cms.org)nameexternal_linkN      get_superuserr   objectscreateget_pluginsfilterget_add_plugin_urilogin_user_contextclientpostassertEqualstatus_codecountself	superuserr   pluginsuridataresponses          P/home/dcms/DCMS/lib/python3.12/site-packages/cms/tests/test_placeholder_admin.pytest_add_plugin_endpointz1PlaceholderAdminTestCase.test_add_plugin_endpoint   s     &&(	!))00f0=))$/66<6P%%#$ & 

 $$Y/ 	3$7STD{{''T2H	3 	--s3!,	3 	3s   7"CC'c                    | j                         }t        j                  j                  d      }|j	                  d      j                  d      }| j                  |dd      }| j                  |      5  ddi}| j                  j                  ||d	
      }ddd       | j                  j                  d       | j                  |j                         d       y# 1 sw Y   FxY w)z?Adding a text plugin works. Text plugins create a ghost plugin.r   r   r   
TextPluginr   r   bodyz<p>Some markup</p>T)followNr    r!   r"   r/   s          r6   test_add_plugin_with_ghostz3PlaceholderAdminTestCase.test_add_plugin_with_ghost    s    &&(	!))00f0=))$/66<6P%%#$ & 

 $$Y/ 	@01D{{''T$'?H	@ 	--s3!,	@ 	@s   7#CC(c                    | j                         }t        j                  j                  d      }t        j                  j                  d      }| j	                  |      }| j                  |      }| j                  |      5  d|j                  d|j                  d}| j                  j                  ||      }ddd       | j                  j                  d       | j                  |j                  d      j                  |j                        j                                | j                  |j                  d      j                  |j                   	      j                                y# 1 sw Y   xY w)
zG
        User can copy plugins from one placeholder to another
        sourcer   targetr   source_languagesource_placeholder_idtarget_languagetarget_placeholder_idNr    pkr   )r#   r   r$   r%   _add_plugin_to_placeholderget_copy_plugin_urir)   rF   r*   r+   r,   r-   
assertTruer&   r'   existsr   )r0   r1   source_placeholdertarget_placeholdersource_pluginendpointr4   r5   s           r6   !test_add_plugins_from_placeholderz:PlaceholderAdminTestCase.test_add_plugins_from_placeholder1   sD    &&(	(0077X7F(0077X7F778JK++M:$$Y/ 	8#');)>)>#');)>)>	D {{''$7H	8 	--s3*66t<CC}GWGWCX__ab*66t<CCP]PiPiCjqqst	8 	8s   8E11E:c                 t   | j                         }t        j                  j                  d|t        j                  j                               }t        j                  j                  d      }| j                  |      }| j                  |      }| j                  |      5  d|j                  |j                  d|j                  j                  d}| j                  j                  ||      }ddd       | j                  j                  d       | j                  |j                  d      j!                  |j                        j#                                | j                  |j                  j                  d      j!                  |j$                  	      j#                                y# 1 sw Y   xY w)
zK
        User can copy plugins from a placeholder to the clipboard
        r   r   user	clipboardr>   r   )rA   rB   source_plugin_idrC   rD   Nr    rE   r   )r#   r   r$   r%   r   rG   rH   r)   rF   rS   r*   r+   r,   r-   rI   r&   r'   rJ   r   r0   r1   user_settingsrK   rM   rN   r4   r5   s           r6   test_copy_plugins_to_clipboardz7PlaceholderAdminTestCase.test_copy_plugins_to_clipboardH   su    &&(	$,,33!))002 4 

 )0077X7F778JK++M:$$Y/ 	8#');)>)>$1$4$4#')6)@)@)C)CD {{''$7H	8 	--s3*66t<CC}GWGWCX__ab##//5<<IbIb<cjjl	
	8 	8s   "AF..F7c                    | j                         }t        j                  j                  d|t        j                  j                               }||j
                  _        |j
                  j                          t        j                  j                  d      }| j                  |      }| j                  |      }| j                  |      5  d|j                  d|j
                  j                  d}| j                  j                  ||      }ddd       | j                  j                  d       | j!                  |j#                  d      j%                  |j                        j'                                | j!                  |j
                  j#                  d      j%                  d	
      j'                                y# 1 sw Y   xY w)z>
        User can copy a placeholder to the clipboard
        r   rQ   r>   r   r@   Nr    rE   PlaceholderPluginr   )r#   r   r$   r%   r   rS   r>   saverG   rH   r)   rF   r*   r+   r,   r-   rI   r&   r'   rJ   rU   s           r6   "test_copy_placeholder_to_clipboardz;PlaceholderAdminTestCase.test_copy_placeholder_to_clipboardf   s    &&(	$,,33!))002 4 

 *7&$$&(0077X7F778JK++M:$$Y/ 	8#');)>)>#')6)@)@)C)C	D {{''$7H	8 	--s3*66t<CC}GWGWCX__ab//;;DAHHUhHipprs	8 	8s   AGGc                    | j                         }t        j                  j                  d      }| j	                  |      }| j                  |      }| j                  |      5  t        |ddg      }d|d<   | j                  j                  ||      }|j                          ddd       | j                  j                  d       | j                  |j                  d          y# 1 sw Y   ExY w)	zC
        The Placeholder admin edit_plugins endpoint works
        edit_plugin_placeholderr   r   r   )fieldszContents modifiedNr    )r#   r   r$   r%   rG   get_change_plugin_urir)   r   r*   r+   refresh_from_dbr,   r-   r   r0   r1   r   pluginrN   r4   r5   s          r6   test_edit_plugin_endpointz2PlaceholderAdminTestCase.test_edit_plugin_endpoint   s     &&(	!))006O0P00=--f5$$Y/ 	% 0IJD.DL{{''$7H""$		% 	--s3d6l3	% 	%s   $AC))C2c                    | j                         }t        j                  j                  d      }| j	                  |      }| j                  |      }| j                  |      5  ddi}| j                  j                  ||      }ddd       | j                  d       | j                  t        j                  j                  |j                        j                                y# 1 sw Y   cxY w)D
        The Placeholder admin delete_plugin endpoint works
        r>   r   r+   TNz<div class="success"></div>rE   )r#   r   r$   r%   rG   get_delete_plugin_urir)   r*   r+   assertContainsassertFalser
   r'   rF   rJ   ra   s          r6   test_delete_plugin_endpointz4PlaceholderAdminTestCase.test_delete_plugin_endpoint   s     &&(	!))00h0?00=--f5$$Y/ 	8D>D{{''$7H	8 	H&CD**11VYY1?FFHI	8 	8s   $!C''C0c                    | j                         }t        j                  j                  d      }| j	                  |       | j                  |      }| j                  |      5  | j                  j                  |ddi      }ddd       | j                  j                  d       | j                  |j                  d      j                         d       y# 1 sw Y   UxY w)re   r>   r   r   r   Nr    r   )r#   r   r$   r%   rG   get_clear_placeholder_urlr)   r*   r+   r,   r-   r&   r.   )r0   r1   r   rN   r5   s        r6   test_clear_placeholder_endpointz8PlaceholderAdminTestCase.test_clear_placeholder_endpoint   s     &&(	!))00h0?''411+>$$Y/ 	?{{''61+>H	? 	--s3006<<>B		? 	?s   $CC c                 d   |j                  |      j                  d      }t        |d|d      }t        |d|d|       t        |d|d|      }t        |d|d|      }t        |d|d|       t        |d|d|      }t        |d||	       t        |d
||dd       t        |d||d       y )Nr   r   MultiColumnPluginzfirst-child)positionColumnPlugin)ro   r?   NoCustomModel)r?   r   r   r   )r?   r   r   StylePlugindiv)r?   tag_type)get_placeholdersgetr   )r0   pagelangph_enmcol1col2mcol2col4s           r6   _fill_page_bodyz(PlaceholderAdminTestCase._fill_page_body   s    %%d+//]/C5"5tmT5.$uU%V[\5"5tm\`a5.$uU%V[\5/4=5,TXtu5-dUK    simple.htmlexcluded_pluginsInheritPlugin)CMS_PLACEHOLDER_CONFc                    t        ddd      }| j                  |d       |j                         }t        j                  j                  dd      }| j                         }t        j                  j                  d|t        j                  j                  d      	      }||j                  _        |j                  j                          t        d
|j                  |j                  f      }| j                  |      5  t!        t"              5 }| j$                  j                  |      }d d d        d d d        | j'                  j(                  d       | j'                  t+              ddj-                  t/        |d      D 	
cg c]  \  }	}
|	 d|
d     c}
}	             y # 1 sw Y   xY w# 1 sw Y   xY wc c}
}	w )NPage 1r   r   cmspagecontent	app_labelmodelrS   r   rQ   "cms_placeholder_render_object_editargsr       
r!   start. sqlr	   r~   get_content_objr   r$   rv   r#   r   r%   r   rS   r>   rZ   r   rF   r)   r   r   r*   r,   r-   lenjoin	enumerater0   rw   contentcontent_typerR   settingsrN   queriesr5   iqs              r6   test_object_edit_endpointz2PlaceholderAdminTestCase.test_object_edit_endpoint   s    8]D9T4(&&("**..m.T!!#''..0C0C0J0JP[0J0\ / 
 %-!! 0


 $$T* 	5&z2 5g;;??845	5 	--s3Wr499U^_fnoUp5qTQPQ2ahZ6H5q+rs5 5	5 	5 6r*    F6F*,F6	G*F3	/F66F?c                    t        ddd      }| j                  |d       |j                         }t        j                  j                  dd      }| j                         }t        j                  j                  d|t        j                  j                  d      	      }||j                  _        |j                  j                          t        d
|j                  |j                  f      }| j                  |      5  t!        t"              5 }| j$                  j                  |      }d d d        d d d        | j'                  j(                  d       | j'                  t+              ddj-                  t/        |d      D 	
cg c]  \  }	}
|	 d|
d     c}
}	             y # 1 sw Y   xY w# 1 sw Y   xY wc c}
}	w )Nr   r   r   r   r   r   rS   r   rQ   'cms_placeholder_render_object_structurer   r       r   r!   r   r   r   r   r   s              r6   test_object_structure_endpointz7PlaceholderAdminTestCase.test_object_structure_endpoint   s    8]D9T4(&&("**..m.T!!#''..0C0C0J0JP[0J0\ / 
 %-!! 5


 $$T* 	5&z2 5g;;??845	5 	--s3Wr499U^_fnoUp5qTQPQ2ahZ6H5q+rs5 5	5 	5 6rr   c                    t        ddd      }| j                  |d       |j                         }t        j                  j                  dd      }| j                         }t        d      }t        d|j                  |j                  f	      }| j                  |      5  | j                  j                  | d
|j                   d|       }ddd       | j                  d       y# 1 sw Y   xY w)z_Toolbar endpoint returns the toolbar including the page menu when called from the edit endpointr   r   r   r   r   r   cms_usersettings_get_toolbarr   r   z?obj_id=z#&obj_type=cms.pagecontent&cms_path=Nz><span>Page<span class="cms-icon cms-icon-arrow"></span></span>)r	   r~   r   r   r$   rv   r#   r   rF   r)   r*   idrg   )r0   rw   r   r   rR   toolbar_endpointedit_endpointr5   s           r6   test_get_toolbar_endpointz2PlaceholderAdminTestCase.test_get_toolbar_endpoint  s    8]D9T4(&&("**..m.T!!#()GH%0


 $$T* 	D{{*:);8GJJ<Or  tA  sB  (C  DH	D 	H&fg	D 	Ds    .C))C2N)__name__
__module____qualname__r7   r<   rO   rW   r[   rc   ri   rl   r~   r   r   r   r    r   r6   r   r      s    -&-"u.
<t:4"JCL .0AB

t
tP .0AB

t
tVhr   r   N)"django.contrib.contenttypes.modelsr   	django.dbr   django.forms.modelsr   django.test.utilsr   r   cms.apir   r	   
cms.modelsr
   r   r   cms.test_utils.testcasesr   cms.utils.urlutilsr   r   r   r   r6   <module>r      s0    :   - F + ; ; 0 ,dh{ dhr   