
    Bht*                         d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ  G d de      Z G d	 d
e      Z G d de      Zy)    )Mockcallpatch)model_to_dict)create_page)PlaceholderUserSettingsfields)PlaceholderRelationField)CMSTestCasec                       e Zd Zd Zd Zd Zy)ChecksTestCasec                 `   | j                         }t               }t        ddd      }|j                  d      j	                  d      }t        g       }t        j                  t        dt        |            5  | j                  |j                  ||             d d d        y # 1 sw Y   y xY w)Ntestnav_playground.htmlenbodyslotreturn_valuechecks)get_superuserr   r   get_placeholdersgetr   r   objectproperty
assertTrue
run_checks)self	superuserfieldpageplaceholdermocks         Q/home/dcms/DCMS/lib/python3.12/site-packages/cms/tests/test_placeholder_checks.pytest_no_check_means_passedz)ChecksTestCase.test_no_check_means_passed   s    &&(	(*6#8$?++D15565B$\\2HhtnM 	FOOE,,[)DE	F 	F 	Fs   9"B$$B-c                    t        d      }t        d      }t        d      }t        ||g      }t        j                  |d|g      5  | j	                  t        |j                        |||g       ddd       y# 1 sw Y   yxY w)zkTest that PlaceholderRelationField.checks combines
        default_checks with field-level checks.
        Tr   r   default_checksN)r   r   r   r   assertEquallistr   )r    check1check2check3r"   s        r&   test_checkszChecksTestCase.test_checks   s}     4(4(4((0@A\\%!1F8< 	U\\"(	 	 	s   )A==Bc                 R   | j                         }t        ddd      }|j                  d      j                  d      }t	        d      }t	        d      }t        ||g	      }| j                  |j                  ||             |j                  ||       |j                          y
)z2Test that one False value short-circuits.
        r   r   r   r   r   Fr   Tr)   N)
r   r   r   r   r   r   assertFalser   assert_called_once_withassert_not_called)r    r!   r#   r$   r-   r.   r"   s          r&   test_checks_one_falsez$ChecksTestCase.test_checks_one_false$   s     &&(	6#8$?++D15565B5)4((0@A))+yAB&&{I>  "    N)__name__
__module____qualname__r'   r0   r5    r6   r&   r   r      s    F#r6   r   c                       e Zd Zd Zd Zy)"ChecksPlaceholderInterfaceTestCasec                    | j                         }t        ddd      }|j                  d      j                  d      }t	        d      }t	        |g      }t        j                  t        dt        |            5  | j                  |j                  |             d d d        |j                  ||       y # 1 sw Y   xY w)	Nr   r   r   r   r   Tr   r   )r   r   r   r   r   r   r   r   r   r   check_sourcer3   )r    r!   r#   r$   checkr%   s         r&   test_check_sourcez4ChecksPlaceholderInterfaceTestCase.test_check_source6   s    &&(	6#8$?++D15565B$'%)\\2HhtnM 	AOOK44Y?@	A%%k9=	A 	As   <!B88Cc                 h   | j                         }t        j                  j                  d      }t	        d      }t	        |g      }t        j                  t        dt        |            5  | j                  |j                  |             d d d        |j                          y # 1 sw Y   xY w)Nr   r   Tr   r   )r   r   objectscreater   r   r   r   r   r   r>   r4   )r    r!   r$   r?   r%   s        r&   &test_check_source_when_source_is_emptyzIChecksPlaceholderInterfaceTestCase.test_check_source_when_source_is_empty@   s    &&(	!))00f0=$'%)\\2HhtnM 	AOOK44Y?@	A!	A 	As   .!B((B1N)r7   r8   r9   r@   rD   r:   r6   r&   r<   r<   4   s    >"r6   r<   c                   \    e Zd 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d Zy)"ChecksUsedInAdminEndpointsTestCasec                     t        d      | _        t        j                  j                  | _        | j
                  | j                  gz   t        j                  _        y )NTr   )r   r?   r
   r   r*   original_checksr    s    r&   setUpz(ChecksUsedInAdminEndpointsTestCase.setUpL   sE    t,
%>>MM9=9M9MQUQ[Q[P\9\''6r6   c                 B    | j                   t        j                  _        y )N)rH   r
   r   r*   rI   s    r&   tearDownz+ChecksUsedInAdminEndpointsTestCase.tearDownQ   s    9=9M9M''6r6   Nc                     	 |j                   }	 |j                   }|d||j                   |d}|S # t        $ r d}Y .w xY w# t        $ r d}Y 2w xY w)N r   )placeholder_idtarget_languagetarget_position	plugin_idplugin_parent)pkAttributeError)r    pluginpositionr$   parentrO   	parent_iddatas           r&   _get_move_dataz1ChecksUsedInAdminEndpointsTestCase._get_move_dataT   sl    	 (^^N			I
 -#'&
   	 N	 
  	I	s   / A  == AAc                 N   | j                         }t        j                  j                  d      }| j	                  |dd      }| j                  |      5  ddd}| j                  j                  ||       d d d        | j                  j                          y # 1 sw Y   $xY w)	Nr   r   
LinkPluginr   r$   plugin_typelanguageA Linkhttps://www.django-cms.orgnameexternal_link)
r   r   rB   rC   get_add_plugin_urilogin_user_contextclientpostr?   r4   )r    r!   r$   urirZ   s        r&   -test_add_plugin_to_placeholder_without_sourcezPChecksUsedInAdminEndpointsTestCase.test_add_plugin_to_placeholder_without_sourceh   s    &&(	!))00f0=%%#$ & 
 $$Y/ 	($7STDKKS$'	( 	

$$&	( 	(s   "BB$c                 n   | j                         }t        ddd      }|j                  d      j                  d      }| j	                  |dd      }| j                  |      5  dd	d
}| j                  j                  ||       d d d        | j                  j                  ||       y # 1 sw Y   &xY w)Nr   r   r   r   r   r]   r^   ra   rb   rc   )
r   r   r   r   rf   rg   rh   ri   r?   r3   r    r!   r#   r$   rj   rZ   s         r&   test_add_pluginz2ChecksUsedInAdminEndpointsTestCase.test_add_pluginv   s    &&(	6#8$?++D15565B%%#$ & 
 $$Y/ 	($7STDKKS$'	( 	

**;	B	( 	(s   $"B++B4c                 <   | j                         }t        j                  j                  d      }| j	                  |      }| j                  |      }t        j                  j                  d|t        j                  j                               }| j                  |      5  d|j                  |j                  d|j                  j                  d}| j                  j                  ||       d d d        | j                  j                          y # 1 sw Y   $xY w)Nr   r   r   r`   user	clipboardsource_languagesource_placeholder_idsource_plugin_idrP   target_placeholder_idr   r   rB   rC   _add_plugin_to_placeholderget_copy_plugin_urir	   rg   rT   rr   rh   ri   r?   r4   r    r!   source_placeholdersource_pluginrj   user_settingsrZ   s          r&   test_copy_plugins_to_clipboardzAChecksUsedInAdminEndpointsTestCase.test_copy_plugins_to_clipboard   s    &&(	(0077V7D778JK&&}5$,,33!))002 4 
 $$Y/ 	(#');)>)>$1$4$4#')6)@)@)C)CD KKS$'	( 	

$$&	( 	(s   "ADDc                 &   | j                         }t        j                  j                  d      }| j	                  |      }| j                  |      }t        j                  j                  d|t        j                  j                               }| j                  |      5  d|j                  d|j                  j                  d}| j                  j                  ||       d d d        | j                  j                          y # 1 sw Y   $xY w)Nr   r   r   rp   )rt   ru   rP   rw   rx   r{   s          r&   "test_copy_placeholder_to_clipboardzEChecksUsedInAdminEndpointsTestCase.test_copy_placeholder_to_clipboard   s    &&(	(0077V7D778JK&&}5$,,33!))002 4 
 $$Y/ 	(#');)>)>#')6)@)@)C)C	D KKS$'	( 	

$$&	( 	(s   "ADDc                    | j                         }t        ddd      }|j                  d      j                  d      }| j	                  |      }t
        j                  j                  d      }| j                  |      }| j                  |      5  d|j                  |j                  d|j                  d}| j                  j                  ||       d d d        | j                  j                          y # 1 sw Y   $xY w)Nr   r   r   r   r   rs   )r   r   r   r   ry   r   rB   rC   rz   rg   rT   rh   ri   r?   r4   )r    r!   r#   r|   r}   target_placeholderrj   rZ   s           r&   /test_copy_plugins_to_placeholder_without_sourcezRChecksUsedInAdminEndpointsTestCase.test_copy_plugins_to_placeholder_without_source   s    &&(	6#8$?!2248<<&<I778JK(0077V7D&&}5$$Y/ 	(#');)>)>$1$4$4#');)>)>D KKS$'	( 	

$$&	( 	(s   AC88Dc                    | j                         }t        ddd      }|j                  d      j                  d      }| j	                  |      }| j                  |      }| j                  |      5  t        |ddg      }d	|d<   | j                  j                  ||       d d d        | j                  j                  ||       y # 1 sw Y   &xY w)
Nr   r   r   r   r   rd   re   )r
   zContents modified)r   r   r   r   ry   get_change_plugin_urirg   r   rh   ri   r?   r3   r    r!   r#   r$   rV   rj   rZ   s          r&   test_edit_pluginz3ChecksUsedInAdminEndpointsTestCase.test_edit_plugin   s    &&(	6#8$?++D15565B00=((0$$Y/ 	( 0IJD.DLKKS$'	(
 	

**;	B	( 	(s   21CCc                 z   | j                         }t        ddd      }t        ddd      }|j                  d      j                  d      }|j                  d      j                  d      }| j	                  |      }| j                  |      }| j                  |      5  | j                  |d|      }| j                  j                  ||       d d d        | j                  | j                  j                  d       | j                  j                  t        ||      t        ||      g       y # 1 sw Y   axY w)	Nr   r   r   r   r      rW   r$      )r   r   r   r   ry   get_move_plugin_urirg   r[   rh   ri   r+   r?   
call_countassert_has_callsr   )	r    r!   r#   page2r|   r   r}   rj   rZ   s	            r&   test_move_pluginz3ChecksUsedInAdminEndpointsTestCase.test_move_plugin   s-   &&(	6#8$?F$94@!2248<<&<I"33D9==6=J778JK&&}5$$Y/ 	(&&. ' D
 KKS$'	( 	..2

###Y/#Y/%
 		( 	(s    1D11D:c                 8   | j                         }t        ddd      }|j                  d      j                  d      }| j	                  |      }| j                  |      }t        j                  j                  d|t        j                  j                               }| j                  |      5  | j                  |d|j                        }| j                  j                  ||       d d d        | j                  j!                  ||       y # 1 sw Y   &xY w)	Nr   r   r   r   r   rp   r   r   )r   r   r   r   ry   r   r	   rB   rC   r   rg   r[   rr   rh   ri   r?   r3   )r    r!   r#   r|   r}   rj   r~   rZ   s           r&   test_cut_pluginz2ChecksUsedInAdminEndpointsTestCase.test_cut_plugin   s   &&(	6#8$?!2248<<&<I778JK&&}5$,,33!))002 4 
 $$Y/ 	(&&)33 ' D
 KKS$'	( 	

**+=yI	( 	(s   0;DDc                    | j                         }t        ddd      }|j                  d      j                  d      }| j	                  |      }| j                  |      }| j                  |      5  ddi}| j                  j                  ||       d d d        | j                  j                  ||       y # 1 sw Y   &xY w)Nr   r   r   r   r   ri   T)r   r   r   r   ry   get_delete_plugin_urirg   rh   ri   r?   r3   r   s          r&   test_delete_pluginz5ChecksUsedInAdminEndpointsTestCase.test_delete_plugin   s    &&(	6#8$?++D15565B00=((0$$Y/ 	(D>DKKS$'	( 	

**;	B		( 	(s   2!B88Cc                 f   | j                         }t        ddd      }|j                  d      j                  d      }| j	                  |      }| j                  |      5  ddi}| j                  j                  ||       d d d        | j                  j                  ||       y # 1 sw Y   &xY w)Nr   r   r   r   r   r   )
r   r   r   r   get_clear_placeholder_urlrg   rh   ri   r?   r3   rm   s         r&   test_clear_placeholderz9ChecksUsedInAdminEndpointsTestCase.test_clear_placeholder  s    &&(	6#8$?++D15565B,,[9$$Y/ 	(A;DKKS$'	( 	

**;	B		( 	(s   !!B''B0)NN)r7   r8   r9   rJ   rL   r[   rk   rn   r   r   r   r   r   r   r   r   r:   r6   r&   rF   rF   J   sJ    ]
N('C'.','&C.J,C
Cr6   rF   N)unittest.mockr   r   r   django.forms.modelsr   cms.apir   
cms.modelsr   r	   r
   cms.models.fieldsr   cms.test_utils.testcasesr   r   r<   rF   r:   r6   r&   <module>r      sF    + + -  8 8 6 0&#[ &#R" ",MC MCr6   