
    Bh3                        d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZ d dlmZ d dlmZ d dlmZ 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/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7m8Z8 d dl9m:Z:m;Z;m<Z<m=Z=m>Z> d dl?m@Z@mAZAmBZBmCZC d dlDmEZE d dlFmGZG d dlHmIZI d dlJmKZK d dlLmMZM d d lNmOZOmPZP ed!        ZQ G d" d#e0      ZR G d$ d%eR      ZS e2j                  eS        G d& d'eE      ZU G d( d)eU      ZV G d* d+eU      ZW G d, d-eU      ZX G d. d/e      ZY G d0 d1e      ZZ G d2 d3e      Z[ G d4 d5e      Z\ G d6 d7eU      Z] G d8 d9eU      Z^y):    N)contextmanager)skipIf)http)settings)admin)FilteredSelectMultipleRelatedFieldWidgetWrapper)ImproperlyConfigured)Media)TestCase)re_pathreverse)timezone)	force_str)override)Text)api)create_page)DontUsePageAttributeWarningPluginAlreadyRegisteredPluginNotRegistered)PagePlaceholder)	CMSPlugin)CMSPluginBase)plugin_pool)
CMSSitemap)ArticleArticlePluginModelSection)
TestPluginTestPlugin2TestPlugin3TestPlugin4TestPlugin5)DynTemplateNonExisitngRenderTemplateNoRenderNoRenderButChildren)CMSTestCase)override_placeholder_conf)
CMSToolbar)get_object_edit_url)
DJANGO_5_1)copy_plugins_to_placeholderget_pluginsc               '      K   | D ]  }t        j                  |        t        j                          	 d  | D ]  }t        j                  |        y # | D ]  }t        j                  |        w xY wwN)r   register_plugin_clear_cachedunregister_plugin)pluginsplugins     F/home/dcms/DCMS/lib/python3.12/site-packages/cms/tests/test_plugins.pyregister_pluginsr9   2   ss      ,##F+, 2 	2F))&1	2g 	2F))&1	2s   1A6A A6A33A6c                   &    e Zd ZeZdZdZdZdZd Z	y)DumbFixturePluginz"Dumb Test Plugin. It does nothing. Fc                     |S r2    )selfcontextinstanceplaceholders       r8   renderzDumbFixturePlugin.renderH   s        N)
__name__
__module____qualname__r   modelnamerender_templateadmin_previewrender_pluginrC   r>   rD   r8   r;   r;   A   s     E/DOMMrD   r;   c                   :    e Zd Zej                  dz   ZdZd Zd Zy)DumbFixturePluginWithUrlsz With custom URLs.Fc                 ,    t        j                  d      S )NzIt works)r   HttpResponse)r?   requests     r8   
_test_viewz$DumbFixturePluginWithUrls._test_viewP   s      ,,rD   c                 n    t        dt        j                  j                  | j                        d      gS )Nz^testview/$dumbfixturepluginrI   )r   r   site
admin_viewrR   r?   s    r8   get_plugin_urlsz)DumbFixturePluginWithUrls.get_plugin_urlsS   s,    NEJJ$9$9$//$JQde
 	
rD   N)rE   rF   rG   r;   rI   rL   rR   rY   r>   rD   r8   rN   rN   L   s"    !!$88DM-
rD   rN   c                   6     e Zd Zd Zd Z fdZd Zd Z xZS )PluginsTestBaseCasec                 j   t        j                          | j                  ddd      | _        | j                  dd      | _        t
        j                  d   d   | _        t
        j                  d   d   | _        | j                  | j                        | _
        | j                  j                          y )NtestTslaver      )r   r4   _create_user
super_userr^   r   	LANGUAGES
FIRST_LANGSECOND_LANGlogin_user_context_login_context	__enter__rX   s    r8   setUpzPluginsTestBaseCase.setUp]   s    !!#++FD$?&&w5
",,Q/2#--a03"55dooF%%'rD   c                 >    | j                   j                  d d d        y r2   )rf   __exit__rX   s    r8   tearDownzPluginsTestBaseCase.tearDownh   s    $$T46rD   c                 d    t        |   |i |}t               |_        t	        |      |_        |S r2   )superget_requestr   placeholder_mediar,   toolbar)r?   argskwargsrQ   	__class__s       r8   rn   zPluginsTestBaseCase.get_requestk   s2    '%t6v6$)G!$W-rD   c                     t        |j                  j                  d      j                  d      d   j                  d      d         S )Nutf8z/edit-plugin/r_   /r   )intcontentdecodesplit)r?   responses     r8   get_response_pkz#PluginsTestBaseCase.get_response_pkq   s@    8##**6288I!LRRSVWXYZ[[rD   c                 B    t         j                  j                  d      S )Nr]   slot)r   objectscreaterX   s    r8   get_placeholderz#PluginsTestBaseCase.get_placeholdert   s    ""))v)66rD   )	rE   rF   rG   rh   rk   rn   r|   r   __classcell__)rs   s   @r8   r[   r[   \   s    	(7\7rD   r[   c                   ,   e Zd Zd.dZd Z e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 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/d)Z,d* Z-d+ Z.d, Z/y-)0PluginsTestCasec                 H   | j                  |j                  d      j                  |      dt        j                  d   d         }ddd}| j
                  j                  ||      }| j                  |j                  d	       t        j                  j                  d
      S )Nenr~   
LinkPluginr   rB   plugin_typelanguageA Linkhttps://www.django-cms.orgrI   external_link   pk)get_add_plugin_uriget_placeholdersgetr   rb   clientpostassertEqualstatus_coder   r   latest)r?   pager   add_urldatar{   s         r8   _create_link_plugin_on_pagez+PluginsTestCase._create_link_plugin_on_pagey   s    ))--d377T7B$''*1- * 

 !3OP;;##GT2--s3  ''--rD   c                 |   | j                  |      }| j                  j                  |      }| j                  |j                  d       |dd}| j                  j                  ||      }| j                  |j                  d       t        j                  j                  |j                        j                         S )Nr   r   r   r   )
get_change_plugin_urir   r   r   r   r   r   r   r   get_bound_plugin)r?   r7   textendpointr{   r   s         r8   __edit_link_pluginz"PluginsTestCase.__edit_link_plugin   s    --f5;;??8,--s3/KL;;##Hd3--s3  $$		$2CCEErD   z%Django 5.2+ fixed the template enginec                 r    | j                  t              5  t        t            ddd       y# 1 sw Y   yxY w)z
        Avoid a bug in Django's template engine that is incompatible with Python 3.9+
        type hinting. It has been fixed in Django 5.2
        See https://github.com/django-cms/django-cms/issues/7948
        N)assertRaises	TypeErrorr!   rw   rX   s    r8   test_no_plugin_class_get_itemz-PluginsTestCase.test_no_plugin_class_get_item   s.     y) 	sO	 	 	s   -6c                 4   | j                         }| j                  j                  | j                  d      |       t        j
                  j                         }| j                  |      }| j                  |d      }| j                  d|j                         y)z5
        Test that you can add a text plugin
        r   Hello WorldN)get_new_page_datar   r   get_page_add_urir   r   firstr   "_PluginsTestCase__edit_link_pluginr   rI   )r?   	page_datar   created_pluginr7   s        r8   test_add_edit_pluginz$PluginsTestCase.test_add_edit_plugin   sy    
 **,	..t4i@||!!#99$?((G4rD   c                 Z   t        j                          t         j                  j                  t           }| j                         }| j                  |dt        j                  d   d         }| j                         }t        j                  d      }| j                  |      5  | j                  |      } ||j                  t         j                        j                  |      }t!        |j"                  j%                               }|j                  |      }	t!        |	j"                  j%                               }
| j'                  ||
       | j)                  |j"                  d   j*                  t,               | j)                  |	j"                  d   j*                  t,               | j)                  |j"                  d   j*                  j*                  t.               | j)                  |	j"                  d   j*                  j*                  t.               d d d        y # 1 sw Y   y xY w)NArticlePluginr   r   r   )rH   
admin_sitesections)r   autodiscoverrV   	_registryr   r   r   r   rb   get_superuserr   
get_pluginre   rn   rH   get_formlistbase_fieldskeysr   assertIsInstancewidgetr	   r   )r?   admin_instancerB   r   	superuserr7   rQ   PluginFormClassplugin_fieldsOriginalFormClassoriginal_fieldss              r8   test_plugin_add_form_integrityz.PluginsTestCase.test_plugin_add_form_integrity   s   --.@A**,))+?]e]o]opq]rst]u)v&&(	''8$$Y/ (	&&w/G$ll :: hw  !!<!<!A!A!CDM . 7 7 @"#4#@#@#E#E#GHO ]O< !!++J7>>) !!!--j9@@) !!++J7>>EE& !!!--j9@@GG&K(	 (	 (	s   $E4H!!H*c                 0   dddgii}| j                  d      }t        |      5  | j                         }| j                  j	                  ||       t
        j                  j                         }t        j                  d|      }|D cg c]  }|j                   }}| j                  dg|       d d d        t        |      5  ddlm} |j                  d      }| j                  dg|       d d d        y c c}w # 1 sw Y   OxY w# 1 sw Y   y xY w)Nbodyr6   
TextPluginr   CMS_PLACEHOLDER_CONFr   )ColumnPlugin)r   r+   r   r   r   r   r   r   r   get_all_pluginsrE   r   @cms.test_utils.project.pluginapp.plugins.multicolumn.cms_pluginsr   get_child_classes)	r?   r   add_page_endpointr   r   installed_pluginsclsr   child_pluginss	            r8   test_restricted_pluginz&PluginsTestCase.test_restricted_plugin   s    &\N(CD 11$7 '<PQ 	@..0IKK.	:<<%%'D + ; ;FD I9J K# K Kl^->?	@ '<PQ 	<e(::64HMl^];		< 	<	 !L	@ 	@	< 	<s*   A%D 
C;D ,D;D  D	Dc                 
   dddgii}| j                  d      }t        |      5  | j                         }| j                  j	                  ||       t
        j                  j                         }t        j                  d|      }|D cg c]  }|j                   }}| j                  d|       ddd       ddgdgdi}t        |      5  | j                         }| j                  j	                  ||       t
        j                  j                         }t        j                  d|      }|D cg c]  }|j                   }}| j                  d|       ddd       yc c}w # 1 sw Y   xY wc c}w # 1 sw Y   yxY w)z7
        Test that you can't add a text plugin
        r   excluded_pluginsr   r   r   N)r6   r   )r   r+   r   r   r   r   r   r   r   r   rE   assertNotIn)r?   r   r   r   r   r   r   s          r8   test_excluded_pluginz$PluginsTestCase.test_excluded_plugin   sr   
 !');l^(LM 11$7 '<PQ 	>..0IKK.	:<<%%'D + ; ;FD I9J K# K K\+<=	> !'\NYeXf(gh '<PQ 	>..0IKK.	:<<%%'D + ; ;FD I9J K# K K\+<=	> 	> !L	> 	>  !L	> 	>s=   A%E(
E#E(A%E93E4E9#E((E14E99Fc                 >   t        j                  ddddd      }|j                  d      j                  d      }t        j                  |d	dd
      }t        j                  |d	dd      }t
        j                  j                  |j                        }t
        j                  j                  |j                        }| j                  d      5  | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                         |      }| j                  ||      }| j                  |d       ddd       y# 1 sw Y   yxY w)C
        Test that plugin position is saved after creation
        PluginOrderPagecol_two.htmlr   page1Tslugin_navigationcol_leftr~   r   I'm the firstr   I'm the secondr   FCMS_PERMISSIONr_      r   zI'm the firstI'm the secondN)r   r   r   r   
add_pluginr   r   r   r   r   positionget_contextget_absolute_url_render_placeholder)	r?   page_enph_entext_plugin_1text_plugin_2db_plugin_1db_plugin_2r@   rendered_placeholders	            r8   test_plugin_orderz!PluginsTestCase.test_plugin_order  sf    //"3^TPWgkl((.22
2C ulDWulDGWX''++}/?/?+@''++}/?/?+@]]%]0 	R]33Q7[1115]33Q7[1115&&w'?'?'A&PG#'#;#;E7#K 13PQ	R 	R 	Rs   B6FFc                    t        j                  ddddd      }|j                  d      j                  d      }t        j                  |d	dd
      }t        j                  |d	dd      }|j                  d      j                  d      }t        j                  |d	dd      }|j
                  dddd}| j                  |      }| j                  j                  ||       |j                  d      j                  d      }| j                  d      5  | j                  t        j                  j                  |j                        j                  d       | j                  t        j                  j                  |j                        j                  d       | j                  t        j                  j                  |j                        j                  d       | j                  |j!                         |      }| j#                  ||      }	| j                  |	d       ddd       y# 1 sw Y   yxY w)r   r   r   r   r   Tr   r   r~   r   r   r   zI'm the thirdr   r<   r_   )	plugin_idplugin_parenttarget_languagetarget_positionFr   r   r      r   z(I'm the firstI'm the secondI'm the thirdN)r   r   r   r   r   idget_move_plugin_urir   r   r   r   r   r   r   r   r   r   r   )
r?   cms_pagerB   r   text_plugin_3r   r   r   draft_page_contextr   s
             r8   test_plugin_order_altz%PluginsTestCase.test_plugin_order_alt  s    ??#4ndQXhlm//599z9J {L$M]^{L$_]//599z9J {L$_] '))# 	
 ++M:4(//599z9J]]%]0 	_Y..22m6F6F2GPPRSTY..22m6F6F2GPPRSTY..22m6F6F2GPPRST "&!1!1(2K2K2MT\!1!]#'#;#;KI[#\ 13]^	_ 	_ 	_s   DH44H=c                    t        j                  ddd      }|j                  d      j                  d      }|j                  d      j                  d      }t        j                  |dd      }t        j                  |dd|	      }t        j                  |dd|	      }t        j                  |d
d|d      }t        j                  |d
d|d      }t        |g|d|      }	t        |g|d      }
|j                  dg       | j                  |j                  d       t        |g|d|      }| j                  |j                  d       | j                  |j                  d       | j                  |	d   j                  d       | j                  |
d   j                  d       | j                  |d   j                  d       y )NCopyPluginTestPage (EN)nav_playground.htmlr   r   r~   right-columnMultiColumnPluginr   targetr   r   )r	  r   r   )root_pluginr   )fields   r      r      r_      )	r   r   r   r   r   r/   refresh_from_dbr   r   )r?   r   rB   placeholder_rightcolumnscolumn_1column_2text_1text_2
returned_1
returned_2
returned_3s               r8   test_plugin_positionz$PluginsTestCase.test_plugin_positionE  s   //";=RTXY..t488f8E#44T:>>N>S...A4H>>+~tGT>>+~tGT\4Wfg\4Wgh0&;Zbc
0&;LdS
 	   5**A.0&;Zbc
 	!,!,A//3A//3A//3rD   c                 &   t        j                  ddd      }t        j                  ddd      }|j                  d      j                  d      }|j                  d      j                  d      }t        j                  |ddd	
      }| j                  |j                  t        j                  j                         d   j                         t        j                  |dd|dd      }| j                  |      }| j                  |j                         j                         d       | j                  |j                  j                  |j                         | j                  t        j                  j                         d       t        |j                         |d       | j                  |j                   j#                  d      j                         d       |j                   j                  d      j%                         d   }| j                  |j                         j                         d       |j                         j                         j%                         d   }| j                  t        j                  j                         d       | j                  t        j                  j#                  d      j                         d       | j                  t        j                  j#                  d      j                         d       | j                  |      }| j                  |      }| j                  |j                         j                         d       | j                  |j                  j                  |j                         | j                  |j&                  |j&                         | j                  |j(                  |j(                         | j                  |j*                  |j*                         t        |g|d       y)z>
        Test that copying plugins works as expected.
        r  r  r   CopyPluginTestPage (DE)der   r~   r   r   r   r   r   r   r   r	  rI   r   r_   r   r   N)parentr  )r   r   r   r   r   r   r   r   r   allreloadget_childrencountr   r/   r0   cmsplugin_setfilterget_plugin_instancerI   r   r   )	r?   r   page_der   ph_detext_plugin_enlink_plugin_entext_plugin_delink_plugin_des	            r8   test_copy_pluginsz!PluginsTestCase.test_copy_pluginsm  s=   
 //";=RTXY//";=RTXY((.222?((.222? |TV**I,=,=,A,A,CA,F,I,IJ <n8[w

 ^4 	446<<>B..11>3D3DE 	**002A6 	$E$5$5$7N,,3343@FFH!L,,000=QQSTUV446<<>B'446::<PPRSTU 	**002A6 	**1141@FFH!L**1141@FFH!L^4^4 	446<<>B..11>3D3DE,,n.A.AB55~7S7ST,,n.A.AB 	$^$4edKrD   c                    t        j                  ddd      }|j                  d      j                  d      }t        j                  |ddd      }t        j                  |d	dd|
      }t        j                  |d	dd|
      }t        j                  |dd|dd      }||||g}t        j                  ddd      }|j                  d      j                  d      }	t        j                  |	ddd      }
t        j                  |	d	dd|

      }t        ||||g|	d|       | j                  |      }|j                         }| j                  |j                         t        |             t        ||      D ]O  \  }}| j                  |j                         j                         |j                         j                                Q y )Nr  r  r   r   r~   r  zfirst-child)r   r   )r   r	  r   r   r   r  r  r  )r6   rB   r   r
  )r   r   r   r   r   r/   r"  get_descendantsr   r$  lenzipr#  )r?   r   r   mcol1_encol1_encol2_enr+  old_pluginsr(  r)  mcol1_decol1_denew_plugins
old_plugin
new_plugins                  r8   test_deep_copy_pluginsz&PluginsTestCase.test_deep_copy_plugins  s   //";=RTXY((.222? >>%)<d][ ..}]ef ..}]ef <gHTp
  '>B//";=RTXY((.222? >>%)<d][ ..}]ef#w@		
 ++g&--/**,c+.>?&)+{&C 	c"J
Z446<<>
@W@W@Y@_@_@ab	crD   c                 "   t        j                  ddd      }t        j                  ddd      }|j                  d      j                  d      }|j                  d      j                  d      }t        j                  |dd       | j                  |j                  d      j                         d	       | j                  |j                  d      j                         d
       t        |j                  d      |d      }|j                  d      D cg c]  }|j                          }}| j                  t        |      d	       | j                  |j                  d      j                         d	       | j                  ||       y c c}w )Nr  r  r   r  r  r   r~   NoCustomModelr_   r   r  r   r   r   r   r   r   r0   r$  r/   get_plugins_listr   r1  assertSequenceEqual)r?   r   r(  r   r)  r9  r7   new_plugins_qss           r8   %test_copy_plugin_without_custom_modelz5PluginsTestCase.test_copy_plugin_without_custom_model  sV   //";=RTXY//";=RTXY((.222?((.222?uot4 	**40668!<**40668!< 2%2H2H2NPU`deBGBSBSTXBYZ&113ZZ[)1-**40668!<  = [s   Fc                    t        j                  ddd      }t        j                  ddd      }|j                  d      j                  d      }|j                  d      j                  d      }t        j                  |dd      }t        j                  |d	d|
      }t        j                  |dd|
       | j                  |j                  d      j                         d       | j                  |j                  d      j                         d       t        |j                  d      |d      }|j                  d      D cg c]  }|j                          }	}| j                  t        |      d       | j                  |j                  d      j                         d       | j                  |	|       y c c}w )Nr  r  r   r  r  r   r~   r  r   r  r>  r   r   r  r?  )
r?   r   r(  r   r)  grid_plugincolumn_pluginr9  r7   rB  s
             r8   -test_copy_nested_plugins_without_custom_modelz=PluginsTestCase.test_copy_nested_plugins_without_custom_model  s   //";=RTXY//";=RTXY((.222?((.222?nnU,?Fund;WuotMJ 	**40668!<**40668!< 2%2H2H2NPU`deBGBSBSTXBYZ&113ZZ[)1-**40668!<  = [s   F>c                 ,   | j                  t        t        j                  t               | j                  t        t        j                  t
               | j                  t        t        j                  t               t        j                  t               y r2   )r   r
   r   validate_templatesr'   r(   r)   r&   rX   s    r8   test_plugin_validationz&PluginsTestCase.test_plugin_validation  s^    .0N0NPij.0N0NPXY.0N0NPcd&&{3rD   c                 ~   t        j                  dt        j                  d   d   d      }t        j                  |j                  t        j                  d   d         j                  d      ddd	
      }| j                  t        j                  j                         j                         d       d|j                  i}| j                  |      }| j                  j                  ||      }| j!                  |d       | j                  dt        j                  j                         j                                y)zo
        When removing a draft plugin we would expect the public copy of the plugin to also be removed
        	test pager   r  )titler   templater   r~   r   r   r<   )rB   r   r   r   r_   r   z<div class="success"></div>N)r   r   r   rb   r   r   r   r   r   r   r!  r$  r   get_delete_plugin_urir   r   assertContains)r?   r   r7   plugin_datar   r{   s         r8   #test_remove_plugin_before_publishedz3PluginsTestCase.test_remove_plugin_before_published  s   
 [8;M;Ma;PQR;S^st--h.@.@.CA.FGKKQWKX$	
 	**..0668!< #FII.--f5;;##Hk:H&CDI--11399;<rD   c                 B   t        j                  ddd      }t        j                  |j                  d      j	                  d      dt
        j                  d   d   d	
      }| j                  t        j                  j                         j                         d       t        d      }|j                          | j                  |dt
        j                  d   d   |      }| j                  j!                  |dd	i      }| j                  |j"                  d       y)z0
        Test case for PlaceholderField
        rL  r  r   )rM  rN  r   r   r~   r   r   r<   )rB   r   r   r   r_   	subpluginr   rB   r   r   r     N)r   r   r   r   r   r   rb   r   r   r   r!  r$  r   saver   r   r   r   )r?   r   r7   phr   r{   s         r8   )test_remove_plugin_not_associated_to_pagez9PluginsTestCase.test_remove_plugin_not_associated_to_page  s     [;P[_`--d377V7D$''*1-	
 	**..0668!<k*
	))(BTBTUVBWXYBZci * 
 ;;##Gfb\:--s3rD   c                 P   t        t        j                        }t        t              5  d}	 t        j
                  t               | j                  |       d d d        t        t        j                        }| j                  ||       y # t        $ r d}Y Rw xY w# 1 sw Y   FxY wNFT)	r1  r   registered_pluginsr9   r;   r3   r   
assertTruer   r?   number_of_plugins_beforeraisednumber_of_plugins_afters       r8   'test_register_plugin_twice_should_raisez7PluginsTestCase.test_register_plugin_twice_should_raise0  s    #&{'E'E#F /0 	$F++,=> OOF#	$ #&k&D&D"E13JK + 	$ 	$s.   BBBBBBBB%c                    t        t        j                        }d}	 t        j                  t               | j                  |       t        t        j                        }| j                  ||       y # t
        $ r d}Y Jw xY wr[  )r1  r   r\  r5   r;   r   r]  r   r^  s       r8   0test_unregister_non_existing_plugin_should_raisez@PluginsTestCase.test_unregister_non_existing_plugin_should_raise?  su    #&{'E'E#F 	 ))*;< 	"%k&D&D"E13JK # 	F	s   A3 3B Bc                    t        j                  ddd      }|j                  d      j                  d      }t	        dd|dd	      }|j                          | j                  t        j                  j                  d
      j                         d       | j                  t        j                  j                  d      j                         d       y)al  
        Test search for pages
        To be fully useful, this testcase needs to have the following different
        Plugin configurations within the project:
            * unaltered cmsplugin_ptr
            * cmsplugin_ptr with related_name='+'
            * cmsplugin_ptr with related_query_name='+'
            * cmsplugin_ptr with related_query_name='whatever_foo'
            * cmsplugin_ptr with related_name='whatever_bar'
            * cmsplugin_ptr with related_query_name='whatever_foo' and related_name='whatever_bar'
        Those plugins are in cms/test_utils/project/pluginapp/revdesc/models.py
        r   r  r   r   r~   hellor   r_   )r   r   rB   r   r   hir   N)r   r   r   r   r   rW  r   r   r   searchr$  )r?   r   rB   r   s       r8   test_search_pagesz!PluginsTestCase.test_search_pagesM  s     v'<dC++D15565B4[Vbmno		,,T288:A>,,W5;;=qArD   c                    t        j                  ddd      }|j                  d      j                  d      }t        j
                  j                  d|d| j                         | j                  || j                         d	
      }| j                  t        |             | j                  t        |j                               y )Nr   r  r   r   r~   r   r_   r   rB   r   r   i,  )width)r   r   r   r   r   r   r   rc   r   r   assertFalser1  _plugins_cache)r?   r   rB   outs       r8   test_empty_plugin_is_ignoredz,PluginsTestCase.test_empty_plugin_is_ignoredb  s    v'<dC++D15565B  $#__	 	! 	
 &&{D4D4D4Fc&RS"[7789rD   c                    t               }| j                  |j                         | j                  dt	        |             | j                  dt	        |             t         j
                  j                  d      }| j                  d|j                   t	        |             | j                  d|j                   dt	        |             y )Nzid=Nonezplugin_type=''r   )r   zid=zplugin_type='')r   assertIsNoner   assertInreprr   r   r   )r?   non_saved_pluginsaved_plugins      r8   	test_reprzPluginsTestCase.test_reprr  s    $;*--.i&6!78&-=(>? ((//L/ILOO,-tL/ABl&>&>%?qA4CUVrD   c                    t        j                  ddd      }|j                  d      j                  d      }t        j                  |ddd      }|j
                  }| j                  |t        j                  t        j                  |                   | j                  |t        j                  t        j                  |                   y )	Nr   r  r   r   r~   r   r   r   )
r   r   r   r   r   cmsplugin_ptrr   pickleloadsdumps)r?   r   rB   text_plugin
cms_plugins        r8   test_picklezPluginsTestCase.test_pickle|  s    v'<dC++D15565Bnn	
 !..
 	fll6<<3L&MN 	V\\&,,z2J%KLrD   c                 Z   t        j                  ddd      }|j                  d      j                  d      }t        j                  |ddd       t
        j                  j                         j                  d	      }d
d l	}|j                         }t        j                  |d
   |       y )Nr   r  r   r   r~   r   r   r   r   r   )r   r   r   r   r   r   r   r!  deferioBytesIOr{  dump)r?   r   rB   r6   r  as         r8   test_defer_picklez!PluginsTestCase.test_defer_pickle  s    v'<dC++D15565B{L$]K,,""$**:6JJLGAJ"rD   c                    t        j                  ddd      }|j                  d      j                  d      }t	        d|d| j
                        }|j                          | j                  |j                         d	       y )
Nr   r  r   r   r~   r   r_   rk  z<Empty>)	r   r   r   r   r   rc   rW  r   get_short_description)r?   r   rB   r  s       r8   test_empty_plugin_descriptionz-PluginsTestCase.test_empty_plugin_description  sq    v'<dC++D15565B$#__	
 	
002I>rD   c                    t        j                  ddd      }|j                  d      j                  d      }t	        d|d| j
                        }|j                          d	 }| j                  t        d
||       t        j                  d      5 }t        j                  d       |j                   | j                  dt        |             | j                  d|d   j                          d d d        y # 1 sw Y   y xY w)Nr   r  r   r   r~   r   r_   rk  c                     | j                   S r2   r   )r7   s    r8   get_pagez;PluginsTestCase.test_page_attribute_warns.<locals>.get_page  s    ;;rD   znDon't use the page attribute on CMSPlugins! CMSPlugins are not guaranteed to have a page associated with them!T)recordalwaysztest_plugins.pyr   )r   r   r   r   r   rc   rW  failUnlessWarnsr   warningscatch_warningssimplefilterr   r   r1  rt  filename)r?   r   rB   r  r  ws         r8   test_page_attribute_warnsz)PluginsTestCase.test_page_attribute_warns  s    v'<dC++D15565B,KRS^b^m^mn		 	'Q	
 $$D1 	<Q!!(+FFQA'MM+QqT]];		< 	< 	<s   AC88Dc                    t        j                         }|t        j                  d      z
  }t	        j
                  ddd      }||_        ||_        |j                          | j                  |d      }| j                  |d      }t               }|j                  |j                         j                               }|t        j                  |j                  	      z  }| j!                  |j                  j#                         |j#                                | j!                  |j                  j#                         |j#                         t        j                  d      z          y )
Nr_   )daysr   r  r   r   r~   fnord)microseconds)r   nowdatetime	timedeltar   r   creation_datechanged_daterW  r   r   r   lastmoditemsr   microsecondr   date)r?   r  one_day_agor   r7   sitemapactual_last_modification_times          r8   =test_editing_plugin_changes_page_modification_time_in_sitemapzMPluginsTestCase.test_editing_plugin_changes_page_modification_time_in_sitemap  s   llnH..A66v'<dC('		11$V1D((9,(/8M8M8O(P%%););IfIrIr)ss%,,1135R5W5W5YZ**//1;3C3C3EHZHZ`aHb3bcrD   c                    t        t              5  t        j                  ddd      }t        j                  |j                  d      j                  d      dt        j                  d   d         }t        j                  |j                  d      j                  d      dt        j                  d   d   |	      }|j                  |j                  d      j                  d
      j                  dddd}| j                  |      }| j                  j                  ||      }| j                  |j                  d       d d d        y # 1 sw Y   y xY w)Nr   r  r   r   r~   r;   r   r   rU  r  r<   r_   )r   placeholder_idr   r   r   r   )r9   r;   r   r   r   r   r   r   rb   r   r   r   r   r   r   )r?   r   r7   child_pluginr   r   r{   s          r8   +test_moving_plugin_to_different_placeholderz;PluginsTestCase.test_moving_plugin_to_different_placeholder  s1   /0 	8??6+@$GD^^ 11$7;;;H/!++A.q1F
 >> 11$7;;;H/!++A.q1	L *__"&"7"7"="A"A~"A"V"Y"Y#'!##$D //=H{{''$7HX1137/	8 	8 	8s   D3EEc                     t        d      }| j                  j                  |      }| j                  |j                  d       | j                  |j
                  d       y )Nzadmin:dumbfixturepluginr   s   It works)r   r   r   r   r   rx   )r?   
plugin_urlr{   s      r8   test_custom_plugin_urlsz'PluginsTestCase.test_custom_plugin_urls  sK    67
;;??:.--s3));7rD   c                 B   t        dt        ft        dd            }t        |      5  t	        j
                  ddd      }|j                  d      j                  d	      }t        j                  ||
      }| j                  ||v        ddd       y# 1 sw Y   yxY w)z
        Assert that a plugin marked as 'require_parent' is not listed
        in the plugin pool when a placeholder is specified
        ParentRequiredPluginTFrequire_parentrL   r   r  r   r   r~   )rB   r   N)typer   dictr9   r   r   r   r   r   r   rm  )r?   r  r   rB   plugin_lists        r8   test_plugin_require_parentz*PluginsTestCase.test_plugin_require_parent  s    
  $"]$4d$^c6d 
 23 	B??6+@$GD//599v9FK%55+TXYK1[@A	B 	B 	Bs   A#BBc                    t        j                  ddd      }|j                  d      j                  d      }ddlm} dd	d
d}dd	d
d} |t        j                  |j                  |      }|D cg c]  }|d   d
k(  s| }}| j                  t        |      d       |d   }t        d      5  | j                  t        |d         |d          | j                  t        |d         |d          d d d        t        d      5  | j                  t        |d         |d          | j                  t        |d         |d          d d d        y c c}w # 1 sw Y   exY w# 1 sw Y   y xY w)Nr   r  r   r   r~   r   )get_toolbar_plugin_structGenericStyleStylePlugin)modulerI   value	Generisch)r6   r   r   r  r_   r  rI   r  )r   r   r   r   cms.utils.placeholderr  r   r\  r   r   r1  force_languager   )	r?   r   rB   r  expected_struct_enexpected_struct_detoolbar_structconfigstyle_configs	            r8   test_plugin_toolbar_structz*PluginsTestCase.test_plugin_toolbar_struct  s   v'<dC++D15565BC  "
 ""
 322!!
 .<`6vgR_?_``\*A.#AD! 	ZY|H'=>@RS[@\]Y|F';<>PQW>XY	Z D! 	ZY|H'=>@RS[@\]Y|F';<>PQW>XY	Z 	Z a	Z 	Z	Z 	Zs&   2E E1AEAE$E!$E-c                 ,   | j                         }| j                  |      }t        |      }| j                         }|j	                  d      j                  d      }| j                  |d       | j                  |d       | j                  |      5  | j                  ||      }t        |      |_
        | j                  |      }|j                  |d|      }| j                  d	|       | j                  d
|       d d d        y # 1 sw Y   y xY w)Nr   r   r~   change_pageadd_textr   )rQ   )r   r   zA<a data-rel="add" data-add-form="true" href="TextPlugin">Text</a>zA<a data-rel="add" data-add-form="true" href="LinkPlugin">Link</a>)get_permissions_test_pageget_pagecontent_objr-   "get_staff_user_with_no_permissionsr   r   add_permissionre   rn   r,   rp   get_structure_rendererrender_placeholderrt  r   )	r?   r   page_contentpage_edit_url
staff_userrB   rQ   rendereroutputs	            r8   &test_plugin_toolbar_struct_permissionsz6PluginsTestCase.test_plugin_toolbar_struct_permissions#  s   --///5+L9<<>
++D15565BJ6J
3$$Z0 	j&&}4&@G(1GO2272CH00tRV0WFMM]_ef`bhi	j 	j 	js   A.D

Dc           	      p   t        j                  ddd      }|j                  d      j                  d      }t	        dt
        ft        dgd	            }t        |      5  t        j                  ||t        j                  d
   d
         }|j                         }| j                  dg|j                  |j                  |             dddddgiii}t        |      5  | j                  dg|j                  |j                  |             d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r  r   r   r~   ChildClassesPluginr   zallow_children_plugin.html)child_classesrJ   r   r  r   PicturePluginr   )r   r   r   r   r  r   r  r9   r   r   rb   get_plugin_class_instancer   r   r   r+   )r?   r   rB   r  r7   r   s         r8   'test_plugin_child_classes_from_settingsz7PluginsTestCase.test_plugin_child_classes_from_settings5  sE   v'<dC++D15565B! ~?[\
 01 	c^^K1CXEWEWXYEZ[\E]^F557Fl^V-E-EkFVFVX\-]^ #,|_.M&$  +@TU c  ,1I1I+JZJZ\`1abc	c 	cc c	c 	cs%   "A?D,!.D D, D)	%D,,D5c           	      n   t        j                  ddd      }|j                  d      j                  d      }t	        dt
        ft        dgd	            }t        |      5  t        j                  ||t        j                  d
   d
         }|j                         }| j                  dg|j                  |j                  |             ddddgiii}t        |      5  | j                  dg|j                  |j                  |             d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r  r   r   r~   ParentClassesPluginr   Fparent_classesrL   r   r  r!   r   )r   r   r   r   r  r   r  r9   r   r   rb   r  r   get_parent_classesr   r+   )r?   r   rB   r  r7   r   s         r8   (test_plugin_parent_classes_from_settingsz8PluginsTestCase.test_plugin_parent_classes_from_settingsO  s@   v'<dC++D15565B"!M#3T,gl5m
 12 	d^^K1DhFXFXYZF[\]F^_F557Fl^V-F-F{GWGWY]-^_ $-~'$  +@TU d  ,1J1J;K[K[]a1bcd	d 	dd d	d 	ds%   "A>D+ .DD+D(	$D++D4c                 "   t        j                  ddd      }|j                  d      j                  d      }t	        dt
        ft        dd	            }t	        d
t
        ft        dgd            }t        ||      5  t        j                  ||t        j                  d   d         }|j                         }|j                  |j                  |      }| j                  d
|       | j                  d|       d d d        y # 1 sw Y   y xY w)Nr   r  r   r   r~   ParentPluginFTrL   allow_childrenChildPluginr  r   r   r   r   r   r  r   r  r9   r   r   rb   r  r   r   rt  r?   r   rB   r  r  r7   r  s          r8   &test_plugin_parent_classes_from_objectz6PluginsTestCase.test_plugin_parent_classes_from_objectf  s    v'<dC++D15565BN],<dQVgk>lm==*:DQ_P`pu<vwlK8 	9^^Kx?Q?QRS?TUV?WXF557F"44[5E5EtLMMM-7MM.-8	9 	9 	9s    A<DDc           	      h   ddl m} t        j                  ddd      }|j	                  d      j                  d      }t        dt        ft        d	d
            }t        dt        ft        d	dgd	            }i }t        ||      5  t        j                  ||t        j                  d   d         } ||||      \  }}	| j                  d|       | j                  d|       dg|_         ||||      \  }}	| j                  d|       | j                  d|       d d d        y # 1 sw Y   y xY w)Nr   get_plugin_restrictionsr   r  r   r   r~   r  FTr  r  cache_parent_classesr  rL   r<   )cms.utils.pluginsr  r   r   r   r   r  r   r  r9   r   r   rb   rt  r  r   
r?   r  r   rB   r  r  restriction_cacher7   r  _s
             r8   ;test_plugin_child_classes_cache_ignores_uncachable_childrenzKPluginsTestCase.test_plugin_child_classes_cache_ignores_uncachable_childrent  s4   =v'<dC++D15565BN],<dQVgk>lm%* ./#
 lK8 	9^^Kx?Q?QRS?TUV?WXF6vtEVWM1 MM-7MM.-8 +-K&6vtEVWM1 ]M:MM.-8!	9 	9 	9   	BD((D1c           	      h   ddl m} t        j                  ddd      }|j	                  d      j                  d      }t        dt        ft        d	d
            }t        dt        ft        d	dgd	            }i }t        ||      5  t        j                  ||t        j                  d   d         } ||||      \  }}	| j                  d|       | j                  d|       dg|_         ||||      \  }}	| j                  d|       | j                  d|       d d d        y # 1 sw Y   y xY w)Nr   r  r   r  r   r   r~   r  FTr  r  r<   r  )r  r  r   r   r   r   r  r   r  r9   r   r   rb   r   rt  r  r  s
             r8   ;test_plugin_child_classes_allows_add_by_uncachable_childrenzKPluginsTestCase.test_plugin_child_classes_allows_add_by_uncachable_children  s2   =v'<dC++D15565BN],<dQVgk>lm%* "t#
 lK8 	9^^Kx?Q?QRS?TUV?WXF6vtEVWM1]M:MM.-8 +9)9K&  7vtEVWM1MM-7MM.-8	9 	9 	9r  c                     t        j                  ddd      }|j                  d      j                  d      }t	        dt
        ft        dd	            }t	        d
t
        ft        dd            }t        ||      5  t        j                  ||t        j                  d   d         }|j                         }|j                  |j                  |      }| j                  d
|       | j                  d|       d d d        y # 1 sw Y   y xY w)Nr   r  r   r   r~   r  FTr  r  r  r   r  r  s          r8   &test_plugin_require_parent_from_objectz6PluginsTestCase.test_plugin_require_parent_from_object  s    v'<dC++D15565BN],<dQVgk>lm==*:DPTdi<jklK8 	9^^Kx?Q?QRS?TUV?WXF557F"44[5E5EtLMMM-7MM.-8	9 	9 	9s   ?A<DDc                 j    t         j                   G d dt                     }| j                  |       y )Nc                       e Zd ZdZdZy)[PluginsTestCase.test_plugin_pool_register_returns_plugin_class.<locals>.DecoratorTestPluginFzTest PluginN)rE   rF   rG   rL   rI   r>   rD   r8   DecoratorTestPluginr    s    !M DrD   r  )r   r3   r   assertIsNotNone)r?   r  s     r8   .test_plugin_pool_register_returns_plugin_classz>PluginsTestCase.test_plugin_pool_register_returns_plugin_class  s2    		$	$	!- 	! 
%	! 	01rD   c                 
   dd l }ddlm} t        t              5  |j                  t        |      D cg c]  }t        j                  |t        d       c}|      }t        |      D ]>  \  }}	||z   dz   |	_
        |dkD  r||dz
     j                  |	_        |	j                          @ t        |d      D ]  \  }}	||	_
        |	j                           |rt         ||            }d d d        |S c c}w # 1 sw Y   S xY w)Nr   )downcast_pluginsr   )kr_   )start)randomr  r   r9   r   sampleranger   r   	enumerater   r   	parent_idrW  r   )
r?   rB   ndowncastr  r   r  r6   ir7   s
             r8   _create_plugin_treez#PluginsTestCase._create_plugin_tree  s    6m, 	:mm_def_g$hZ[S^^KPT%U$hlmmnG&w/ 	6"#a%!)q5'.q1u~'8'8F$	
 'wa8 	6"# /89	:  %i	: s   C8"C3
BC83C88Dc                 \   | j                         }| j                  |dd      }| j                  d      5  |d   j                         }d d d        | j	                  D cg c]  }|j
                   c}|d d D cg c]  }|j
                   c}       y # 1 sw Y   OxY wc c}w c c}w )N
   Fr	  r   r   r  assertNumQueriesget_ancestorsr   r   r?   rB   r6   	ancestorsancestorr7   s         r8   test_get_ancestorsz"PluginsTestCase.test_get_ancestors  s    **,**;U*K""1% 	4113I	4 	i@((++@[bcfdf[gBhQW699Bhi	4 	4 ABh   B!B$=B)
B!c                 R   | j                         }t        t              5  t        j                  |t        d      }|j                          d d d        | j                  d      5  j                         }d d d        | j                  g        y # 1 sw Y   FxY w# 1 sw Y   (xY w)Nr   r   )	r   r9   r   r   r   rW  r  r  r   )r?   rB   r7   r  s       r8   test_get_ancestors_no_parentz,PluginsTestCase.test_get_ancestors_no_parent  s    **,m, 	^^KEFKKM	 ""1% 	/,,.I	/B'	 		/ 	/s   ,B%BBB&c                 \   | j                         }| j                  |dd      }| j                  d      5  |d   j                         }d d d        | j	                  D cg c]  }|j
                   c}|d d D cg c]  }|j
                   c}       y # 1 sw Y   OxY wc c}w c c}w )Nr  Tr  r   r  r  r  s         r8   *test_get_ancestors_with_downcasted_pluginsz:PluginsTestCase.test_get_ancestors_with_downcasted_plugins  s    **,**;T*J""1% 	4113I	4 	i@((++@[bcfdf[gBhQW699Bhi	4 	4 ABhr  N)r   )F)0rE   rF   rG   r   r   r   r.   r   r   r   r   r   r   r  r  r.  r<  rC  rG  rJ  rR  rY  rb  rd  ri  rp  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r>   rD   r8   r   r   x   s   	.F 
NCD E50d<(>8R0%_N&4P9Lv+cZ>$>(4=.40LLB*: WM"#?<.d 848B %ZNj$c4d.9!9F 9D92*j(jrD   r   c                   $    e Zd Zd Zd Zd Zd Zy)PluginManyToManyTestCasec                    | j                  ddd      | _        | j                  dd      | _        | j                  | j                        | _        | j                  j                          g | _        g | _        t        d      D ]e  }t        j                  j                  d|z        }| j                  j                  |       | j                  j                  |j                         g t        | j                        | _        | j                  D ]6  }t        d      D ]&  }t         j                  j                  d|z  |	       ( 8 t"        j$                  d
   d
   | _        t"        j$                  d   d
   | _        y )Nr]   Tr^   r   z
section %srU   r  z
article %s)rM  sectionr   r_   )r`   ra   r^   re   rf   rg   r   section_pksr  r    r   r   appendr   r1  section_countr   r   rb   rc   rd   )r?   r
  r  js       r8   rh   zPluginManyToManyTestCase.setUp  sI   ++FD$?&&w5
"55dooF%%' q 	0Aoo,,,2B,CGMM  )##GJJ/	0 !/}} 	PG2Y P&&\A-=w&OP	P #,,Q/2#--a03rD   c                    t        j                  ddd      }|j                  d      j                  d      }t        j                  |ddd       t        j                  |ddd	       | j                  |j                         
      }|d   }t        |||j                        }| j                         }|D ]  }|j                  d	k(  rX|j                  |||      }| j                  |j                         j                  i ||      d       | j                  d|v        j|j                  |||      }| j                  |j                         j                  i ||      d       | j!                  d|v         y )Nr  r  r   r   r~   ArticleDynamicTemplatePluginza title)rM  zcustom template)pathrQ   zarticles_custom.htmlzArticles Custom templatezarticles.html)r   r   r   r   r   r   r   r0   rN  get_content_rendererrM  rL   r   r  get_render_templater]  rm  )	r?   r   r   r@   rQ   r6   content_rendererr7   rx   s	            r8   test_dynamic_plugin_templatez5PluginManyToManyTestCase.test_dynamic_plugin_template  so   //";=RTXY((.222?u<d)Tu<dJ[\""(@(@(B"C)$gug.>.>?446 	HF||00*88%P  446JJ2vW\]_u  :g EF*88%P  446JJ2vW\]_n   !;w!FG	HrD   c                    | j                  t        j                  j                         d       | j	                         }| j
                  j                  | j                  d      |       t        j                  j                         }|j                  | j                        j                  d      }| j                  |d| j                        }d| j                  d}| j
                  j                  ||      }| j                  |j                  d	       | j                  t        j                  j                         d
       t        j                  j!                         d   }| j                  | j"                  |j$                  j                                | j
                  j                  d      }| j                  |j                  d	       | j                  |j$                  j&                  j(                  j*                  d       y )Nr   r   r   r~   r   r   Articles Plugin 1rM  r   r   r_   z/en/*manytomany_rel_articlepluginmodel_sections)r   r   r   r$  r   r   r   r   r   r   r   rc   r   r   r   r   r!  r"  r   through_metadb_table)r?   r   r   rB   r   r   r{   r7   s           r8   test_add_plugin_with_m2mz1PluginManyToManyTestCase.test_add_plugin_with_m2m0  s   +3399;Q?**,	..t4i@||!!#++DOO<@@j@Q))#'__ * 

 -$:J:JK;;##GT2--s3+3399;Q?#++//1!4++V__-B-B-DE;;??6*--s30066??AmnrD   c                 	   t        j                  ddd      }|j                  d      j                  d      }t        j
                  j                  d|d| j                        }| j                  || j                  	      }d
| j                  d}| j                  j                  ||      }| j                  |j                  d       | j                  t        j
                  j                         d       | j                  t        j
                  j                         d   j                   j                         | j"                         | j%                         }|j'                  |j)                          d| j*                   |j,                  d       | j/                  | j*                  |      }| j                  j                  ||      }| j1                  || j3                  | j*                               | j                  t4        j
                  j7                  | j                  	      j                         d       | j                  t4        j
                  j7                  | j*                  	      j                         d       | j                  t4        j
                  j                         d       | j                  t8        j
                  j                         j                         d       |j,                  |j,                  | j*                  | j                  d}| j;                  || j                  	      }| j                  j                  ||      }| j                  |j                  d       | j                  |j<                  j?                  d      j                  d      d       | j                  t4        j
                  j7                  | j                  	      j                         d       | j                  t4        j
                  j7                  | j*                  	      j                         d       | j                  t4        j
                  j                         d       t        j
                  j                         D 	cg c]  }	|	j                   j                          }
}	tA        tC        |
            D cg c]  }| j"                   }}| j                  ||
       y c c}	w c c}w )Nr   r  r   r   r~   r   r_   rk  r  r,  r-  r   r    )rM  r   )source_placeholder_idtarget_placeholder_idr   source_languageru   z"plugin_type": "ArticlePlugin"r   )"r   r   r   r   r   r   r   rc   r   r   r   r   r   r   r$  r!  r   r"  r   update	get_titlerd   r   r   assertRedirectsget_pages_admin_list_urir   r&  r   get_copy_plugin_urirx   ry   r  r1  )r?   r   rB   r7   r   r   r{   r   	copy_dataplgn	db_countsr  expecteds                r8   test_copy_plugin_with_m2mz2PluginManyToManyTestCase.test_copy_plugin_with_m2mF  s   v'<dC++D15565B#++22'#__	 3 
 --ft-O,$:J:JK;;##Hd3--s3+3399;Q?+33779!<EEKKMtOaOab**,	 NN,-Qt/?/?.@A GG	
 (()9)94@;;##Hi8Xt'D'DTEUEU'VW**114??1KQQSUVW**114;K;K1LRRTVWX**002A6))+113Q7 &1^^%0^^#//#	
	 ++FT__+M;;##Hi8--s3))008>>?_`bcd**114??1KQQSUVW**114;K;K1LRRTVWX**002A67I7Q7Q7U7U7WXtT]]((*X	X05c)n0EF1D&&FF9- YFs   !S0S5N)rE   rF   rG   rh   r*  r2  rA  r>   rD   r8   r  r    s    4,H0o,4.rD   r  c                       e Zd ZdZd Zy)PluginCopyRelationsTestCasez5Test the suggestions in the docs for copy_relations()c                    | j                  ddd      | _        t        j                  d   d   | _        | j                  | j                        | _        | j                  j                          | j                         }d|d<   t        j                  di || _        | j                         }d|d<   t        j                  di || _        | j                  j                  | j                        j                  d      | _        | j                  j                  | j                        j                  d      | _        y )	Nr]   Tr   F	publishedr   r~   r>   )r`   ra   r   rb   rc   re   rf   rg   get_new_page_data_dbfieldsr   r   r   page2r   r   placeholder1placeholder2)r?   
page_data1
page_data2s      r8   rh   z!PluginCopyRelationsTestCase.setUp  s   ++FD$?",,Q/2"55dooF%%'446
"'
;__2z2
446
"'
;__2z2
 JJ77HLLRXLY JJ77HLLRXLYrD   N)rE   rF   rG   __doc__rh   r>   rD   r8   rC  rC  }  s    ?ZrD   rC  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)PluginsMetaOptionsTestsz8TestCase set for ensuring that bugs like #992 are caughtc                     t         j                  }| j                  |j                  j                  d       | j                  |j                  j
                  d       y)z<handling when a CMSPlugin meta options are computed defaultsmeta_testpluginmodelmetaN)r!   rH   r   r0  r1  	app_labelr?   r7   s     r8   test_meta_options_as_defaultsz5PluginsMetaOptionsTests.test_meta_options_as_defaults  sD    
 !!..0FG//8rD   c                     t         j                  }| j                  |j                  j                  d       | j                  |j                  j
                  d       y)zChandling when a CMSPlugin meta options are declared as per defaultsmeta_testpluginmodel2rQ  N)r"   rH   r   r0  r1  rR  rS  s     r8   &test_meta_options_as_declared_defaultsz>PluginsMetaOptionsTests.test_meta_options_as_declared_defaults  sD     ""..0GH//8rD   c                     t         j                  }| j                  |j                  j                  d       | j                  |j                  j
                  d       y)zBmake sure customised meta options on CMSPlugins don't break thingsone_thing_testpluginmodel3	one_thingN)r#   rH   r   r0  r1  rR  rS  s     r8   "test_meta_options_custom_app_labelz:PluginsMetaOptionsTests.test_meta_options_custom_app_label  sD     ""..0LM//=rD   c                     t         j                  }| j                  |j                  j                  d       | j                  |j                  j
                  d       y)z-make sure custom database table names are OK.or_another_4rQ  N)r$   rH   r   r0  r1  rR  rS  s     r8   !test_meta_options_custom_db_tablez9PluginsMetaOptionsTests.test_meta_options_custom_db_table  sC     ""..?//8rD   c                     t         j                  }| j                  |j                  j                  d       | j                  |j                  j
                  d       y)z>We should be able to customise app_label and db_table togetheror_another_5rZ  N)r%   rH   r   r0  r1  rR  rS  s     r8   test_meta_options_custom_bothz5PluginsMetaOptionsTests.test_meta_options_custom_both  sC     ""..?//=rD   N)	rE   rF   rG   rL  rT  rW  r[  r^  ra  r>   rD   r8   rN  rN    s    B99>9>rD   rN  c                   *    e Zd Zd Zd Zd Zd Zd Zy)NoDatabasePluginTestsc                 @    t        j                  |      j                  S r2   )r   r   rH   )r?   r   s     r8   get_plugin_modelz&NoDatabasePluginTests.get_plugin_model  s    %%k2888rD   c                     | j                  d      }| j                  d      }| j                  t        |j                        t        |j                               y )Nr   r   )re  assertNotEqualr   _render_metar?   r   links      r8   test_render_meta_is_uniquez0NoDatabasePluginTests.test_render_meta_is_unique  sH    $$\2$$\2Bt0012d6G6G3HIrD   c                    | j                  d      }| j                  d      }d|j                  _        d|j                  _        | j                  |j                  j                         | j                  |j                  j                         d|j                  _        | j                  |j                  j                         | j	                  |j                  j                         y )Nr   r   FT)re  rh  text_enabledrm  r]  ri  s      r8   test_render_meta_does_not_leakz4NoDatabasePluginTests.test_render_meta_does_not_leak  s    $$\2$$\2).&).&**778**778)-&**778))667rD   c                 \    ddl m} | j                  |j                  j                  d       y )Nr   )TestPlugin1bunch_of_plugins_testplugin1).cms.test_utils.project.bunch_of_plugins.modelsrp  r   r0  r1  )r?   rp  s     r8   test_db_table_hackz(NoDatabasePluginTests.test_db_table_hack  "    N**335STrD   c                 \    ddl m} | j                  |j                  j                  d       y )Nr   )r"   bunch_of_plugins_testplugin2)rr  r"   r   r0  r1  )r?   r"   s     r8   test_db_table_hack_with_mixinz3NoDatabasePluginTests.test_db_table_hack_with_mixin  rt  rD   N)rE   rF   rG   re  rk  rn  rs  rw  r>   rD   r8   rc  rc    s    9J
8UUrD   rc  c                       e Zd Zd Zd Zy)SimplePluginTestsc                 Z     G d dt               }| j                  |j                  d       y )Nc                       e Zd ZdZy)6SimplePluginTests.test_simple_naming.<locals>.MyPlugin	base.htmlNrE   rF   rG   rJ   r>   rD   r8   MyPluginr|        )OrD   r  z	My Plugin)r   r   rI   )r?   r  s     r8   test_simple_namingz$SimplePluginTests.test_simple_naming  s$    	*} 	* 	4rD   c                      G d dt               } |t        t        j                        }i }|j	                  |dd      }| j                  |d   d       | j                  |d   d       | j                  ||       y )Nc                       e Zd ZdZy)7SimplePluginTests.test_simple_context.<locals>.MyPluginr}  Nr~  r>   rD   r8   r  r    r  rD   r  r_   r   rA   rB   )r   r   r   rV   rC   r   assertIs)r?   r  r7   r@   out_contexts        r8   test_simple_contextz%SimplePluginTests.test_simple_context  sp    	*} 	* ,ejj9mmGQ2Z0!4]3Q7k7+rD   N)rE   rF   rG   r  r  r>   rD   r8   ry  ry    s    5	,rD   ry  c                       e Zd Zd Zy)BrokenPluginTestsc                     dg}| j                  |      5  dt        _        | j                  t        t        j
                         ddd       y# 1 sw Y   yxY w)z
        If there is an import error in the actual cms_plugin file it should
        raise the ImportError rather than silently swallowing it -
        in opposition to the ImportError if the file 'cms_plugins.py' doesn't
        exist.
        z&cms.test_utils.project.brokenpluginapp)INSTALLED_APPSFN)r   r   
discoveredr   ImportErrordiscover_plugins)r?   new_appss     r8   test_import_broken_pluginz+BrokenPluginTests.test_import_broken_plugin  sQ     ==]](]3 	I%*K"k;+G+GH	I 	I 	Is   0AAN)rE   rF   rG   r  r>   rD   r8   r  r    s    
IrD   r  c                       e Zd Zd Zd Zy)MTIPluginsTestCasec                    ddl m} 	 t        ddt        j                  d   d         }|j                  t        j                  d   d         j                  d      }| j                  |dt        j                  d   d         }d	d
d}| j                  j                  ||      }| j                  |j                  d       | j                  |j                  j                         d       |j                  j                         d   }| j                  d	|j                         | j                  d
|j                          y )Nr   )TestPluginBetaModelTestr  r   r~   TestPluginBetar   ALPHABETA)alphabetar   r_   )+cms.test_utils.project.mti_pluginapp.modelsr  r   r   rb   r   r   r   r   r   r   r   r   r$  r!  r  r  )r?   r  r   rB   r   r   r{   plugin_models           r8   r   z'MTIPluginsTestCase.test_add_edit_plugin  s'   S	
 6#8(:L:LQ:OPQ:RS++H,>,>q,A!,DEIIvIV ))#(''*1- * 
 !&1;;##GT2--s3,44::<a@*22668;,"4"45!2!23rD   c                    ddl m}m}m}m}m}m}m}m}m	}	 | j                  |j                  j                  j                  j                  d       | j                  |j                  j                  j                  j                  d       | j                  |j                  j                  j                  j                  d       | j                  |j                  j                  j                  j                  d       | j                  |j                  j                  j                  j                  d       | j                  |	j                  j                  j                  j                  d       | j                  |j                  j                  j                  j                  d       | j                  |j                  j                  j                  j                  d       | j                  t!        |d             y )	Nr   )	AbstractPluginParentLessMixedPluginMixedPluginNonPluginModelProxiedAlphaPluginModelProxiedBetaPluginModelTestPluginAlphaModelr  TestPluginGammaModel"mti_pluginapp_testpluginalphamodelz%(app_label)s_%(class)s"mti_pluginapp_testplugingammamodelmti_pluginapp_mixedpluginmti_pluginapp_lessmixedpluginrz  )r  r  r  r  r  r  r  r  r  r  r   rz  fieldremote_fieldrelated_namerm  hasattr)
r?   r  r  r  r  r  r  r  r  r  s
             r8   test_related_namez$MTIPluginsTestCase.test_related_name!  s   
	
 
	
 
	
 	 ..44AANNPt	
 	--33@@MMOs	
 	#1177DDQQSw	
 	"0066CCPPRv	
 	-;;AANN[[]vw ..44AANNPt	
 	2288EERRTop 	))//<<IIKj	
 	ABrD   N)rE   rF   rG   r   r  r>   rD   r8   r  r    s    44(CrD   r  c                       e Zd Zd Zy)UserInputValidationPluginTestc                    d}| j                         }t        dd|      }|j                  |      j                  d      }| j	                  |d|      }| j                  |      5  | j                  j                  |      }d d d        | j                  j                  d	       | j                  d
|j                  j                  d             y # 1 sw Y   QxY w)Nr   z
error pager  r  r   r~   z1TextPlugin"><script>alert("hello world")</script>r   rV  zOTextPlugin&quot;&gt;&lt;script&gt;alert(&quot;hello world&quot;)&lt;/script&gt;zutf-8)r   r   r   r   r   re   r   r   r   rt  rx   ry   )r?   r   r   r   rB   r   r{   s          r8   test_error_response_escapesz9UserInputValidationPluginTest.test_error_response_escapesM  s    &&(	<)>R++H599v9F))%Xck * 
 $$Y/ 	0{{w/H	0 	--s3]##G,	
		0 	0s   'CCN)rE   rF   rG   r  r>   rD   r8   r  r  L  s    
rD   r  )_r  r{  r  
contextlibr   unittestr   djangor   django.confr   django.contribr   django.contrib.admin.widgetsr   r	   django.core.exceptionsr
   django.forms.widgetsr   django.test.testcasesr   django.urlsr   r   django.utilsr   django.utils.encodingr   django.utils.translationr   r  djangocms_text_ckeditor.modelsr   cmsr   cms.apir   cms.exceptionsr   r   r   
cms.modelsr   r   cms.models.pluginmodelr   cms.plugin_baser   cms.plugin_poolr   cms.sitemaps.cms_sitemapr   >cms.test_utils.project.pluginapp.plugins.manytomany_rel.modelsr   r   r    9cms.test_utils.project.pluginapp.plugins.meta.cms_pluginsr!   r"   r#   r$   r%   ?cms.test_utils.project.pluginapp.plugins.validation.cms_pluginsr&   r'   r(   r)   cms.test_utils.testcasesr*   $cms.test_utils.util.context_managersr+   cms.toolbar.toolbarr,   cms.toolbar.utilsr-   cms.utils.compatr.   r  r/   r0   r9   r;   rN   r3   r[   r   r  rC  rN  rc  ry  r  r  r  r>   rD   r8   <module>r     sS      %       Z 7 & * ( ! + ? /   d d ( , ) ' / o o   1 J * 1 ' F 2 2 

 1 

   5 67+ 78Fj) FjRy.2 y.xZ"5 Z$.>h .>b"UH "UJ, ,&I ICC, CCL
$7 
rD   