o
    h+                    @   sR  d dl mZ d dlmZmZ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mZ d d
l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!m"Z" d dl#m$Z$ d dl%m&Z&m'Z' d dl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 d dl9m:Z: d dl;m<Z<m=Z=m>Z> d dl?m@Z@ d dlAmBZB d dlCmDZD d dlEmFZF d dlGmHZHmIZImJZJmKZK d dlLmMZM d dlNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZ d dl[m\Z\ G dd deZ]dd Z^G d d! d!eZ_G d"d# d#eZ`G d$d% d%e\eZaG d&d' d'e\eZbG d(d) d)eZcG d*d+ d+eZdG d,d- d-eZeG d.d/ d/eZfG d0d1 d1eZgG d2d3 d3eZhG d4d5 d5e\eZiG d6d7 d7e\eZjG d8d9 d9eZkG d:d; d;eZlG d<d= d=e\eZmG d>d? d?e\eZnG d@dA dAe\eZoG dBdC dCeZpG dDdE dEe\eZqG dFdG dGe\eZrdHS )I    )Mapping)datedatetimetimezonewraps)AnyOptional)mock)forms)settings)get_user_model)AnonymousUser
Permission)checks)FieldDoesNotExistImproperlyConfigured)RequestFactoryTestCaseoverride_settings)reverse)escapejson_script)freeze_time)WagtailAdminModelFormWagtailAdminPageForm)CommentPanel
FieldPanelFieldRowPanel	HelpPanelInlinePanelMultiFieldPanelMultipleChooserPanel
ObjectListPageChooserPanelPanelPublishingPanelTabbedInterfaceTitleFieldPanelexpand_panel_list*extract_panel_definitions_from_model_classget_form_for_model)DraftailRichTextArea)AdminAutoHeightTextInputAdminDateInputAdminPageChooser)FormSubmission)FormSubmissionsPanel)get_dummy_request)get_image_model)CommentCommentReplyPageSite)ValidatedPageForm)Advert	EventPageEventPageChooserModelEventPageSpeakerFormPageWithRedirectGalleryPagePageChooserModel
PersonPageRestaurantPageRestaurantTag
SimplePageValidatedPage)WagtailTestUtilsc                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )TestGetFormForModelc                 C   s@   t  }| td |  W d    d S 1 sw   Y  d S )Nz]ObjectList is not bound to a model yet. Use `.bind_to_model(model)` before using this method.)r#   assertRaisesMessageAttributeErrorget_form_class)selfedit_handler rL   f/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/admin/tests/test_edit_handlers.pytest_get_form_without_modelC   s   
"z/TestGetFormForModel.test_get_form_without_modelc                 C   sB   t ttd}| t|t | }| d|j | d|j d S )N)
form_classtitlepath)r+   r:   r   
assertTrue
issubclassassertNotInfieldsrJ   EventPageFormformrL   rL   rM   /test_get_form_for_model_without_explicit_fieldsL   s   zCTestGetFormForModel.test_get_form_for_model_without_explicit_fieldsc                 C   s   t ttg dd}| }| t|t | t|jd t	j
 | t|jd t	j | t|jd jt | d|j d S )NrP   slug	date_fromdate_torO   rU   rP   r\   rQ   )r+   r:   r   rR   rS   r   assertEqualtyperU   r   	CharField	DateFieldwidgetr.   rT   rV   rL   rL   rM   (test_get_form_for_model_without_formsetsX   s   z<TestGetFormForModel.test_get_form_for_model_without_formsetsc                 C   s>   t ttg dddgd}| }| d|j | d|j d S )NrZ   speakersrelated_linksrO   rU   formsets)r+   r:   r   assertInrh   rV   rL   rL   rM   %test_get_form_for_model_with_formsetsl   s   z9TestGetFormForModel.test_get_form_for_model_with_formsetsc                 C   st   t ttg dd}| t|t | }| t|jd jt	 t t
tg dd}| }| t|jd jt d S )N)rP   r[   contentr^   rk   )rP   r[   bodyrl   )r+   rC   r   rR   rS   r_   r`   rU   rc   r-   r:   r,   )rJ   SimplePageFormsimple_formrW   
event_formrL   rL   rM    test_direct_form_field_overridesy   s   
z4TestGetFormForModel.test_direct_form_field_overridesc                 C   sx   t ttdgdgd}| }| t|jd tj | t|jd jt	 | 
d|j | d|j | 
d|j d S )Nr\   re   rg   rP   rf   r+   r:   r   r_   r`   rU   r   rb   rc   r.   rT   ri   rh   rV   rL   rL   rM   ,test_get_form_for_model_with_specific_fields      z@TestGetFormForModel.test_get_form_for_model_with_specific_fieldsc                 C   s6   t ttdgd}| }| d|j | d|j d S )Nr\   r^   re   rf   )r+   r:   r   rT   rh   rV   rL   rL   rM   1test_get_form_for_model_without_explicit_formsets   s   zETestGetFormForModel.test_get_form_for_model_without_explicit_formsetsc                 C   sx   t ttdgdgd}| }| t|jd tj | t|jd jt	 | 
d|j | d|j | 
d|j d S )NrP   rf   )rO   excludeexclude_formsetsr\   re   rq   rV   rL   rL   rM   ,test_get_form_for_model_with_excluded_fields   rs   z@TestGetFormForModel.test_get_form_for_model_with_excluded_fieldsc                 C   sV   t ttddgdtjid}| }| t|jd tj | t|jd j	tj d S Nr]   r\   )rO   rU   widgets
r+   r:   r   r   PasswordInputr_   r`   rU   rb   rc   rV   rL   rL   rM   6test_get_form_for_model_with_widget_overrides_by_class   s   zJTestGetFormForModel.test_get_form_for_model_with_widget_overrides_by_classc                 C   sX   t ttddgdt id}| }| t|jd tj | t|jd j	tj d S rx   rz   rV   rL   rL   rM   9test_get_form_for_model_with_widget_overrides_by_instance   s   
zMTestGetFormForModel.test_get_form_for_model_with_widget_overrides_by_instancec                 C   s   t ttg dd}|  }| d| | td| tjjddd tjjdd	d |d
ddd}| 	|
  | |jd dg d S )N)rP   r[   tagsr^   zCdata-w-tag-url-value="/admin/tag-autocomplete/tests/restauranttag/"z"autocompleteOnly": trueItalianitalian)namer[   Indianindian	Buonasera	buonaserazItalian, deliciousr~   )r+   rA   r   as_pri   r   rB   objectscreaterR   is_validr_   cleaned_data)rJ   RestaurantPageForm	form_htmlrX   rL   rL   rM   #test_tag_widget_is_passed_tag_model   s*   
z7TestGetFormForModel.test_tag_widget_is_passed_tag_modelN)__name__
__module____qualname__rN   rY   rd   rj   rp   rr   rt   rw   r|   r}   r   rL   rL   rL   rM   rF   B   s    	rF   c                    s    fdd}|S )Nc                    s   t   fdd}|S )Nc                     s6   j   z | i | W j   d S j   w N)get_edit_handlercache_clear)argskwargs)fnpage_clsrL   rM   	decorated   s   
z8clear_edit_handler.<locals>.decorator.<locals>.decoratedr   )r   r   r   )r   rM   	decorator   s   	z%clear_edit_handler.<locals>.decoratorrL   )r   r   rL   r   rM   clear_edit_handler   s   r   c                   @   s\   e Zd Zeedd Zeedd Zeedd Zeedd Z	eed	d
 Z
dS )TestPageEditHandlersc                 C   $   t  }| }| t|t dS )zS
        Forms for pages should have a base class of WagtailAdminPageForm.
        N)r:   r   rI   rR   rS   r   )rJ   rK   rW   rL   rL   rM   test_get_edit_handler  s   z*TestPageEditHandlers.test_get_edit_handlerc                 C   r   )z
        ValidatedPage sets a custom base_form_class. This should be used as the
        base class when constructing a form for ValidatedPages
        N)rD   r   rI   rR   rS   r8   )rJ   rK   GeneratedValidatedPageFormrL   rL   rM   'test_get_form_for_page_with_custom_base  s   z<TestPageEditHandlers.test_get_form_for_page_with_custom_basec                 C   s   G dd d}t jddtdd}t jddtd	d}tjjtd
|d$ t  }dd |D }|jdd d | |||g W d    d S 1 sIw   Y  d S )Nc                   @   s   e Zd ZdS )zMTestPageEditHandlers.test_check_invalid_base_form_class.<locals>.BadFormClassN)r   r   r   rL   rL   rL   rM   BadFormClass&  s    r   zBValidatedPage.base_form_class does not extend WagtailAdminPageFormz\Ensure that wagtail.admin.tests.test_edit_handlers.BadFormClass extends WagtailAdminPageFormzwagtailadmin.E001hintobjidzVValidatedPage.get_edit_handler().get_form_class() does not extend WagtailAdminPageFormz]Ensure that the panel definition for ValidatedPage creates a subclass of WagtailAdminPageFormzwagtailadmin.E002base_form_class)newc                 S   s   g | ]
}|j tjkr|qS rL   )levelr   ERROR).0erL   rL   rM   
<listcomp>;  s    zKTestPageEditHandlers.test_check_invalid_base_form_class.<locals>.<listcomp>c                 S   s   | j S r   r   )r   rL   rL   rM   <lambda>>  s    zITestPageEditHandlers.test_check_invalid_base_form_class.<locals>.<lambda>)key)	r   ErrorrD   r
   patchobject
run_checkssortr_   )rJ   r   invalid_base_forminvalid_edit_handlererrorsrL   rL   rM   "test_check_invalid_base_form_class$  s&   "z7TestPageEditHandlers.test_check_invalid_base_form_classc                 C   st   t  t_tjjtdt  dd! t  }| t	|t
 t }| |g  W d   dS 1 s3w   Y  dS )z
        Set a custom edit handler on a Page class, but dont customise
        ValidatedPage.base_form_class, or provide a custom form class for the
        edit handler. Check the generated form class is of the correct type.
        rK   T)r   r   N)r'   rD   rK   r
   r   r   r   rI   rR   rS   r   checkr_   )rJ   rO   r   rL   rL   rM   #test_custom_edit_handler_form_classB  s   
"z8TestPageEditHandlers.test_custom_edit_handler_form_classc                 C   sh   t  }t|}| d| |jd d d d}t|}| d| | d| | d| | d| d S )Nz9model=<class 'wagtail.test.testapp.models.ValidatedPage'>)instancerequestrX   zinstance=Nonezrequest=Nonez	form=None)rD   r   reprri   get_bound_panel)rJ   rK   handler_reprbound_handlerbound_handler_reprrL   rL   rM   	test_reprR  s"   zTestPageEditHandlers.test_reprN)r   r   r   r   r:   r   rD   r   r   r   r   rL   rL   rL   rM   r     s    




r   c                   @   $   e Zd Zdd Zdd Zdd ZdS ))TestExtractPanelDefinitionsFromModelClassc                 C   s4   t t}| t|d | tdd |D  d S )N   c                 s       | ]}t |tV  qd S r   )
isinstancer!   r   panelrL   rL   rM   	<genexpr>p  s    z\TestExtractPanelDefinitionsFromModelClass.test_can_extract_panel_property.<locals>.<genexpr>)r*   r<   r_   lenrR   anyrJ   resultrL   rL   rM   test_can_extract_panel_propertyl  s   zITestExtractPanelDefinitionsFromModelClass.test_can_extract_panel_propertyc                 C   s*   t tdgd}|D ]	}| |jd q	d S )Nhostname)ru   )r*   r7   assertNotEqual
field_name)rJ   panelsr   rL   rL   rM   test_excluder  s   z6TestExtractPanelDefinitionsFromModelClass.test_excludec                 C   s$   t t}| tdd |D  d S )Nc                 s   s$    | ]}t |to|jd kV  qdS )r\   N)r   r   r   r   rL   rL   rM   r   |  s
    
zVTestExtractPanelDefinitionsFromModelClass.test_can_build_panel_list.<locals>.<genexpr>)r*   r:   rR   r   )rJ   r   rL   rL   rM   test_can_build_panel_listw  s   zCTestExtractPanelDefinitionsFromModelClass.test_can_build_panel_listN)r   r   r   r   r   r   rL   rL   rL   rM   r   k  s    r   c                   @      e Zd Zdd Zdd ZdS )TestPanelAttributesc                 C   s   t  d| _| jdd}|| j_|  | _tttdddidt	dt
jd	tt	d
t	dddidgddidgddddidttddddidgddtttdddidt	dtt	dt	dddidgddidgddidgddgddidt| _d S )N/adminusernamez)Double-check event details before submit.zdata-panel-typehelpattrsrP   rc   r\   r]   fieldz	field-rowEvent detailsshinyzobject-listheading	classnamer   re   Speakersinline)labelr   r   z(Double-check cost details before submit.z	help-costcostz.nested-object_list-multi_field-field_row-fieldz(nested-object_list-multi_field-field_rowzmulti-fieldSecrettabs)r   getr   create_superuseruserloginr'   r#   r   r   r   Textarear   r    r!   bind_to_modelr:   event_page_tabbed_interfacerJ   r   rL   rL   rM   setUp  s|   


>@zTestPanelAttributes.setUpc                 C   s   | j  }tdd}||d}| j j||| jd}| }| |dd | |dd | |dd | |d	d | |d
d | |dd | |dd | |dd | |dd | |dd d S )NAbergavenny sheepdog trialsrP   r   r   rX   r   zdata-panel-type="tabs"   zdata-panel-type="multi-field"z:data-panel-type="nested-object_list-multi_field-field_row"z@data-panel-type="nested-object_list-multi_field-field_row-field"zdata-panel-type="help-cost"zdata-panel-type="inline"zdata-panel-type="object-list"zdata-panel-type="field-row"zdata-panel-type="field"zdata-panel-type="help")r   rI   r:   r   r   render_htmlr_   countrJ   rW   eventrX   tabbed_interfacer   rL   rL   rM   test_render  s6   


zTestPanelAttributes.test_renderN)r   r   r   r   r   rL   rL   rL   rM   r     s    Ir   c                   @   <   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestTabbedInterfacec              
   C   s   t  d| _| jdd}|| j_|  | _| jddd| _tj	jdd}| jj
| tttd	tjd
tdtdgdddttdddgddttdddgddttdgdddttdgdddgddidt| _d S ) Nr   r   r   admin2ztest2@email.com)r   emailcustom_see_panel_setting)codenamerP   r   r\   r]   r   r   )r   r   re   r   r   r   r   	superuser)
permissionr   ztests.custom_see_panel_settingzCustom Setting)r	  r   z$tests.other_custom_see_panel_settingzOther Custom Settingdata-controllerzmy-tabbed-interfacer   )r   r   r   r   r   r   create_user
other_userr   r   user_permissionsaddr'   r#   r   r   r   r    r   r:   r   )rJ   r   prL   rL   rM   r     sV   
	

%'zTestTabbedInterface.setUpc                 C   <   | j  }| }| d|j | t|jd jtj	 d S Nre   rP   )
r   rI   ri   rh   r_   r`   rU   rc   r   r   rV   rL   rL   rM   test_get_form_class#     
z'TestTabbedInterface.test_get_form_classc                 C   s   | j  }tdd}||d}| j j||| jd}| }| d| | d| | d| | d| | d	| | d
| | d| d S )Nr   r   r   r   <a id="tab-label-event_details" href="#tab-event_details" class="w-tabs__tab shiny" role="tab" aria-selected="false" tabindex="-1">t<a id="tab-label-speakers" href="#tab-speakers" class="w-tabs__tab " role="tab" aria-selected="false" tabindex="-1">z)aria-labelledby="tab-label-event_details"z$aria-labelledby="tab-label-speakers"&Abergavenny sheepdog trials</textarea>z%data-controller="my-tabbed-interface"signup_link)r   rI   r:   r   r   r   ri   rT   r   rL   rL   rM   r   -  s,   


zTestTabbedInterface.test_renderc                 C   s&   t | j d }| |h d d S )NrU   >   r   rP   r]   r\   )setr   get_form_optionsr_   r   rL   rL   rM   test_required_fieldsQ  s   z(TestTabbedInterface.test_required_fieldsc                 C   sV   | j  }tdd}||d}| j j||| jd}| }| d| | d| d S )Nr   r   r   r   r  r  )r   rI   r:   r   r   render_form_contentri   rT   r   rL   rL   rM   test_render_form_contentV  s   


z,TestTabbedInterface.test_render_form_contentc                 C   s  | j  }tdd}||d}| d4 | j j||| jd}| }| d| | d| | d| | d	| | d
| W d   n1 sKw   Y  | d: 	 | j| j_	| j j||| jd}| }| d| | d| | 
d| | d	| | 
d| W d   n1 sw   Y  | d< t }|| j_	| j j||| jd}| }| d| | d| | 
d| | 
d	| | 
d| W d   dS 1 sw   Y  dS )z
        test that three tabs show when the current user has permission to see all three
        test that two tabs show when the current user does not have permission to see all three
        r   r   r   zSuper user testr   r  r  z,<a id="tab-label-secret" href="#tab-secret" z<<a id="tab-label-custom_setting" href="#tab-custom_setting" zH<a id="tab-label-other_custom_setting" href="#tab-other_custom_setting" NzNot superuser permissionszH<a id="tab-label-other_custom_setting" href="#tab-other-custom_setting" zNon superuser)r   rI   r:   subTestr   r   r   ri   r  r   rT   r   )rJ   rW   r   rX   r   r   r   rL   rL   rM   test_tabs_permissionsh  s   



""z)TestTabbedInterface.test_tabs_permissionsN)	r   r   r   r   r  r   r  r  r  rL   rL   rL   rM   r    s    2
$r  c                   @   r   )TestObjectListc                 C   s^   t  d| _t }|| j_ttdtjdtdtdt	dddgd	d
ddid
t| _d S )Nr   rP   r   r\   r]   re   r   r  r   r   r
  zmy-object-listr   )r   r   r   r   r   r#   r   r   r   r    r   r:   event_page_object_listr   rL   rL   rM   r     s   

zTestObjectList.setUpc                 C   r  r  )
r   rI   ri   rh   r_   r`   rU   rc   r   r   rV   rL   rL   rM   r    r  z"TestObjectList.test_get_form_classc                 C   s   | j  }tdd}||d}| j j||| jd}| }| d| | d| | d| | d| | d	| | d
| d S )Nr   r   r   r   z<div class="w-panel__header">z data-controller="my-object-list"z2<label for="id_date_from" id="id_date_from-label">z@<div class="help">Not required if event is on a single day</div>r  r  )	r   rI   r:   r   r   r   ri   assertInHTMLrT   )rJ   rW   r   rX   object_listr   rL   rL   rM   r     s*   


zTestObjectList.test_renderN)r   r   r   r   r  r   rL   rL   rL   rM   r    s    
r  c                       s4   e Zd Z fddZdd Zdd Zdd Z  ZS )	TestFormatValueForDisplayc                    s8   t    t | _tdtdddtddddd| _d S )Nr              publicrP   r\   r]   audience)superr   r%   r   r:   r   r   rJ   	__class__rL   rM   r     s   


zTestFormatValueForDisplay.setUpc                 C   $   | j | jj}| || jj d S r   )r   format_value_for_displayr   rP   assertIsr   rL   rL   rM   test_charfield_return_value      z5TestFormatValueForDisplay.test_charfield_return_valuec                 C   r/  r   )r   r0  r   r\   r1  r   rL   rL   rM   test_datefield_return_value$  r3  z5TestFormatValueForDisplay.test_datefield_return_valuec                 C   s"   | j tj }| |d d S )Nz'Root, Welcome to your new Wagtail site!)r   r0  r6   r   allr_   r   rL   rL   rM   test_queryset_return_value(  s   z4TestFormatValueForDisplay.test_queryset_return_value)r   r   r   r   r2  r4  r6  __classcell__rL   rL   r-  rM   r#    s
    
r#  c                   @   s   e Zd Zdd Z		d%deeeef  deee  de	fddZ
	d&d	ed
e	dejfddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ ZdS )'TestFieldPanelc                 C   s   t  d| _t }|| j_tdtdddtddddd| _td	d
d	t| _
td	dd	t| _tddd	t| _tddd	t| _dddd| _d S )Nr   r   r$  r%  r&  r'  r(  r)  r]   
full-widthr   T	read_onlyr*  
feed_imagePontypridd sheepdog trialsz
2014-06-01z
2014-06-02rP   r\   r]   )r   r   r   r   r   r:   r   r   r   r   end_date_panelread_only_end_date_panelread_only_audience_panelread_only_image_panelpontypridd_event_datar   rL   rL   rM   r   .  sB   

zTestFieldPanel.setUpNdatarU   returnc                 C   s.   t tt|d ur	|ng dg d}||| jdS )NrP   r[   r]   rg   )rE  r   )r+   r:   r   r   )rJ   rE  rU   clsrL   rL   rM   	_get_formP  s   zTestFieldPanel._get_formr   rX   c                 C   s,   |j s|t}|j|p|  | j| jdS )N)rX   r   r   )modelr   r:   r   rI  r   r   )rJ   r   rX   rL   rL   rM   _get_bound_panel]  s   

zTestFieldPanel._get_bound_panelc                 C   sD   t dt}| t |j W d    d S 1 sw   Y  d S )Nbarbecue)r   r   r6   assertRaisesr   db_field)rJ   field_panelrL   rL   rM   test_non_model_fieldh  s   "z#TestFieldPanel.test_non_model_fieldc                 C   s0   | j }| }| d| | |d dg d S NrU   r]   )r@  r  ri   r_   rJ   r   r   rL   rL   rM   3test_get_form_options_includes_non_read_only_fieldsq  s   zBTestFieldPanel.test_get_form_options_includes_non_read_only_fieldsc                 C   s   | j }| }| d| d S )NrU   )rA  r  rT   rR  rL   rL   rM   7test_get_form_options_does_not_include_read_only_fieldsw  s   zFTestFieldPanel.test_get_form_options_does_not_include_read_only_fieldsc              	   C   s   | j ddgd}dD ]4\}}}t||d}| j||d}| | d|  | | | W d    n1 s9w   Y  q
d S )Nrl   rP   )rU   ))rP   TT)rl   TTr;  rX   z, read_only=)rI  r   rK  r  r1  is_shown)rJ   rX   r   make_read_onlyexpected_valuer   bound_panelrL   rL   rM   test_boundpanel_is_shown|  s   z'TestFieldPanel.test_boundpanel_is_shownc                 C   sT   |  | j}| |j|jj |  tdddd}| |jd | |jjd d S )Nr]   r9  zNew headingr   r   )rK  r@  r_   r   bound_fieldr   r   )rJ   rY  rL   rL   rM   test_override_heading  s   z$TestFieldPanel.test_override_headingc              	   C   s   d t | jjf| j| jd ffD ]W\}}| j|g dd}|  | j| j|d}| }| 	d| * | 
d| | 
d| d| | 
d	| | 
d
| | d| W d    n1 sbw   Y  qd S )Nr]   rG  rE  rU   rU  form data = <inputzvalue=""zdata-field-wrapper(Not required if event is on a single dayerror-message)strr   r]   rD  rI  r   rK  r@  r   r  ri   rT   )rJ   rE  expected_input_valuerX   rY  r   rL   rL   rM   test_render_html  s    zTestFieldPanel.test_render_htmlc              	   C   s   | j jd}| jd f| j| jffD ]F\}}| j|ddgd}|  | j||d}| d|  |	 }| 
d| | || | d| W d    n1 sSw   Y  qd S )	Nz
%B %-d, %YrP   r[   r^  rU  r_  r`  rb  )r   r]   strftimerA  rD  rI  r   rK  r  r   rT   ri   )rJ   expected_value_outputr   rE  rX   rY  r   rL   rL   rM   test_render_html_when_read_only  s"   z.TestFieldPanel.test_render_html_when_read_onlyc                 C   s    | j | jj}| |d d S )NPublic)rB  r0  r   r*  r_   r   rL   rL   rM   .test_format_value_for_display_with_choicefield  s   z=TestFieldPanel.test_format_value_for_display_with_choicefieldc                 C   sP   t  dd}| d | | j|| W d   dS 1 s!w   Y  dS )aV  
        `ForeignKey.formfield()` returns a `ModelChoiceField`, which returns a
        `ModelChoiceIterator` instance when it's `choices` property is
        accessed. This test is to show that `format_value_for_display()` avoids
        evaluating `ModelChoiceIterator` instances, and the database query
        that would trigger.
        Titler   r   N)r3   assertNumQueriesr_   rC  r0  )rJ   imagerL   rL   rM   3test_format_value_for_display_with_modelchoicefield  s   
"zBTestFieldPanel.test_format_value_for_display_with_modelchoicefieldc                 C   s    | j  d }| |dg d S rQ  )r@  r  r_   r   rL   rL   rM   r    s   z#TestFieldPanel.test_required_fieldsc                 C   sB   | j ddddd}|  | | j|}| }| d| d S )Nr>  
2014-07-20
2014-07-33r?  )rE  Enter a valid date.)rI  r   rK  r@  r   ri   )rJ   rX   rY  r   rL   rL   rM   test_error_message_is_rendered  s   z-TestFieldPanel.test_error_message_is_renderedc                 C   sH   |  | j}t|}| d| | d| | d| | d| d S )Nz5model=<class 'wagtail.test.testapp.models.EventPage'>z$instance=Abergavenny sheepdog trialszrequest=<WSGIRequest: GET '/'>zform=EventPageForm)rK  r@  r   ri   )rJ   rY  field_panel_reprrL   rL   rM   r     s   zTestFieldPanel.test_repr)NNr   )r   r   r   r   r	   r   rd  r   listr   rI  r   
BoundPanelrK  rP  rS  rT  rZ  r]  rf  ri  rk  ro  r  rs  r   rL   rL   rL   rM   r8  -  s>    $


	r8  c                   @   r   )TestFieldRowPanelc                 C   s   t  d| _t }|| j_tttg dg d| _tdt	dddt	dddd	| _
ttd
dddtdddgddt| _d S )Nr   rZ   rg   r   r$  r%  r&  r'  r?  r\   col4Startr[  r]   coltwor:  Confirmed event dates only)	help_textr   r   r   r   r   r+   r:   r   rW   r   r   r   r   r   dates_panelr   rL   rL   rM   r     s,   


zTestFieldRowPanel.setUpc                 C   s~   | j dddd| jd}|  | jj| j|| jd}| }| d| | d| | d	| | d
| | d| d S )Nr>  rp  
2014-07-22r?  r   r   zE<label class="w-field__label" for="id_date_to" id="id_date_to-label">rb  r{  zvalue="2014-07-22"rc  	rW   r   r   r~  r   r   r   ri   rT   rJ   rX   rO  r   rL   rL   rM   rf    s,   	z"TestFieldRowPanel.test_render_htmlc                 C   sN   | j dddd| jd}|  | jj| j|| jd}| }| d| d S )Nr>  rp  rq  r?  r   r   rr  )rW   r   r   r~  r   r   r   ri   r  rL   rL   rM   rs  ?  s   	z0TestFieldRowPanel.test_error_message_is_renderedN)r   r   r   r   rf  rs  rL   rL   rL   rM   rw     s    %rw  c                   @   r   )TestFieldRowPanelWithChooserc                 C   sr   t  d| _t }|| j_tttg dg d| _tdt	dddt	dddd	| _
ttd
tdgt| _d S )Nr   rZ   rg   r   r$  r%     r'  r?  r\   r=  r}  r   rL   rL   rM   r   V  s*   

z"TestFieldRowPanelWithChooser.setUpc                 C   sZ   | j dddd| jd}|  | jj| j|| jd}| }| d| | d| d S )	Nr>  rp  r  r?  r   r   zvalue="2014-07-20"rc  r  r  rL   rL   rM   rf  n  s    	z-TestFieldRowPanelWithChooser.test_render_htmlN)r   r   r   r   rf  rL   rL   rL   rM   r  U  s    r  c                   @   sr   e Zd ZdgZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )TestPageChooserPanel	test.jsonc                 C   s   t  d| _t }|| j_t}ttdgt| _	| j	j
d | _| j	 | _tjjdd| _tjjdd| _|jj| jd| _| j| jd| _| jj| j| j| jd	| _d S )
Nr   pager   	christmasr[   eventsr  r   r   )r   r   r   r   r   r?   r#   r$   r   rK   childrenmy_page_chooser_panelrI   PageChooserFormr6   r   christmas_pageevents_index_pager   test_instancerX   r   page_chooser_panel)rJ   r   rJ  rL   rL   rM   r     s    zTestPageChooserPanel.setUpc                 C   s   |  t| jjd jt d S )Nr  )r_   r`   rX   rU   rc   r/   r,  rL   rL   rM   %test_page_chooser_uses_correct_widget  s   z:TestPageChooserPanel.test_page_chooser_uses_correct_widgetc                 C   s.   | j  }djdd| jjd}| || d S )Nnew PageChooser("{id}", {{"modelNames": ["{model}"], "canChooseRoot": false, "userPerms": null, "modalUrl": "/admin/choose-page/", "parentId": {parent}}});id_pagewagtailcore.pager   rJ  parent)r  r   formatr  r   ri   )rJ   r   expected_jsrL   rL   rM   test_render_js_init  s
   

z(TestPageChooserPanel.test_render_js_initc                 C   sv   t tdddgt}|jd }| }|| jd}|j| j|| jd}|	 }dj
dd	| jjd
}| || d S )Nr  T)can_choose_rootr   r   r   znew PageChooser("{id}", {{"modelNames": ["{model}"], "canChooseRoot": true, "userPerms": null, "modalUrl": "/admin/choose-page/", "parentId": {parent}}});r  r  r  )r#   r$   r   r?   r  rI   r  r   r   r   r  r  r   ri   rJ   my_page_object_listr  r  rX   r  r   r  rL   rL   rM   -test_render_js_init_with_can_choose_root_true  s    


zBTestPageChooserPanel.test_render_js_init_with_can_choose_root_truec                 C   s:   | j  }| d| | d| | d| jj | d S )N!<div class="help">help text</div>zQ<div class="chooser__title" data-chooser-title id="id_page-title">Christmas</div>zW<a data-chooser-edit-link href="/admin/pages/%d/edit/" aria-describedby="id_page-title")r  r   ri   r  r   r   rL   rL   rM   rf    s   
z%TestPageChooserPanel.test_render_htmlc                 C   sV   t  }| j|d}| jj||| jd}| }| d| | d| | d| d S )Nr   r   r  zH<div class="chooser__title" data-chooser-title id="id_page-title"></div>zChoose a page)r?   r  r  r   r   r   ri   )rJ   r  rX   r  r   rL   rL   rM   test_render_as_empty_field  s   z/TestPageChooserPanel.test_render_as_empty_fieldc                 C   sL   | j ddi| jd}| |  | jj| j|| jd}| d|  d S )Nr   r   r   rc  )	r  r  assertFalser   r  r   r   ri   r   )rJ   rX   r  rL   rL   rM   test_render_error  s   
z&TestPageChooserPanel.test_render_errorc                 C   st   t tddgt}|jd }| }|| jd}|j| j|| jd}|	 }dj
dd| jjd	}| || d S )
Nr  ztests.EventPager   r   r   r  r  tests.eventpager  r#   r$   r   r;   r  rI   r  r   r   r   r  r  r   ri   r  rL   rL   rM   test_override_page_type  s    



z,TestPageChooserPanel.test_override_page_typec                 C   sr   t tdgt}|jd }| }|| jd}|j| j|| jd}|	 }dj
dd| jjd}| || d S )	Nr  r   r   r   r  r  r  r  r  r  rL   rL   rM   test_autodetect_page_type  s   


z.TestPageChooserPanel.test_autodetect_page_typec                 C   s4   t ddt}| d d }| |jtg d S )Nr  zwagtailcore.sitery   )r$   r   r?   r  r_   target_modelsr7   )rJ   r   rc   rL   rL   rM   test_target_models  s
   
z'TestPageChooserPanel.test_target_modelsc                 C   "   t ddt}| t|j d S )Nr  snowmanr$   r   r?   rM  r   r  rJ   r   rL   rL   rM   !test_target_models_malformed_type  s   z6TestPageChooserPanel.test_target_models_malformed_typec                 C   r  )Nr  zsnowman.lorryr  r  rL   rL   rM   #test_target_models_nonexistent_type  s   
z8TestPageChooserPanel.test_target_models_nonexistent_typeN)r   r   r   fixturesr   r  r  r  rf  r  r  r  r  r  r  r  rL   rL   rL   rM   r    s    	r  c                   @   sN   e Zd ZdgZdd Zdd Zdd Zeddd	d
d Zdd Z	dd Z
dS )TestInlinePanelr  c                 C       t  d| _t }|| j_d S Nr   r   r   r   r   r   r   rL   rL   rM   r   '     zTestInlinePanel.setUpc                 C   s  t tdddddidgt}| }| dgt|j  tj	j
dd}||d	}|j||| jd
}| }| d| | d| | d| | d| | d| | jd|dd | jd|dd | jd|dd | jd|dd | d| | d| | d| dS )
        Check that the inline panel renders the panels set on the model
        when no 'panels' parameter is passed in the InlinePanel definition
        re   r   zclassname-for-speakersr
  test)r   r   r   r  r  r   r   a<label class="w-field__label" for="id_speakers-0-first_name" id="id_speakers-0-first_name-label">zvalue="Father"_<label class="w-field__label" for="id_speakers-0-last_name" id="id_speakers-0-last_name-label">W<label class="w-field__label" for="id_speakers-0-image" id="id_speakers-0-image-label">Choose an image@<input id="id_speakers-0-id" name="speakers-0-id" type="hidden">Tallow_extra_attrsH<input id="id_speakers-0-DELETE" name="speakers-0-DELETE" type="hidden">F<input id="id_speakers-0-ORDER" name="speakers-0-ORDER" type="hidden">N<input id="id_speakers-TOTAL_FORMS" name="speakers-TOTAL_FORMS" type="hidden">var panel = new InlinePanel({zdata-contentpath-disabledzdata-controller="test"N)r#   r    r   r:   rI   r_   ru  rh   keysr   r   r   r   r   ri   assertTagInHTML)rJ   speaker_object_listrW   
event_pagerX   r   r   rL   rL   rM   r   ,  sp   	

zTestInlinePanel.test_renderc                 C   s*  t tddtdtjdtdgdgt}|jd }| }| 	dgt
|j  tjjdd	}||d
}|j||| jd}| }| d| | d| | d| | jd|ddd | d| | d| | jd|dd | jd|dd | jd|dd | jd|dd | d|  dS )z
        Check that inline panel renders the panels listed in the InlinePanel definition
        where one is specified
        re   r   
first_namer   rn  r   r   r   r  r  r   r   r  zFather</textarea>r  z$<input id="id_speakers-0-last_name">T)r   r  r  r  r  r  r  r  r  r  N)r#   r    r   r   r   r   r:   r  rI   r_   ru  rh   r  r   r   r   r   r   ri   rT   r  )rJ   r  speaker_inline_panelrW   r  rX   r   r   rL   rL   rM    test_render_with_panel_overrides{  s|   

z0TestInlinePanel.test_render_with_panel_overridesT)USE_L10NUSE_THOUSAND_SEPARATORc                 C   s|   t tddtdtjdtdgdgt}|jd }| }tj	j
dd	}||d
}|j||| jd}| d|  dS )a  
        Test that the USE_THOUSAND_SEPARATOR setting does not screw up the rendering of numbers
        (specifically maxForms=1000) in the JS initializer:
        https://github.com/wagtail/wagtail/pull/2699
        https://github.com/wagtail/wagtail/issues/3227
        re   r   r  r   rn  r  r   r  r  r   r   zmaxForms: 1000N)r#   r    r   r   r   r   r:   r  rI   r   r   r   r   ri   r   )rJ   r  r  rW   r  rX   r   rL   rL   rM   !test_no_thousand_separators_in_js  s(   

z1TestInlinePanel.test_no_thousand_separators_in_jsc                 C   sN   |    | tdd  | tdd  W d    d S 1 s w   Y  d S )Nc                   S   s
   t ddS )Nr   r  )r    rL   rL   rL   rM   r     s   
 zFTestInlinePanel.test_invalid_inlinepanel_declaration.<locals>.<lambda>c                   S   s   t tddddS )Nre   r   chunky)r   bacon)r    r:   rL   rL   rL   rM   r     s    )ignore_deprecation_warningsrM  	TypeErrorr,  rL   rL   rM   $test_invalid_inlinepanel_declaration  s   
"z4TestInlinePanel.test_invalid_inlinepanel_declarationc                 C   s.   t dt}| |jd | |jd d S )Nsocial_linkszSocial linkszSocial link)r    r   r@   r_   r   r   r  rL   rL   rM   %test_get_heading_and_label_from_field  s   z5TestInlinePanel.test_get_heading_and_label_from_fieldN)r   r   r   r  r   r   r  r   r  r  r  rL   rL   rL   rM   r  $  s    O
T

r  c                   @   "   e Zd ZdgZdd Zdd ZdS )TestNonOrderableInlinePanelr  c                 C   s   t  | _t }|| j_d S r   )r2   r   r   r   r   rL   rL   rM   r     s   z!TestNonOrderableInlinePanel.setUpc                 C   sZ   t tdddgt}| }t }||d}|j||| jd}| }| d| dS )r  r  zSocial Linksr  r   r   z%id="id_social_links-__prefix__-ORDER"N)	r#   r    r   r@   rI   r   r   r   assertNotInHTML)rJ   social_link_object_listPersonPageFormperson_pagerX   r   r   rL   rL   rM   r     s(   
z'TestNonOrderableInlinePanel.test_renderN)r   r   r   r  r   r   rL   rL   rL   rM   r        r  c                   @   r  )TestInlinePanelGetComparisonr  c                 C   r  r  r  r   rL   rL   rM   r   &  r  z"TestInlinePanelGetComparison.setUpc                    sX   t jjddj   j | jd } fdd|D }dd |D }| d| d S )N   r   r   r   c                    s   g | ]}|  qS rL   rL   r   compr  rL   rM   r   5  s    zDTestInlinePanelGetComparison.test_get_comparison.<locals>.<listcomp>c                 S      g | ]}|  qS rL   field_labelr  rL   rL   rM   r   6      zSpeaker lineup)	r6   r   r   specificr   r   r   get_comparisonri   rJ   
comparisonfield_labelsrL   r  rM   test_get_comparison+  s   z0TestInlinePanelGetComparison.test_get_comparisonNr   r   r   r  r   r  rL   rL   rL   rM   r  #  r  r  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS ),TestInlinePanelRelatedModelPanelConfigChecksc                 C   s*   t j| _tt d dd }d| _|| _d S )Nr   c                  S   s   t jdgd} dd | D S )Nr   )r~   c                 S   s   g | ]	}|j tkr|qS rL   )r   r<   )r   warningrL   rL   rM   r   B  s    zaTestInlinePanelRelatedModelPanelConfigChecks.setUp.<locals>.get_checks_result.<locals>.<listcomp>)r   r   )checks_resultrL   rL   rM   get_checks_result?  s   zMTestInlinePanelRelatedModelPanelConfigChecks.setUp.<locals>.get_checks_resultzwagtailadmin.W002)r<   r   original_panelsdelattr
warning_idr  )rJ   r  rL   rL   rM   r   ;  s
   

z2TestInlinePanelRelatedModelPanelConfigChecks.setUpc                 C   s   | j t_d S r   )r  r<   r   r,  rL   rL   rM   tearDownI  s   z5TestInlinePanelRelatedModelPanelConfigChecks.tearDownc                 C   sH   t dt dgt_tjddt| jd}|  }| || ttd dS )zSTest that checks will warn against setting single tabbed panel on InlinePanel modelr  	last_namezQEventPageSpeaker.settings_panels will have no effect on InlinePanel model editingzEnsure that EventPageSpeaker uses `panels` instead of `settings_panels`.
There are no tabs on non-Page model editing within InlinePanels.r   settings_panelsN)	r   r<   r  r   Warningr  r  ri   r  )rJ   r  checks_resultsrL   rL   rM   2test_page_with_inline_model_with_tabbed_panel_onlyL  s   z_TestInlinePanelRelatedModelPanelConfigChecks.test_page_with_inline_model_with_tabbed_panel_onlyc                 C   sx   t dgt_t dgt_tjddt| jd}tjddt| jd}|  }| || | || t	td t	td	 d
S )zOTest that checks will warn against multiple tabbed panels on InlinePanel modelsr  r  zPEventPageSpeaker.content_panels will have no effect on InlinePanel model editingzEnsure that EventPageSpeaker uses `panels` instead of `content_panels`.
There are no tabs on non-Page model editing within InlinePanels.r   zPEventPageSpeaker.promote_panels will have no effect on InlinePanel model editingzEnsure that EventPageSpeaker uses `panels` instead of `promote_panels`.
There are no tabs on non-Page model editing within InlinePanels.content_panelspromote_panelsN)
r   r<   r  r  r   r  r  r  ri   r  )rJ   	warning_1	warning_2r  rL   rL   rM   2test_page_with_inline_model_with_two_tabbed_panelsb  s&   
z_TestInlinePanelRelatedModelPanelConfigChecks.test_page_with_inline_model_with_two_tabbed_panelsc                 C   sN   t dgt_ttt dgddgt_| |  g  ttd ttd dS )zOChecks should NOT warn if InlinePanel models use tabbed panels AND edit_handlerr  r  r  r   rK   r  N)	r   r<   r  r'   r#   rK   r_   r  r  r,  rL   rL   rM   -test_page_with_inline_model_with_edit_handler  s   
zZTestInlinePanelRelatedModelPanelConfigChecks.test_page_with_inline_model_with_edit_handlerN)r   r   r   r   r  r  r  r  rL   rL   rL   rM   r  :  s    r  c                   @   st   e Zd ZdgZdd Zdd Zedddd	 Zd
d Zdd Z	dd Z
dd Zdd Zeddd Zdd ZdS )TestCommentPanelr  c                 C   s   t  jjdd| _t  jjdd| _t d| _| j| j_tt	 g}|
t| _t|g
t| _| j | _tjjdd| _tjj| jd| jdd	| _tjj| jd
| jd| _tjj| jd| jd| _d S )Nr%  pk   r   r  r  r  location)r  textr   contentpathreply_1)commentr  r   reply_2)r   r   r   commenting_userr  r   r   r   r#   r   r   r:   r"  r'   r   rI   rW   r  r4   r   r  r5   r  r  rJ   unbound_object_listrL   rL   rM   r     s.   



zTestCommentPanel.setUpc                 C   R   | j  }| }| |j tt| jjgt	}| }| }| 
|j dS )z
        Test that the comments toggle is enabled for a TabbedInterface containing CommentPanel, and disabled otherwise
        N)r   rI   rR   show_comments_toggler'   r#   r  r  r   r:   r  )rJ   rO   rX   &tabbed_interface_without_content_panelrL   rL   rM   test_comments_toggle_enabled     
z-TestCommentPanel.test_comments_toggle_enabledF)WAGTAILADMIN_COMMENTS_ENABLEDc                 C   B   |  tdd tttjD  t  }| }|  |j dS )z_
        Test that the comment panel is missing if WAGTAILADMIN_COMMENTS_ENABLED=False
        c                 s   r   r   r   r   r   rL   rL   rM   r     
    
zBTestCommentPanel.test_comments_disabled_setting.<locals>.<genexpr>N)r  r   r)   r6   r  r   rI   r  rJ   rO   rX   rL   rL   rM   test_comments_disabled_setting  s   
z/TestCommentPanel.test_comments_disabled_settingc                 C   r  )zC
        Test that the comment panel is present by default
        c                 s   r   r   r  r   rL   rL   rM   r     r  zATestCommentPanel.test_comments_enabled_setting.<locals>.<genexpr>N)rR   r   r)   r6   r  r   rI   r  r  rL   rL   rM   test_comments_enabled_setting  s   
z.TestCommentPanel.test_comments_enabled_settingc                 C   sD  | j | jd}| jj| j| j|djd }| d }| |d | jj	 | t
|d d | |d d d | jjj	 | t
|d d d d	 | |d d d d d | jjj	 | |d d d d d | jjj	 | t| jj	|d
  | t| jj	|d
  zt|d W dS  ty   | d Y dS w )z|
        Test that the context contains the data about existing comments necessary to initialize the commenting app
        r   )r   r   rX   r   comments_datar   commentsr   replies   authorszcomments-datazhFailed to serialize comments data. This is likely due to a custom user model using an unsupported field.N)rW   r  r"  r   r   r  get_context_datar_   r	  r  r   r  r   r  r  ri   rd  r  r   r  fail)rJ   rX   r   rE  rL   rL   rM   test_context  s4   

zTestCommentPanel.test_contextc                 C   s   | j | j| jd}| d|j |jd }| t|jd | |jd j| j |jd jd }| t|jd | |jd j| j dS )z
        Check that the form has the comments/replies formsets, and that the
        user has been set on each CommentForm/CommentReplyForm instance
        r   for_userr  r   r   r  r  N)	rW   r  r	  ri   rh   r_   r   r   r!  )rJ   rX   comments_formsetreplies_formsetrL   rL   rM   	test_form  s   
zTestCommentPanel.test_formc                 C   s4  | j i ddddddddd	| jjd
dd| jjddddddddddddddddddddddi| j| jd}|jd jd }| |	  |jd jd }| 
|	  | |jj| j | j dddd| jj| jj| jjdddddd| j| jd}|jd jd }| |	  d S )Ncomments-TOTAL_FORMSr  comments-INITIAL_FORMSr   comments-MIN_NUM_FORMSr   comments-MAX_NUM_FORMS  comments-0-idcomments-0-textzedited textcomments-0-contentpathcomments-0-replies-TOTAL_FORMS comments-0-replies-INITIAL_FORMS comments-0-replies-MIN_NUM_FORMS comments-0-replies-MAX_NUM_FORMSzcomments-1-idr  zcomments-1-textznew commentzcomments-1-contentpathznew.pathzcomments-1-replies-TOTAL_FORMSz comments-1-replies-INITIAL_FORMSz comments-1-replies-MIN_NUM_FORMSz comments-1-replies-MAX_NUM_FORMSr   r  )r%  r&  r'  r(  r*  r+  r,  comments-0-DELETEr-  r.  r/  r0  )rW   r  r  r  r  r	  rh   r   r  r   rR   r_   r   r   r  rJ   rX   comment_formrL   rL   rM   test_comment_form_validation  s   	
z-TestCommentPanel.test_comment_form_validationc                 C   s^   | j dddd| jj| jj| jjddddddd| j| jd}|jd jd }| 	|
  d S )Nr   r   r)  a_new_position)r%  r&  r'  r(  r*  r+  r,  zcomments-0-positionr1  r-  r.  r/  r0  r   r  )rW   r  r  r  r  r  r	  rh   r   rR   r   r2  rL   rL   rM   %test_users_can_edit_comment_positionsG  s(   z6TestCommentPanel.test_users_can_edit_comment_positionsz2017-01-01 12:00:00c                 C   s   | j dddd| jj| jj| jjdddddd| j| jd}|jd jd }| 	|
  |  tjj| jjd}| |j| j tjrW| |jtdddd	ddtjd
 d S | |jtdddd	dd d S )Nr   r   r)  )r%  r&  r'  r(  r*  r+  r,  zcomments-0-resolvedr-  r.  r/  r0  r   r  r   i     )tzinfo)rW   r  r  r  r  r  r	  rh   r   rR   r   saver4   r   r   r_   resolved_byr   USE_TZresolved_atr   r   utc)rJ   rX   r3  resolved_commentrL   rL   rM   test_comment_resolvea  s<   z%TestCommentPanel.test_comment_resolvec                 C   s  | j i ddddddddd| jjd	| jjd
| jjddddddddd| jjddd| jjdddddd| j| jd}|j	d j
d }|j	d j
}| |d   | |d   | |d   | |d jj| j | j i ddddddddd| jjd	| jjd
| jjddddddddd| jjd| jjddd| jjdddd| j| jd}|j	d j
d }|j	d j
}| |d   | |d   d S ) Nr%  r   r&  r'  r   r(  r)  r*  r+  r,  r-     r.  r  r/  r0  zcomments-0-replies-0-idzcomments-0-replies-0-textedited_textzcomments-0-replies-1-idzcomments-0-replies-1-textzEdited text 2zcomments-0-replies-2-idr  zcomments-0-replies-2-textz	New replyr   r  r  zcomments-0-replies-0-DELETEzcomments-0-replies-1-DELETE)rW   r  r  r  r  r  r  r  r	  rh   r   r  r   rR   r_   r   r   )rJ   rX   r3  reply_formsrL   rL   rM   "test_comment_reply_form_validation  s   	
	
z3TestCommentPanel.test_comment_reply_form_validationN)r   r   r   r  r   r  r   r  r  r  r$  r4  r6  r   r?  rC  rL   rL   rL   rM   r    s    
!:
#r  c                   @   s2   e Zd ZdgZdd Zdd Zdd Zdd	 Zd
S )TestPublishingPanelr  c                 C   sT   |   | _tt g}|t| _t|gt| _| j	 | _
tjjdd| _d S )Nr  r  )r   r   r#   r&   r   r:   r"  r'   r   rI   rW   r   r   r  r
  rL   rL   rM   r     s   

zTestPublishingPanel.setUpc                 C   r  )z
        Test that the schedule publishing toggle is shown for a TabbedInterface containing PublishingPanel, and disabled otherwise
        N)r   rI   rR   show_schedule_publishing_toggler'   r#   r  r  r   r:   r  )rJ   rO   rX   )tabbed_interface_without_publishing_panelrL   rL   rM   ,test_schedule_publishing_toggle_toggle_shown  r  z@TestPublishingPanel.test_schedule_publishing_toggle_toggle_shownc                 C   s   |  tdd tttjD  t  }| }|  |j |jd j	}|j
dd}|j
dd}|j
dd}| |d | |d	 | |d
 dS )zF
        Test that the publishing panel is present by default
        c                 s   r   r   )r   r&   r   rL   rL   rM   r     r  zMTestPublishingPanel.test_publishing_panel_shown_by_default.<locals>.<genexpr>	expire_atr
  Ndata-actionzdata-w-dialog-targetzw-actionzw-dialog:hidden->w-action#resetnotify)rR   r   r)   r6   r  r   rI   rE  rU   rc   r   r   r_   )rJ   rO   rX   expire_at_inputdata_controllerdata_actiondata_w_dialog_targetrL   rL   rM   &test_publishing_panel_shown_by_default  s   
z:TestPublishingPanel.test_publishing_panel_shown_by_defaultc                 C   s2   | j | j| jd}| d|j | d|j dS )zI
        Check that the form has the scheduled publishing fields
        r   
go_live_atrH  N)rW   r  r   ri   base_fields)rJ   rX   rL   rL   rM   r$    s   zTestPublishingPanel.test_formN)r   r   r   r  r   rG  rO  r$  rL   rL   rL   rM   rD    s    rD  c                   @   r  )TestMultipleChooserPanelr  c                 C   s   t jjdd| _|  | _d S )Nr  r   )r6   r   r   	root_pager   r   r,  rL   rL   rM   r     s   zTestMultipleChooserPanel.setUpc                 C   sH   | j tddd| jjfd}| |jd | |d | |d d S )Nzwagtailadmin_pages:addtestsgallerypage)r      z!name="gallery_images-TOTAL_FORMS"zchooserFieldName: "image")clientr   r   rS  r   r_   status_codeassertContains)rJ   responserL   rL   rM   test_can_render_panel  s   z.TestMultipleChooserPanel.test_can_render_panelN)r   r   r   r  r   r[  rL   rL   rL   rM   rR    s    rR  c                   @   r  )%TestMultipleChooserPanelGetComparisonr  c                 C   sH   t  d| _t }|| j_tdd| _tjjdd}|j	| jd d S )Nr   z	Test pager   r  r   r   )
r   r   r   r   r   r>   r  r6   r   	add_child)rJ   r   parent_pagerL   rL   rM   r   )  s   z+TestMultipleChooserPanelGetComparison.setUpc                    sL    j  j j  jd } fdd|D }dd |D } d| d S )Nr  c                    s   g | ]	}| j  j qS rL   r  r  r,  rL   rM   r   :  s    zMTestMultipleChooserPanelGetComparison.test_get_comparison.<locals>.<listcomp>c                 S   r  rL   r  r  rL   rL   rM   r   ;  r  zGallery images)r  r   r   r   r  ri   r  rL   r,  rM   r  1  s   
z9TestMultipleChooserPanelGetComparison.test_get_comparisonNr  rL   rL   rL   rM   r\  &  s    r\  c                   @   r  )TestPanelIconsc                 C       |   | _t | _| j| j_d S r   r   r   r2   r   r,  rL   rL   rM   r   @     
zTestPanelIcons.setUpc              	   C   s
  t ddddft dd ddft ddddft dd	d	d
fg}tdd |D }|t}| }|j| j| d}| }t|D ]A\}\}}}	}
|j	| }|j
}t|jj}| j||jd | |j| | |d|	 |
 W d    n1 s}w   Y  qAd S )Nr  link-externalr   r*  placeholderrl   pilcrowr=  rn  r  c                 S      g | ]^}}|qS rL   rL   r   r   _rL   rL   rM   r   P  r  z?TestPanelIcons.test_default_fieldpanel_icon.<locals>.<listcomp>r   rX   
field_typer   #icon-)r   r#   r   r:   rI   r   r   r  	enumerater  r   r`   rN  r   r  r   r_   iconr   rJ   casesrK   rO   bound_edit_handlerhtmlirh  expected_iconrendered_defaultdefault_countrY  r   rk  rL   rL   rM   test_default_fieldpanel_iconE  s,   


z+TestPanelIcons.test_default_fieldpanel_iconc              	   C   s,  t ddddddft ddddddft d	d
dd
ddft ddddddfg}tdd |D }|t}| }|j| j| d}| }t|D ]J\}\}}}	}
|j	| }|j
}t|jj}| j||jd$ | |j| | d| | | |d|	 |
 W d    n1 sw   Y  qId S )Nr  cogrn  rc  r   r*  r   rd  rl   cutre  r=  snippetrn  r   c                 S   rf  rL   rL   rg  rL   rL   rM   r   l  r  z@TestPanelIcons.test_override_fieldpanel_icon.<locals>.<listcomp>ri  rj  rl  )r   r#   r   r:   rI   r   r   r  rm  r  r   r`   rN  r   r  r   r_   rn  ri   r   ro  rL   rL   rM   test_override_fieldpanel_icon`  s.   

z,TestPanelIcons.test_override_fieldpanel_iconc           
   	   C   s   t tdtdfddddfttdtdfdd	dd	fg}td
d |D }|t}| }|j| j| d}|	 }t
|D ]3\}\}}|j| }	| jt|d | |	j| | d| | W d    n1 sow   Y  qAd S )Nr\   r]   Dateyszcalendar-alt)r   rn  	time_fromtime_toTimeyshistoryc                 S   rf  rL   rL   rg  rL   rL   rM   r     r  z@TestPanelIcons.test_override_panelgroup_icon.<locals>.<listcomp>ri  
panel_typerl  )r!   r   r   r#   r   r:   rI   r   r   r  rm  r  r  r`   r_   rn  ri   
rJ   rp  rK   rO   rq  rr  rs  r   rt  rY  rL   rL   rM   test_override_panelgroup_icon}  s<   	

z,TestPanelIcons.test_override_panelgroup_iconc           
   	   C   s   t dddddftddddd	dfg}td
d |D }|t}| }|j| j| d}| }t	|D ]3\}\}}|j
| }	| jt|d | |	j| | d| | W d    n1 sdw   Y  q6d S )Ncarousel_itemsCarouseycogs)r   rn  rf   Linky	link_pagepick)r   chooser_field_namern  c                 S   rf  rL   rL   rg  rL   rL   rM   r     r  zATestPanelIcons.test_override_inlinepanel_icon.<locals>.<listcomp>ri  r  rl  )r    r"   r#   r   r:   rI   r   r   r  rm  r  r  r`   r_   rn  ri   r  rL   rL   rM   test_override_inlinepanel_icon  s6   

z-TestPanelIcons.test_override_inlinepanel_iconc              	   C   s  t jjdd}tdddddd}|j|d	}tjji |d
 tddddftdddfg}t	dd |D }|
t}| }|j| j| |d}| }t|D ]3\}\}	}
|j| }| jt|	d | |j|
 | d|
 | W d    n1 sw   Y  qQd S )Nr  r   z
Contact usz
contact-uszto@email.comzfrom@email.comzThe subject)rP   r[   
to_addressfrom_addresssubjectr   )	form_datar  thank_you_redirect_pageresetry  	thumbtackc                 S   rf  rL   rL   rg  rL   rL   rM   r     r  z@TestPanelIcons.test_override_misc_panel_icon.<locals>.<listcomp>r   rX   r   r  rl  )r6   r   r   r=   r]  r0   r   r$   r1   r#   r   rI   r   r   r  rm  r  r  r`   r_   rn  ri   )rJ   rS  	form_pagerp  rK   rO   rq  rr  rs  r   rt  rY  rL   rL   rM   test_override_misc_panel_icon  s8   


z,TestPanelIcons.test_override_misc_panel_iconN)	r   r   r   r   rw  r|  r  r  r  rL   rL   rL   rM   r_  ?  s    !r_  c                   @   s   e Zd ZdgZdd ZedfddZeedd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* ZdS )+TestTitleFieldPanelr  c                 C   r`  r   ra  r,  rL   rL   rM   r     rb  zTestTitleFieldPanel.setUpNc                 C   s8   | |}| }|j| j| |d}| }| |S )Nr  )r   rI   r   r   r  get_soup)rJ   rK   rJ  r   rO   rq  rr  rL   rL   rM   get_edit_handler_html  s   

z)TestTitleFieldPanel.get_edit_handler_htmlc                 C   s,   t  }|jd jd }| t|t d S )Nr   )r6   r   r  rR   r   r(   )rJ   rK   first_inner_panel_childrL   rL   rM   1test_default_page_content_panels_uses_title_field  s   zETestTitleFieldPanel.test_default_page_content_panels_uses_title_fieldc                 C   s   |  ttdtdg}| |jddid |dj}| |d d | |d d	 | |d
 d | |d d | |d d d S )NrP   r[   classw-panel titler   inputr   rd  zPage title*r
  w-syncdata-w-sync-target-value#id_slugrI  Ofocus->w-sync#check blur->w-sync#apply change->w-sync#apply keyup->w-sync#apply)r  r#   r(   r   assertIsNotNonefindr   r_   rJ   rr  r   rL   rL   rM   test_default_title_field_panel  s   z2TestTitleFieldPanel.test_default_title_field_panelc                 C   sJ   |  ttdg}| |jddid |dj}| |d d d S )NrP   r  r  r   r  r  r  )r  r#   r(   r  r  r   r_   r  rL   rL   rM   test_form_without_slugfield	  s   z/TestTitleFieldPanel.test_form_without_slugfieldc                 C   sZ   | j ttdtdddgt d}| |jddid |d	j}| |d
 d d S )NrP   r[   Tr;  r   r  r  r   r  r  r  )	r  r#   r(   r   r:   r  r  r   r_   r  rL   rL   rM   !test_form_with_readonly_slugfield	  s   z5TestTitleFieldPanel.test_form_with_readonly_slugfieldc                 C   s   t jjdd}| |jd | jttdtdg|d}| 	|
djd | jttddd	tdg|d}| |
djd d
S )z
        If the Page (or any model) has `live = True`, do not apply the actions by default.
        Allow this to be overridden though.
        r  r  TrP   r[   r   r  rI  )apply_if_liveN)r:   r   r   r_   liver  r#   r(   r   assertIsNoner  r   r  )rJ   
event_liverr  rL   rL   rM   $test_not_using_apply_actions_if_live	  s   z8TestTitleFieldPanel.test_not_using_apply_actions_if_livec                 C   sb   | j ttddgdtdgtd}|dj}| |d d | |d d	 | |d
  d S )Nr  urltargets)rJ  r  r
  r  r  #id_urlrI  )	r  r#   r(   r   r9   r  r   r_   r  r  rL   rL   rM   *test_using_apply_actions_if_non_page_model;	  s   z>TestTitleFieldPanel.test_using_apply_actions_if_non_page_modelc                 C   s   t dddd}d|_| jttddgdtdgt |d	}|d
j}| |d d | |d d | 	|
d | jttddgddtdgt |d	}|d
j}| |
d dS )z^
        Check for instance being live should be agnostic to how that is implemented.
        zFree sheepdogzhttps://example.comi  )r  r  r   Tr  r  r  )rJ  r   r  r
  r  r  r  rI  )r  r  N)r9   r  r  r#   r(   r   r  r   r_   r  r   r  )rJ   advert_liverr  r   rL   rL   rM   =test_using_apply_actions_if_non_page_model_with_live_propertyG	  s4   
zQTestTitleFieldPanel.test_using_apply_actions_if_non_page_model_with_live_propertyc                 C   s>   |  ttdg dtdg}|dj}| |d d d S )NrP   r  r[   r  r  r  r  r#   r(   r   r  r   r_   r  rL   rL   rM    test_targets_override_with_emptyo	  s
   z4TestTitleFieldPanel.test_targets_override_with_emptyc                 C   sP   |  ttddgdtdg}|dj}| |d d | |d d d S )	Nr  rP   r  r  r
  r  r  z	#id_titler  r  rL   rL   rM   )test_targets_override_with_non_slug_fieldx	  s   z=TestTitleFieldPanel.test_targets_override_with_non_slug_fieldc                 C   sX   |  ttdddgdtdtdg}|dj}| |d d | |d d	 d S )
NrP   r   r  r  r  r
  r  r  z#id_cost, #id_locationr  r  rL   rL   rM   *test_targets_override_with_multiple_fields	  s   
z>TestTitleFieldPanel.test_targets_override_with_multiple_fieldsc                 C   sN   |  ttdddtdg}| |jddid | |jddid d S )	NrP   zsuper-titler:  r[   r  r  r   zw-panel super-title)r  r#   r(   r   r  r  r  )rJ   rr  rL   rL   rM   test_classname_override	  s   z+TestTitleFieldPanel.test_classname_overridec                 C   s   t jdddddd}| ttd|dtd	g}|d
j}| |d d | |d d	ddg | |d d | |d d d S )Nzw-cleanz!w-clean#clean blur->w-clean#cleanz
trim upperz.will-be-ignored)r
  rI  data-w-clean-filters-valuer  r   rP   r   r[   r  r
  zw-clean w-syncrI   r  r  r  r  )
r   	TextInputr  r#   r(   r   r  r   r_   join)rJ   rc   rr  r   rL   rL   rM   test_merging_data_attrs	  s,   	z+TestTitleFieldPanel.test_merging_data_attrsc                 C   Z   |  ttdddtdg}|dj}| |d d | |d d | d	| d S )
NrP   Frd  r[   r  r   r
  r  rd  r  r#   r(   r   r  r   r_   rT   r  rL   rL   rM   test_placeholder_override_false	  s   z3TestTitleFieldPanel.test_placeholder_override_falsec                 C   sZ   |  ttdd dtdg}|dj}| |d d | |d d | d| d S )	NrP   r  r[   r  r   r
  r  rd  r  r  rL   rL   rM   test_placeholder_override_none	     z2TestTitleFieldPanel.test_placeholder_override_nonec                 C   r  )
NrP   r  r  r[   r  r   r
  r  rd  r  r  rL   rL   rM   &test_placeholder_override_empty_string	  r  z:TestTitleFieldPanel.test_placeholder_override_empty_stringc                 C   sj   |  ttdtjddiddtdg}|dj}| |d d | |d	 d
 | |d d d S )NrP   rd  zMy custom placeholderr   r   r[   r  r   r
  r  	r  r#   r(   r   r  r   r  r   r_   r  rL   rL   rM   $test_placeholder_override_via_widget	  s    z8TestTitleFieldPanel.test_placeholder_override_via_widgetc              	   C   l   |  ttddtjddiddtdg}|dj}| |d	 d | |d
 d | |d d d S )NrP   zPANEL placeholderrd  WIDGET placeholderr   rd  rc   r[   r  r   r
  r  r  r  rL   rL   rM   /test_placeholder_override_via_widget_over_kwarg	  "   zCTestTitleFieldPanel.test_placeholder_override_via_widget_over_kwargc              	   C   r  )NrP   Frd  r  r   r  r[   r  r   r
  r  r  r  rL   rL   rM   5test_placeholder_override_via_widget_over_false_kwarg
  r  zITestTitleFieldPanel.test_placeholder_override_via_widget_over_false_kwarg)r   r   r   r  r   r:   r  r   r6   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rL   rL   rL   rM   r    s2    

(	$r  N)scollections.abcr   r   r   r   	functoolsr   typingr   r	   unittestr
   djangor   django.confr   django.contrib.authr   django.contrib.auth.modelsr   r   django.corer   django.core.exceptionsr   r   django.testr   r   r   django.urlsr   django.utils.htmlr   r   	freezegunr   wagtail.admin.formsr   r   wagtail.admin.panelsr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   wagtail.admin.rich_textr,   wagtail.admin.widgetsr-   r.   r/   wagtail.contrib.forms.modelsr0   wagtail.contrib.forms.panelsr1   wagtail.coreutilsr2   wagtail.imagesr3   wagtail.modelsr4   r5   r6   r7   wagtail.test.testapp.formsr8   wagtail.test.testapp.modelsr9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   wagtail.test.utilsrE   rF   r   r   r   r   r  r  r#  r8  rw  r  r  r  r  r  r  r  rD  rR  r\  r_  r  rL   rL   rL   rM   <module>   sr    H8 9`m dB TU3  \$U  BA 