U
    {hO                    @   sl  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m	Z	 d dl
mZ d dlmZ d dlmZmZ d dlmZmZ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#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d dl*m+Z+ d dl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; d dl<m=Z= d dl>m?Z?m@Z@ d dlAmBZB d dlCmDZD d dlEmFZF G dd de=eZGG dd de=eZHG dd de=eZIG dd de=eZJG dd de=eZKG d d! d!e=eZLG d"d# d#e=eZMG d$d% d%e=eZNG d&d' d'e=eZOed(d)G d*d+ d+e=eZPG d,d- d-e=eZQG d.d/ d/e=eZRG d0d1 d1e=eZSdS )2    N)mock)settings)Group
Permission)mail)ContentFile)HttpRequestHttpResponse)TestCasemodify_settingsoverride_settings)reverse)timezone)gettext_lazy)AdminURLFinder)PageClassNotFoundError)	CommentCommentReplyGroupPagePermissionLocalePagePageLogEntryPageSubscriptionRevisionSite)page_published)EVENT_AUDIENCE_CHOICESAdvertAdvertPlacementCustomPermissionPageEventCategory	EventPageEventPageCarouselItemFilePageManyToManyBlogPagePageChooserModel
SimplePageSingleEventPageStandardIndex
StreamPage
TaggedPage)WagtailTestUtils)inline_formsetnested_form_data)submittable_timestamp)UserProfile)render_timestampc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dddd Z
dd Zdd Zejddd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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Z d;d< Z!d=d> Z"d?d@ Z#dAdB Z$dCdD Z%dEdF Z&dGdH Z'dIdJ Z(e	dKdLdMiidNe)dOdPdQdRdSdT Z*e)dUdVidWdXdY Z+dZd[ Z,d\d] Z-d^d_ Z.d`da Z/dbdc Z0ddde Z1dfdg Z2dhdi Z3djdk Z4dldm Z5dndo Z6dpdq Z7drds Z8dtdu Z9dvdw Z:dxdy Z;dzd{ Z<dS )|TestPageEditzdata-side-panel-toggle="status"[^<]+<svg[^<]+<use[^<]+</use[^<]+</svg[^<]+<div data-side-panel-toggle-counter[^>]+w-bg-critical-200[^>]+>\s*%(num_errors)s\s*</div>c                 C   s  t jjdd| _tdddd}| jj|d |   tjj|jd| _	t
d}d	|_td
d|d}| jj|d |   tjj|jd| _tddddddd| _| jj| jd tddddddd| _| jj| jd tdddddd| _| jj| jd |  | _d S )N   idHello world!hello-worldhellotitleslugcontentinstancezFile for testing multipartztest.txtz	File Pagez	file-pager9   r:   
file_field
Event page
event-pagethe moonpublicfree
2001-01-01r9   r:   locationaudiencecost	date_fromzMars landingzmars-landingZmarszHello unpublished world!zhello-unpublished-worldFT)r9   r:   r;   livehas_unpublished_changes)r   objectsget	root_pager&   	add_childsave_revisionpublishr4   
child_pager   namer#   	file_pager!   
event_pager'   single_event_pageunpublished_pageloginuser)selfrS   Z	fake_filerU    r\   p/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/admin/tests/pages/test_edit_page.pysetUp<   s\    zTestPageEdit.setUpc                 C   sj   |j  }| jd|ddd | |}|d}| | | jd| d|ddd | jd|ddd d S )	N_<button type="button" data-a11y-dialog-show="schedule-publishing-dialog">Edit schedule</button>   TcountZallow_extra_attrsz
            template[data-controller="w-teleport"][data-w-teleport-target-value="[data-edit-form]"]
            #schedule-publishing-dialog
            z<form action="z" method="POST" data-edit-form>zn<div id="schedule-publishing-dialog" class="w-dialog w-dialog--message publishing" data-controller="w-dialog">)r;   decodeassertTagInHTMLget_soup
select_oneassertIsNotNone)r[   responseedit_urlhtmlsoupZdialogr\   r\   r]   assertSchedulingDialogRenderedx   s0    



z+TestPageEdit.assertSchedulingDialogRenderedc                 C   s:  | j td| jjfd}| |jd | |d d | |d | |d | |d | |d	 | |d
 | |d | |d | |d | |d | |d | |d | |d | |d | |td| jjfd | j|td| jjfddd t	| j
}d| jj }| || j| d S )Nwagtailadmin_pages:editargs   Content-Typetext/html; charset=utf-8id="status-sidebar-live"zWho this event is forzq<label class="w-field__label" for="id_speakers-__prefix__-last_name" id="id_speakers-__prefix__-last_name-label">zAdd speakerszPut the keynote speaker firstzFor SEO nerds onlyzW<button type="submit" name="action-panic" value="Panic!" class="button">Panic!</button>ztestapp/js/siren.jszW<button type="submit" name="action-relax" value="Relax." class="button">Relax.</button>z`<button type="submit" name="action-submit" value="Submit to Moderators approval" class="button">zT<aside class="form-side form-side--initial" aria-label="Side panels" data-form-side>zdata-form-side-explorerzReferenced 0 timeswagtailadmin_pages:usagewagtailadmin_pages:history   rb   z/admin/pages/%d/edit/)clientrN   r   rV   r4   assertEqualstatus_codeassertContainsassertNotContainsr   rZ   get_edit_url)r[   rh   
url_finderZexpected_urlr\   r\   r]   test_page_edit   sZ     
zTestPageEdit.test_page_editc                 C   sT   t jj| jd | jtd| jjfd}| |d | |td| jjfd d S )Npagerm   rn   zReferenced 1 timert   )	r%   rM   createrV   rx   rN   r   r4   r{   r[   rh   r\   r\   r]   "test_usage_count_information_shown   s     z/TestPageEdit.test_usage_count_information_shownc                 C   s\   t ddd}| jj|d | jtd|jfd}| |jd | 	|td|jfd d S )	NzPage with custom permszcustom-perms)r9   r:   r<   rm   rn   rp   ru   )
r   rO   rP   rx   rN   r   r4   ry   rz   r|   )r[   r   rh   r\   r\   r]   test_edit_custom_permissions   s    z)TestPageEdit.test_edit_custom_permissionsF)ZWAGTAIL_WORKFLOW_ENABLEDc                 C   s8   | j td| jjfd}| |jd | |d d S )Nrm   rn   rp   z%value="Submit to Moderators approval")rx   rN   r   rV   r4   ry   rz   r|   r   r\   r\   r]   6test_workflow_buttons_not_shown_when_workflow_disabled   s
    zCTestPageEdit.test_workflow_buttons_not_shown_when_workflow_disabledc                 C   s8   | j td| jjfd}| |jd | |d d S )Nrm   rn   rp   zid="status-sidebar-draft")rx   rN   r   rX   r4   ry   rz   r{   r   r\   r\   r]   &test_edit_draft_page_with_no_revisions   s
    z3TestPageEdit.test_edit_draft_page_with_no_revisionsc                 C   sx   | j td| jjfd}| |jd | |d | |d | j td| j	jfd}| |jd | 
|d dS )z|
        Test checks if 'enctype="multipart/form-data"' is added and only to forms that require multipart encoding.
        rm   rn   rp   zenctype="multipart/form-data"zwagtailadmin/pages/edit.htmlN)rx   rN   r   rV   r4   ry   rz   r|   assertTemplateUsedrU   r{   r   r\   r\   r]   test_edit_multipart  s    z TestPageEdit.test_edit_multipartz&wagtail.models.ContentType.model_classN)Zreturn_valuec              	   C   s4   |  t  | jtd| jjfd W 5 Q R X d S )Nrm   rn   )ZassertRaisesr   rx   rN   r   rV   r4   )r[   Zmocked_methodr\   r\   r]   -test_edit_when_specific_class_cannot_be_found  s    z:TestPageEdit.test_edit_when_specific_class_cannot_be_foundc                 C   s   t ddd}dd|dd}| jtd| jjgd	|}| |td
| jjgd	 tj	
 }| |jj|j | tj|jj | |j d dS )zG
        Check that file uploads work when directly publishing
        
   A new filezpublished-file.txtrT   New filenew-filePublish)r9   r:   r?   action-publishrm   rn   wagtailadmin_exploreN)r   rx   postr   rU   r4   assertRedirectsrO   r#   rM   rN   ry   r?   rT   
assertTrueospathexistsread)r[   file_upload	post_datarh   rU   r\   r\   r]   test_upload_file_publish!  s$      
z%TestPageEdit.test_upload_file_publishc              	   C   s   t ddd}dd|d}| jtd| jjgd|}| |td| jjgd tj	t
j|j}| tj| t|d	}| | d W 5 Q R X tj    tj }| |jj|j | tj|jj | |j d d
S )zB
        Check that file uploads work when saving a draft
        r   zdraft-file.txtr   r   r   r>   rm   rn   rbN)r   rx   r   r   rU   r4   r   r   r   joinr   Z
MEDIA_ROOTrT   r   r   openry   r   r#   rM   rN   get_latest_revisionrR   r?   )r[   r   r   rh   	file_pathZ
saved_filerU   r\   r\   r]   test_upload_file_draft<  s,      
z#TestPageEdit.test_upload_file_draftc                 C   st   d| j _| j jtjjddd | j   | jt	d| j
jfd}| |jd t| j }| || j d S )NFwagtailadminaccess_adminZcontent_type__app_labelcodenamerm   rn   .  )rZ   is_superuseruser_permissionsaddr   rM   rN   saverx   r   rS   r4   ry   rz   r   assertIsNoner}   rV   )r[   rh   r~   r\   r\   r]   test_page_edit_bad_permissions^  s     

z+TestPageEdit.test_page_edit_bad_permissionsc                 C   s   dddd}| j td| jjfd|}| |td| jjfd tjj| jjd}| 	|j
 | |j| jj | |j| jj | |j| jj | |j|d  d S )	NI've been edited!Some contentr6   r9   r;   r:   rm   rn   r3   r9   )rx   r   r   rS   r4   r   r&   rM   rN   r   rL   ry   r9   r;   r:   draft_titler[   r   rh   child_page_newr\   r\   r]   test_page_edit_posts  s$      z TestPageEdit.test_page_edit_postc                 C   s  dddd}| j td| jjfd|}| |td| jjfd tjj| jjd}| 	|j
 | |j | |jd | |jd | |jd | |j|d  t }|d	t|d
 | j td| jjfd|}| |jd tjj| jjd}| 	|j dddd}| j td| jjfd|}| |td| jjfd tjj| jjd}| 	|j
 | |jd | |jd | |jd | |j|d  d S )NzHello unpublished world! editedzhello editedzhello-unpublished-world-editedr   rm   rn   r3   r9   r   )r   
go_live_atr   z!Hello unpublished world! edited 2zhello edited 2z hello-unpublished-world-edited-2)rx   r   r   rX   r4   r   r&   rM   rN   r   rL   assertFalserK   ry   r9   r;   r:   r   r   nowupdater.   rz   )r[   r   rh   r   r   r\   r\   r]   $test_page_edit_post_unpublished_page  sd    z1TestPageEdit.test_page_edit_post_unpublished_pagec                 C   sh   d| j _| j   dddd}| jtd| j jfd|}| |d tj	j
| j jd	}| |j d S )
NTr   r   r6   r   rm   rn   z+The page could not be saved as it is lockedr3   )rS   lockedr   rx   r   r   r4   r{   r&   rM   rN   r   rL   r   r\   r\   r]   test_page_edit_post_when_locked  s    
 z,TestPageEdit.test_page_edit_post_when_lockedc                 C   sb  t  tjdd }t  tjdd }dddt|t|d}td| jjfd	}| jj	||d
d}| 
||dd tjj| jjd}| |j | tjj|jdjd
d  | tjj|jt| d  | tjj|jt| d  | j|dd
dd | j|dt| d
dd | j|dt| d
dd | || | |d d S )N
   days   r   r   r6   r9   r;   r:   r   	expire_atrm   rn   Tfollowr   rp   r3   	object_idZapproved_go_live_at__isnullr   Zcontent__go_live_at__startswithr   Zcontent__expire_at__startswith;<div class="w-label-3 w-text-primary">Once published:</div>r`   rj   rb   .<span class="w-text-grey-600">Go-live:</span> -<span class="w-text-grey-600">Expiry:</span> TThis publishing schedule will only take effect after you select the "Publish" option)r   r   datetime	timedeltar.   r   rS   r4   rx   r   r   r&   rM   rN   r   rK   r   r   page_revisionsfilterexcluder   strdater{   r0   rl   )r[   r   r   r   ri   rh   r   r\   r\   r]   test_edit_post_scheduled  sj    

z%TestPageEdit.test_edit_post_scheduledc                 C   s4  t jj| jddid ddddd}td	| jjfd
}| jj||dd}|j	
 }| ||dd tjj| jjd}| |j | tjj|jdjdd  tjr| tjj|jdd  n| tjj|jdd  | j|dddd | j|dddd | || | jd|ddd | |d d S )NZcurrent_time_zonezAsia/Jakarta)rZ   defaultsr   r   r6   z2022-03-20 06:00)r9   r;   r:   r   rm   rn   Tr   r   rp   r3   r   r   z2022-03-19T23:00:00Z)r   Zcontent__go_live_atz2022-03-20T06:00:00r   r`   r   zD<span class="w-text-grey-600">Go-live:</span> March 20, 2022, 6 a.m.z><input type="text" name="go_live_at" value="2022-03-20 06:00">ra   r   )r/   rM   Zupdate_or_createrZ   r   rS   r4   rx   r   r;   rc   r   r&   rN   r   rK   r   r   r   r   r   r   r   ZUSE_TZr{   rl   rd   )r[   r   ri   rh   rj   r   r\   r\   r]   (test_edit_post_scheduled_custom_timezone>  sp    
	z5TestPageEdit.test_edit_post_scheduled_custom_timezonec                 C   sh   | j ddd}|jtjjdd | jdd | jtd| j	j
fd}| |jd	 | |d
 d S )Neditorpasswordr   Editorsr   usernamerm   rn   rp   z4Anyone with editing permissions can create schedules)create_usergroupsr   r   rM   rN   rY   rx   r   rV   r4   ry   rz   r{   )r[   r   rh   r\   r\   r]   .test_schedule_panel_without_publish_permission  s     z;TestPageEdit.test_schedule_panel_without_publish_permissionc              	   C   s   dddt t tjdd t t tjdd d}| jtd| jj	fd	|}| 
|jd
 | |jd dd | |jd dd | j|ddd d}| |j | jd|i  | |d d S )Nr   r   r6   r2   r   r`   r   rm   rn   rp   formr   z1Go live date/time must be before expiry date/timer   <<div class="w-label-3 w-text-primary">Invalid schedule</div>Trj   
num_errors!data-w-unsaved-force-value="true"r.   r   r   r   r   rx   r   r   rS   r4   ry   rz   assertFormErrorcontextr{   assertRegexr;   rc   STATUS_TOGGLE_BADGE_REGEXr[   r   rh   r   r\   r\   r]   )test_edit_scheduled_go_live_before_expiry  sH     z6TestPageEdit.test_edit_scheduled_go_live_before_expiryc                 C   s   dddt t tjdd d}| jtd| jj	fd|}| 
|jd	 | |jd
 dd | j|ddd d}| |j | jd|i  | |d d S )Nr   r   r6   r   )r9   r;   r:   r   rm   rn   rp   r   r   z&Expiry date/time must be in the futurer   Tr   r`   r   r   r   r   r\   r\   r]   &test_edit_scheduled_expire_in_the_past  s8     z3TestPageEdit.test_edit_scheduled_expire_in_the_pastc           
      C   sV  t  tjdd | j_t  tjdd | j_| j }t  tjdd }t  tjdd }dddt|t|d	}t	d
| jj
fd}| j||}| |jd tjj| jj
d}| |j | |j|j | j|ddd | j|ddd | j|ddd |j }| jd|ddd | j|ddd d}	| |j | jd|	i  d S )Nr`   r   r2   r   ir   r   r6   r   rm   rn   rp   r3   r   Tr   z-<span class="w-text-grey-600">Go-live:</span>z,<span class="w-text-grey-600">Expiry:</span>r_   ra   r   r   )r   r   r   r   rS   r   r   rQ   r.   r   r4   rx   r   ry   rz   r&   rM   rN   r   rK   Zlatest_revision_idpkr|   r;   rc   rd   r{   r   r   )
r[   Zlatest_revisionr   r   r   ri   rh   r   rj   r   r\   r\   r]   <test_edit_post_invalid_schedule_with_existing_draft_schedule  sb    

zITestPageEdit.test_edit_post_invalid_schedule_with_existing_draft_schedulec              	   C   s^  t  }t| z8d| j_| j  tj	j
| jjdj}ddddd}| jjtd| jjfd	|dd
}| |td| jjfd	 tj	j
| jjd}| |j|d  | |j|d  | |jd |jd d }| |d |j | |d | | |d |j | |j | ||j |jd D ]}| d|j  qJq.W 5 t| X d S )NTr3   r   r   hello-world-newr   r9   r;   r:   r   rm   rn   r   r   r9   r`   r   r2   Zsenderr=   messages)r   Z	MagicMockr   connectZ
disconnectrS   rL   r   r&   rM   rN   r4   first_published_atrx   r   r   r   rO   ry   r9   r   Z
call_countZ
mock_callsZspecific_classassertIsInstancer   r   assertInmessage)r[   Zmock_handlerr   r   rh   r   Z	mock_callr   r\   r\   r]   test_page_edit_post_publish4  sH    

 z(TestPageEdit.test_page_edit_post_publishc              
   C   s   t dddd}| jj|d |   t jj|jd| _| jj	t
  }t
 tjdd }d	d
ddt|ddddd	}| jtd| jjfd| t jj| jjd}|j	t
  }| |j|j | |jd dS )znTest that we can update the first_published_at via the Page edit form,
        for page models that expose it.r5   zhello-again-worldr7   )r9   r:   bodyr<   r3   r2   r   r   r   r   r     )	r9   r   r:   r   r   comments-TOTAL_FORMScomments-INITIAL_FORMScomments-MIN_NUM_FORMScomments-MAX_NUM_FORMSrm   rn   N)r$   rO   rP   rQ   rR   rM   rN   r4   rS   r   r   r   r   r   r.   rx   r   r   assertNotEqualr   ry   )r[   rS   Zinitial_deltar   r   r   Z	new_deltar\   r\   r]    test_first_published_at_editablep  s8     z-TestPageEdit.test_first_published_at_editablec                 C   s`  d| j _| j   t tjdd }t tjdd }ddddt|t|d	}| j	t
d
| j jfd|}| |jd tjj| j jd}| |j | tjj|jdjdd  | j|jdd | |jd | jt
d
| j jfd|}| j|ddd | j|dt| ddd | j|dt| ddd |j }| jd|ddd d S )NFr`   r   r2   r   r   r6   r   r9   r;   r:   r   r   r   rm   rn   r   r3   r   Tr   OA page scheduled for future publishing should have has_unpublished_changes=Truemsg	scheduledr   r   r   r   r   r_   r   ra   ) rS   rK   r   r   r   r   r   r.   rx   r   r   r4   ry   rz   r&   rM   rN   r   r   r   r   r   r   r   rL   status_stringr|   r{   r0   r;   rc   rd   r[   r   r   r   rh   r   rj   r\   r\   r]   1test_edit_post_publish_scheduled_unpublished_page  sp    
  
z>TestPageEdit.test_edit_post_publish_scheduled_unpublished_pagec                 C   sn  d| j _| j   t tjdd }t tjdd }ddddt|t|d	}| j	t
d
| j jfd|}| |jd tjj| j jd}| |j | |jd | tjj|jdjdd  t }dddd|d}| j	t
d
| j jfd|}| |jd tjj| j jd}| |j | tjj|jdjdd  |j }| jd|ddd d S )NFr`   r   r2   r   r   r6   r   r  rm   rn   r   r3   r  r   Tr   r9   r;   r:   r   r   rp   r_   r   ra   )rS   rK   r   r   r   r   r   r.   rx   r   r   r4   ry   rz   r&   rM   rN   r   r  r   r   r   r   r   r   r;   rc   rd   r  r\   r\   r]   @test_edit_post_publish_now_an_already_scheduled_unpublished_page  sd    
  
zMTestPageEdit.test_edit_post_publish_now_an_already_scheduled_unpublished_pagec           	      C   s  d| j _| j   | j j}| j j}t tjdd }t tjdd }ddddt	|t	|d	}| j
td
| j jfd|}| |jd tjj| j jd}| |j | |jd | tjj|jdjdd  | j|jdd | | |d | j|j|dd | j
td
| j jfd|}| j|ddd | j|dt| ddd | j|dt| ddd |j ! }| j"d|ddd d S )NTr`   r   r2   r   r   r6   r   r  rm   rn   r   r3   live + scheduledr   r   r  r  z`A page scheduled for future publishing should have a new revision, that is not the live revisionGA live page with scheduled revisions should still have original contentr   r   r   r   r   r_   r   ra   )#rS   rK   r   live_revisionr9   r   r   r   r   r.   rx   r   r   r4   ry   rz   r&   rM   rN   r   r  r   r   r   r   r   rL   r   r   r|   r{   r0   r;   rc   rd   )	r[   r  original_titler   r   r   rh   r   rj   r\   r\   r]   /test_edit_post_publish_scheduled_published_page/  s    
  
z<TestPageEdit.test_edit_post_publish_scheduled_published_pagec                 C   sj  d| j _| j   | j j}t tjdd }t tjdd }ddddt|t|d	}| j	
td
| j jfd|}| |jd tjj| j jd}| |j | tjj|jdjdd  | |j|d t }dddd|d}| j	
td
| j jfd|}| |jd tjj| j jd}| |j | tjj|jdjdd  | |jd d S )NTr`   r   r2   r   r   r6   r   r  rm   rn   r   r3   r   r   r  r
  rp   r5   )rS   rK   r   r9   r   r   r   r   r.   rx   r   r   r4   ry   rz   r&   rM   rN   r   r   r   r   r   r   )r[   r  r   r   r   rh   r   r\   r\   r]   >test_edit_post_publish_now_an_already_scheduled_published_page  sh    
  zKTestPageEdit.test_edit_post_publish_now_an_already_scheduled_published_pagec                 C   s  t  tjdd }ddddt|d}td| jjfd	}| j	||}| 
|jd
 tjj| jjd}| |j | 
|jd | 
|j|jddd t  tjdd }t  tjdd }dddt|t|d}| jj	||dd}| ||d
d tjj| jjd}| |j | tjj|jdjdd  | tjj|jt| d  | tjj|jt| d  | j|dt| ddd | j|dddd | j|dt| ddd | j|dt| ddd | || d S )Nr   r   r   r   r6   r   r9   r;   r:   r   r   rm   rn   r   r3   rK   r   secondmicrosecondr      r   Tr   rp   r   r   r   r   r   r`   r   r   r   ) r   r   r   r   r.   r   rS   r4   rx   r   ry   rz   r&   rM   rN   r   rK   r  r   replacer   r   r   r   r   r   r   r   r   r{   r0   rl   )r[   r   r   ri   rh   r   r   new_expire_atr\   r\   r]   ;test_edit_post_save_schedule_before_a_scheduled_expire_page  s    

zHTestPageEdit.test_edit_post_save_schedule_before_a_scheduled_expire_pagec           	      C   s  t  tjdd }ddddt|d}td| jjfd	}| j	||}| 
|jd
 tjj| jjd}| |j | 
|jd | 
|j|jddd t  tjdd }t  tjdd }ddddt|t|d}| j	||}| 
|jd
 tjj| jjd}| |j | 
|jd | tjj|jdjdd  | jtd| jjfd	|}| j|dt| dd | j|ddd | j|dt| ddd | j|dt| ddd |j }| jd|ddd d S )Nr   r   r   r   r6   r   r  rm   rn   r   r3   rK   r   r  r   r  r  r  r   Tr   r   r   r   r   r`   r   r_   ra   )r   r   r   r   r.   r   rS   r4   rx   r   ry   rz   r&   rM   rN   r   rK   r  r   r  r   r   r   r   r   r|   r0   r{   r;   rc   rd   	r[   r   r   ri   rh   r   r   r  rj   r\   r\   r]   >test_edit_post_publish_schedule_before_a_scheduled_expire_page9  s     
zKTestPageEdit.test_edit_post_publish_schedule_before_a_scheduled_expire_pagec           	      C   s  t  tjdd }ddddt|d}td| jjfd	}| j	||}| 
|jd
 tjj| jjd}| |j | 
|jd | 
|j|jddd t  tjdd }t  tjdd }ddddt|t|d}| j	||}| 
|jd
 tjj| jjd}| |j | 
|jd | tjj|jdjdd  | jtd| jjfd	|}| j|dt| ddd | j|ddd | j|dt| ddd | j|dt| ddd |j }| jd|ddd d S )Nr   r   r   r   r6   r   r  rm   rn   r   r3   rK   r   r        r  r  r   Tr   r   r`   r   r   r   r   r_   ra   )r   r   r   r   r.   r   rS   r4   rx   r   ry   rz   r&   rM   rN   r   rK   r  r   r  r   r   r   r   r   r{   r0   r|   r;   rc   rd   r  r\   r\   r]   =test_edit_post_publish_schedule_after_a_scheduled_expire_page  s     	
zJTestPageEdit.test_edit_post_publish_schedule_after_a_scheduled_expire_pagec                 C   s   |  ddd ddddd}| jtd	| jjfd
|}| |td| jjfd
 tj	j
| jjd}| |j | |jj|jj d S )NZ	moderatorzmoderator@email.comr   r   r   r6   Submitr9   r;   r:   action-submitrm   rn   r   r3   )Zcreate_superuserrx   r   r   rS   r4   r   rO   r&   rM   rN   r   rL   ry   Zcurrent_workflow_statestatusZSTATUS_IN_PROGRESSr   r\   r\   r]   test_page_edit_post_submit  s(      z'TestPageEdit.test_page_edit_post_submitc                 C   sn   t dddd| _| jj| jd dddd}| jtd	| jjfd
|}| |j	d | 
|jd dd d S )NzHello world 2zhello-world2r7   r8   r<   r6   r  )r9   r:   r!  rm   rn   rp   r   r:   z?The slug 'hello-world' is already in use within the parent page)r&   rS   rO   rP   rx   r   r   r4   ry   rz   r   r   r[   r   rh   r\   r\   r]   !test_page_edit_post_existing_slug$  s(       z.TestPageEdit.test_page_edit_post_existing_slugc                 C   s   ddddd}t d| jjfd}| j||}| |jd | |j	 d	d	d
 | j
|}| |jd | |d | j|dd	d | |d | |t d| jjfd d S )Nr   r   r6   r  r   "wagtailadmin_pages:preview_on_editrn   rp   TZis_validZis_availabletests/simple_page.htmlzI&#39;ve been edited!r   zEdit this pagerm   )r   rS   r4   rx   r   ry   rz   assertJSONEqualr;   rc   rN   r   r{   r|   r[   r   preview_urlrh   r\   r\   r]   test_preview_on_editA  s0      z!TestPageEdit.test_preview_on_editc                 C   sP   t d| jjfd}| j|}| |jd | j|ddd | j|ddd d S )Nr&  rn   rp   z.<title>Preview not available - Wagtail</title>Tr   z;<h1 class="preview-error__title">Preview not available</h1>)r   rS   r4   rx   rN   ry   rz   r{   )r[   r+  rh   r\   r\   r]   #test_preview_on_edit_no_session_keyb  s        z0TestPageEdit.test_preview_on_edit_no_session_keydefaultZBACKENDz-django.core.cache.backends.locmem.LocMemCache)ZCACHESz0django.middleware.cache.FetchFromCacheMiddlewarez-django.middleware.cache.UpdateCacheMiddleware)appendprepend)Z
MIDDLEWAREc                 C   s   ddddd}t d| jjfd}| j|| | j|}| j|dd	d
 d|d< | j|| | j|}| j|dd	d
 dS )z/
        Tests solution to issue #5975
        zI've been edited one time!r   r6   r  r   r&  rn   zI&#39;ve been edited one time!Tr   zI've been edited two times!r9   zI&#39;ve been edited two times!N)r   rS   r4   rx   r   rN   r{   r*  r\   r\   r]   test_preview_does_not_cachex  s      z(TestPageEdit.test_preview_does_not_cacher/  childpage.example.com)ZALLOWED_HOSTSc                 C   s   t jjd| jd ddddd}td| jjfd	}| j||}| |j	d
 | 
|j ddd | j|}| |j	d
 | |d | t |jd jd d S )Nr2  )hostnamerO   r   r   r6   r  r   r&  rn   rp   Tr'  r(  request)r   rM   r   rS   r   r4   rx   r   ry   rz   r)  r;   rc   rN   r   Zfind_for_requestr   r3  r*  r\   r\   r]   test_preview_uses_correct_site  s.     z+TestPageEdit.test_preview_uses_correct_sitec                 C   sJ   d| j _| j   | jtd| j jfd}| |jd | 	|d d S )N2This title only exists on the live database recordrm   rn   rp   )
rS   r9   r   rx   rN   r   r4   ry   rz   r{   r   r\   r\   r]   'test_editor_picks_up_direct_model_edits  s    
 z4TestPageEdit.test_editor_picks_up_direct_model_editsc                 C   s|   d| j _| j   tjj| j jd| _ d| j _| j   | j	t
d| j jfd}| |jd | |d | |d d S )NSome content with a draft editr3   r6  rm   rn   rp   )rS   r;   rQ   r&   rM   rN   r4   r9   r   rx   r   ry   rz   r|   r{   r   r\   r\   r]   Ftest_editor_does_not_pick_up_direct_model_edits_when_draft_edits_exist  s    

 zSTestPageEdit.test_editor_does_not_pick_up_direct_model_edits_when_draft_edits_existc                 C   sp   d| j _d| j _| j   | jtd| j jfd}d}d}| j|ddd	 | j	||dd	 | j||dd	 d S )
Nr8  revised-slug-in-draft-onlyrm   rn   a  <input type="text" name="slug" value="revised-slug-in-draft-only" data-controller="w-slug" data-action="blur-&gt;w-slug#slugify w-sync:check-&gt;w-slug#compare w-sync:apply-&gt;w-slug#urlify:prevent" data-w-slug-compare-as-param="urlify" data-w-slug-allow-unicode-value maxlength="255" aria-describedby="panel-child-promote-child-for_search_engines-child-slug-helptext" required id="id_slug">a{  <input type="text" name="slug" value="hello-world" data-controller="w-slug" data-action="blur-&gt;w-slug#slugify w-sync:check-&gt;w-slug#compare w-sync:apply-&gt;w-slug#urlify:prevent" data-w-slug-compare-as-param="urlify" data-w-slug-allow-unicode-value maxlength="255" aria-describedby="panel-child-promote-child-for_search_engines-child-slug-helptext" required id="id_slug" />z#href="/revised-slug-in-draft-only/"Tr   )
rS   r;   r:   rQ   rx   rN   r   r4   r|   r{   r[   rh   Zinput_field_for_draft_slugZinput_field_for_live_slugr\   r\   r]   @test_editor_page_shows_live_url_in_status_when_draft_edits_exist  s     
  zMTestPageEdit.test_editor_page_shows_live_url_in_status_when_draft_edits_existc                 C   sp   d| j _d| j _| j   | jtd| j jfd}d}d}| j|ddd	 | j	||dd	 | j||dd	 d S )
NzThe other side of Marsr:  rm   rn   a  <input type="text" name="slug" value="revised-slug-in-draft-only" data-controller="w-slug" data-action="blur-&gt;w-slug#slugify w-sync:check-&gt;w-slug#compare w-sync:apply-&gt;w-slug#urlify:prevent" data-w-slug-compare-as-param="urlify" data-w-slug-allow-unicode-value maxlength="255" aria-describedby="panel-child-promote-child-common_page_configuration-child-slug-helptext" required id="id_slug" />a  <input type="text" name="slug" value="mars-landing" data-controller="w-slug" data-action="blur-&gt;w-slug#slugify w-sync:check-&gt;w-slug#compare w-sync:apply-&gt;w-slug#urlify:prevent" data-w-slug-compare-as-param="urlify" data-w-slug-allow-unicode-value maxlength="255" aria-describedby="panel-child-promote-child-common_page_configuration-child-slug-helptext" required id="id_slug" />z4href="/revised-slug-in-draft-only/pointless-suffix/"Tr   )
rW   rG   r:   rQ   rx   rN   r   r4   r|   r{   r;  r\   r\   r]   Gtest_editor_page_shows_custom_live_url_in_status_when_draft_edits_exist  s     
  zTTestPageEdit.test_editor_page_shows_custom_live_url_in_status_when_draft_edits_existc              	      s^    fdd}  d|   jtd jjfd}W 5 Q R X  |jd  |jd d S )Nc                    s&     | t  |j jj tdS NzOverridden!r   r   ry   r4   rS   r	   r4  r   r[   r\   r]   	hook_func  s    z:TestPageEdit.test_before_edit_page_hook.<locals>.hook_funcbefore_edit_pagerm   rn   rp      Overridden!)	register_hookrx   rN   r   rS   r4   ry   rz   r;   r[   rB  rh   r\   rA  r]   test_before_edit_page_hook  s    z'TestPageEdit.test_before_edit_page_hookc              	      s    fdd}  d|0 ddddd} jtd	 jjfd
|}W 5 Q R X  |jd  |jd  t	j
j jjdjd d S )Nc                    s&     | t  |j jj tdS r>  r?  r@  rA  r\   r]   rB  $  s    z?TestPageEdit.test_before_edit_page_hook_post.<locals>.hook_funcrC  r   r   r   r   r   rm   rn   rp   rD  r3   r5   rE  rx   r   r   rS   r4   ry   rz   r;   r   rM   rN   r9   r[   rB  r   rh   r\   rA  r]   test_before_edit_page_hook_post#  s    z,TestPageEdit.test_before_edit_page_hook_postc              	      s    fdd}  d|0 ddddd} jtd	 jjfd
|}W 5 Q R X  |jd  |jd  t	j
j jjdjd d S )Nc                    s&     | t  |j jj tdS r>  r?  r@  rA  r\   r]   rB  =  s    z9TestPageEdit.test_after_edit_page_hook.<locals>.hook_funcZafter_edit_pager   r   r   r   r   rm   rn   rp   rD  r3   rH  rI  r\   rA  r]   test_after_edit_page_hook<  s"     z&TestPageEdit.test_after_edit_page_hookc              	      s    fdd}  d|0 ddddd} jtd	 jjfd
|}W 5 Q R X  |jd  |jd  j	    jj
td d S )Nc                    s&     | t  |j jj tdS r>  r?  r@  rA  r\   r]   rB  X  s    z7TestPageEdit.test_after_publish_page.<locals>.hook_funcZafter_publish_pager   r   r   r   r   rm   rn   rp   rD  rK   rE  rx   r   r   rS   r4   ry   rz   r;   refresh_from_dbr  _rI  r\   rA  r]   test_after_publish_pageW  s    
z$TestPageEdit.test_after_publish_pagec              	      s    fdd}  d|0 ddddd} jtd	 jjfd
|}W 5 Q R X  |jd  |jd  j	    jj
td d S )Nc                    s&     | t  |j jj tdS r>  r?  r@  rA  r\   r]   rB  p  s    z8TestPageEdit.test_before_publish_page.<locals>.hook_funcZbefore_publish_pager   r   r   r   r   rm   rn   rp   rD  zlive + draftrL  rI  r\   rA  r]   test_before_publish_pageo  s    
z%TestPageEdit.test_before_publish_pagec              	   C   sr   dd }|  d|  | jtd| jjfd}W 5 Q R X | |j}|d}| 	| |d}| 	| d S )Nc                 S   s:   t | D ],\}}|jdkr| | | d|  q6qd S )Nr   r   )	enumeraterT   popinsert)
menu_itemsr4  r   indexitemr\   r\   r]   rB    s
    

zFTestPageEdit.test_override_default_action_menu_item.<locals>.hook_funcconstruct_page_action_menurm   rn   z!.w-dropdown__content .action-savez,.w-dropdown-button > [name="action-publish"])
rE  rx   rN   r   rW   r4   re   r;   rf   rg   )r[   rB  rh   rk   Zsave_buttonZpublish_buttonr\   r\   r]   &test_override_default_action_menu_item  s    


z3TestPageEdit.test_override_default_action_menu_itemc              	   C   sJ   dd }|  d|  | jtd| jjfd}W 5 Q R X | |d d S )Nc                 S   s"   | D ]}|j dkrd|_ qqd S )Nr   Foobar)rT   label)rT  r4  r   rV  r\   r\   r]   rB    s    
zLTestPageEdit.test_override_publish_action_menu_item_label.<locals>.hook_funcrW  rm   rn   rY  )rE  rx   rN   r   rW   r4   r{   rF  r\   r\   r]   ,test_override_publish_action_menu_item_label  s    z9TestPageEdit.test_override_publish_action_menu_item_labelc                 C   s   | j jdd}| jtd|jgd}| |jd | |d d | |d | 	|d	 td| j jgd}| j|d
| ddd d S )Nznew-event-pageZupdate_slugrm   rn   rp   rq   rr   rs   z"wagtailadmin/pages/edit_alias.htmlz)<a class="button button-secondary" href="z">Edit original page</a>Tr   )
rV   create_aliasrx   rN   r   r4   ry   rz   r{   r   )r[   
alias_pagerh   Zoriginal_page_edit_urlr\   r\   r]   test_edit_alias_page  s"     
z!TestPageEdit.test_edit_alias_pagec                 C   sF   | j jdd}dddd}| jtd|jgd|}| |jd	 d S )
Nznew-child-pager\  r   r   r6   r   rm   rn   i  )rS   r]  rx   r   r   r4   ry   rz   )r[   r^  r   rh   r\   r\   r]   test_post_edit_alias_page  s     z&TestPageEdit.test_post_edit_alias_pagec                 C   s   d| j _| j   tjjdd | jtd| j j	fd}| 
|jd ddd	d
}| jtd| j j	fd|}| |td| j j	fd dS )q
        Verify that changing LANGUAGE_CODE with no corresponding database change does not break editing
        zHello world updateddeZlanguage_coderm   rn   rp   r   r   r6   r   N)rS   r9   rQ   r   rM   r   rx   rN   r   r4   ry   rz   r   r   r[   rh   r   r\   r\   r]   $test_edit_after_change_language_code  s&    
  z1TestPageEdit.test_edit_after_change_language_codec                 C   s   t jjdd tjj| jjd  | j	
td| jjfd}| |jd ddd	d
}| j	td| jjfd|}| |td| jjfd dS )ra  rb  rc  r   rm   rn   rp   r   r   r6   r   N)r   rM   r   r   r   r   rS   r4   deleterx   rN   r   ry   rz   r   r   rd  r\   r\   r]   6test_edit_after_change_language_code_without_revisions  s$      zCTestPageEdit.test_edit_after_change_language_code_without_revisionsc              	   C   sN   | j td| jjfd | d  | j td| jjfd W 5 Q R X d S )Nrm   rn   #   )rx   rN   r   rV   r4   assertNumQueriesrA  r\   r\   r]   'test_page_edit_num_queries_as_superuser  s
    z4TestPageEdit.test_page_edit_num_queries_as_superuserc              	   C   s~   | j ddd}|jtjjdd | jdd | jtd| j	j
fd | d	  | jtd| j	j
fd W 5 Q R X d S )
Nr   r   r   r   r   r   rm   rn   '   )r   r   r   r   rM   rN   rY   rx   r   rV   r4   ri  )r[   r   r\   r\   r]   $test_page_edit_num_queries_as_editor  s    z1TestPageEdit.test_page_edit_num_queries_as_editor)=__name__
__module____qualname__r   r^   rl   r   r   r   r   r   r   r   r   patchr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r  r  r#  r%  r,  r-  r   r1  r5  r7  r9  r<  r=  rG  rJ  rK  rO  rP  rX  r[  r_  r`  re  rg  rj  rl  r\   r\   r\   r]   r1   6   s   < E

"PGP/'D<*KJZLdeh! 
 !
r1   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestPageEditReorderingc                 C   sj   t jjdd| _tddddddd	| _td
ddtdddtdddg| j_| jj| jd | 	 | _
d S )Nr2   r3   r@   rA   rB   rC   rD   rE   rF   1234567r`   )captionZ
sort_order7654321abcdefgrv   r<   )r   rM   rN   rO   r!   rV   r"   carousel_itemsrP   rY   rZ   rA  r\   r\   r]   r^   ,  s    	


zTestPageEditReordering.setUpc                 C   s6   |j d jd jd }dd |jD }| || d S )NZedit_handlerr   	   c                 S   s   g | ]}|j jjqS r\   )r   r=   rs  ).0childr\   r\   r]   
<listcomp>E  s     z6TestPageEditReordering.check_order.<locals>.<listcomp>)r   childrenry   )r[   rh   Zexpected_orderZinline_panelorderr\   r\   r]   check_orderC  s    z"TestPageEditReordering.check_orderc                 C   s>   | j td| jjfd}| |jd | |dddg d S )Nrm   rn   rp   rr  rt  ru  )rx   rN   r   rV   r4   ry   rz   r}  r   r\   r\   r]   
test_orderH  s
    z!TestPageEditReordering.test_orderc                 C   s  dddddddddddddddd	dd	| j j d j| j j d jd
| j j d j| j j d jd	| j j d
 j| j j d
 jdd}| jtd| j jfd|}| |td| j jfd | j	td| j jfd}| 
|jd | |dddg d S )Nr@   rA   
01/01/2014$10rC   	somewherer   r   rv   r2   r`   r9   r:   rJ   rI   rH   rG   related_links-INITIAL_FORMSrelated_links-MAX_NUM_FORMSrelated_links-TOTAL_FORMSspeakers-INITIAL_FORMSspeakers-MAX_NUM_FORMSspeakers-TOTAL_FORMShead_counts-INITIAL_FORMShead_counts-MAX_NUM_FORMShead_counts-TOTAL_FORMScarousel_items-INITIAL_FORMScarousel_items-MAX_NUM_FORMScarousel_items-TOTAL_FORMSzcarousel_items-0-idzcarousel_items-0-captionzcarousel_items-0-ORDERzcarousel_items-1-idzcarousel_items-1-captionzcarousel_items-1-ORDERzcarousel_items-2-idzcarousel_items-2-captionzcarousel_items-2-ORDERrm   rn   rp   ru  rr  rt  )rV   rv  allr4   rs  rx   r   r   r   rN   ry   rz   r}  r$  r\   r\   r]   test_reorderP  sR      z#TestPageEditReordering.test_reorderc                 C   s   dddddddddddddddd	dd	| j j d j| j j d jd
| j j d j| j j d jd	| j j d
 j| j j d
 jdd}| jtd| j jfd|}| |j	d | 
|dddg d S )N rA   r  r  rC   r  r   r   rv   r2   r`   r  rm   rn   rp   ru  rr  rt  )rV   rv  r  r4   rs  rx   r   r   ry   rz   r}  r$  r\   r\   r]   "test_reorder_with_validation_error  sD     z9TestPageEditReordering.test_reorder_with_validation_errorN)rm  rn  ro  r^   r}  r~  r  r  r\   r\   r\   r]   rq  +  s
   /rq  c                   @   s   e Zd Zdd ZdS )TestIssue197c                 C   s   t jjdd| _| jjtddddd| _|  | _dddd	d
}| j	
td| jjfd|}| |td| jjfd tjj| jjd}| d|j  | d|j  d S )Nr2   r3   zTagged pageztagged-pageF)r9   r:   rK   r<   zhello, worldr   )r9   r:   tagsr   rm   rn   r   r7   Zworld)r   rM   rN   rO   rP   r*   Ztagged_pagerY   rZ   rx   r   r   r4   r   r   r  Zslugsr[   r   rh   r   r\   r\   r]   test_issue_197  s2    	
  zTestIssue197.test_issue_197N)rm  rn  ro  r  r\   r\   r\   r]   r    s   r  c                   @   sJ   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S )TestChildRelationsOnSuperclass	test.jsonc                 C   sV   t jjdd| _tjjdd| _tddt| jdgd| _| jj	| jd | 
  d S )	Nr2   r3   r`   My lovely indexmy-lovely-index)advert)r9   r:   advert_placementsr<   )r   rM   rN   rO   r   test_advertr(   r   
index_pagerP   rY   rA  r\   r\   r]   r^     s    z$TestChildRelationsOnSuperclass.setUpc                 C   sH   | j tddd| jjfd}| |jd | |d | |d d S )Nwagtailadmin_pages:addtestsstandardindexrn   rp   Adverts id_advert_placements-TOTAL_FORMS)rx   rN   r   rO   r4   ry   rz   r{   r   r\   r\   r]   test_get_create_form  s    z3TestChildRelationsOnSuperclass.test_get_create_formc              	   C   s   ddddddddd}| j td	d
d| jjfd|}tjj| jjddj	}| 
|td|jfd | |j d | |j jjd d S )N
New index!	new-index101000yellowr  r9   r:   advert_placements-TOTAL_FORMSadvert_placements-INITIAL_FORMSadvert_placements-MAX_NUM_FORMSadvert_placements-0-advertadvert_placements-0-colouradvert_placements-0-idr  r  r  rn   Zpath__startswithr:   rm   r`   r  )rx   r   r   rO   r4   r   rM   rN   r   specificr   ry   r  rb   firstr  textr  r\   r\   r]   test_post_create_form  s4    
	  z4TestChildRelationsOnSuperclass.test_post_create_formc              	   C   s`   ddddddddd}| j tdd	d
| jjfd|}| |jd | |d | |d d S )Nr  r  r  r  r  r  r  r  r  r  rn   rp   This field is required.r   )rx   r   r   rO   r4   ry   rz   r{   r$  r\   r\   r]   6test_post_create_form_with_validation_error_in_formset	  s&    
	zUTestChildRelationsOnSuperclass.test_post_create_form_with_validation_error_in_formsetc                 C   s`   | j td| jjfd}| |jd | |d | |d | |d | j|ddd	 d S )
Nrm   rn   rp   r  r  zi<div class="chooser__title" data-chooser-title id="id_advert_placements-0-advert-title">test_advert</div>zd<input type="hidden" name="advert_placements-0-advert" value="1" id="id_advert_placements-0-advert">Tr   )rx   rN   r   r  r4   ry   rz   r{   r   r\   r\   r]   test_get_edit_form'	  s    z1TestChildRelationsOnSuperclass.test_get_edit_formc                 C   s   ddddddd| j j jdddd	d
}| jtd| j jfd|}| |td| jjfd t	j
j| j jdj}| |j d | |j d jjd | |j d jjd d S )Nr  r  2r  r  r  purpler  r   )r9   r:   r  r  r  r  r  r  zadvert_placements-1-advertzadvert_placements-1-colourzadvert_placements-1-idr   rm   rn   r   r3   r2   r   r  r`   )r  r  r  r4   rx   r   r   r   rO   r   rM   rN   r  ry   rb   r  r  r  r  r\   r\   r]   test_post_edit_form;	  s2      z2TestChildRelationsOnSuperclass.test_post_edit_formc              
   C   sh   ddddddd| j j jdd	}| jtd| j jfd	|}| |jd
 | 	|d | 	|d d S )Nr  r  r  r  r  r   )	r9   r:   r  r  r  r  r  r  r   rm   rn   rp   r  r   )
r  r  r  r4   rx   r   r   ry   rz   r{   r$  r\   r\   r]   4test_post_edit_form_with_validation_error_in_formsetY	  s"     zSTestChildRelationsOnSuperclass.test_post_edit_form_with_validation_error_in_formsetN)rm  rn  ro  fixturesr^   r  r  r  r  r  r  r\   r\   r\   r]   r    s    r  c                   @   s    e Zd ZdZdd Zdd ZdS )TestIssue2492a  
    The publication submission message generation was performed using
    the Page class, as opposed to the specific_class for that Page.
    This test ensures that the specific_class url method is called
    when the 'view live' message button is created.
    c                 C   sl   t jjdd| _tddddtj td d d}| jj|d	 |	 
  tjj|jd| _|  | _d S )
Nr2   r3   z
Test Eventz
test-eventztest location10r   )r9   r:   rG   rI   rJ   rH   r<   )r   rM   rN   rO   r'   r   r   r   rP   rQ   rR   r4   rS   rY   rZ   r[   rS   r\   r\   r]   r^   x	  s    
zTestIssue2492.setUpc                 C   s   d| j j| j j| j j| j j| j j| j jddddddddddddddddd}| jjt	d| j j
fd|dd}tjj| j j
dj}|jd	 D ]}| d
| d
|j  qqd S )Nr   r   )r   r9   rJ   r:   rH   rG   rI   r  r  carousel_items-MIN_NUM_FORMSr  r  r  speakers-MIN_NUM_FORMSr  r  r  related_links-MIN_NUM_FORMSr  r  r  head_counts-MIN_NUM_FORMSr  rm   rn   Tr   r3   r   ")rS   r9   rJ   r:   rH   rG   rI   rx   r   r   r4   r'   rM   rN   urlr   r   r   )r[   r   rh   new_urlr   r\   r\   r]   test_page_edit_post_publish_url	  sB    z-TestIssue2492.test_page_edit_post_publish_urlN)rm  rn  ro  __doc__r^   r  r\   r\   r\   r]   r  p	  s   r  c                       sP   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
  ZS )TestIssue3982z
    Pages that are not associated with a site, and thus do not have a live URL,
    should not display a "View live" link in the flash message after being
    edited.
    c                    s   t    |   d S )N)superr^   rY   rA  	__class__r\   r]   r^   	  s    
zTestIssue3982.setUpc                 C   sb   | j jtddd|jfdddddd	d
d}| |td|jfd tj }| |j	 ||fS )Nr  r  Z
simplepagern   Hello, world!r   r6   rR   r   Tr   r   )
rx   r   r   r   r   r&   rM   rN   r   rK   )r[   parentrh   r   r\   r\   r]   _create_page	  s     
 
zTestIssue3982._create_pagec                    sJ   |  tjjdd\} |  j | t fdd|jd D  dS )zt
        Create a page under the site root, check the flash message has a valid
        "View live" button.
        r2   r   c                 3   s$   | ]}d |j ko j|j kV  qdS z	View liveNr   r  rx  r   r   r\   r]   	<genexpr>	  s   z7TestIssue3982.test_create_accessible.<locals>.<genexpr>r   N)	r  r   rM   rN   rg   r  r   anyr   r   r\   r   r]   test_create_accessible	  s    z$TestIssue3982.test_create_accessiblec                 C   sF   |  tjjdd\}}| |j | tdd |jd D  dS )z}
        Create a page outside of the site root, check the flash message does
        not have a "View live" button.
        r`   r  c                 s   s   | ]}d |j kV  qdS r  r   r  r\   r\   r]   r  	  s   z9TestIssue3982.test_create_inaccessible.<locals>.<genexpr>r   N)	r  r   rM   rN   r   r  r   r  r   r[   rh   r   r\   r\   r]   test_create_inaccessible	  s    z&TestIssue3982.test_create_inaccessiblec                 C   sx   |j tdddd}| jjtd|jfdddddd	d
d}| |td|jfd tjj|jd}| 	|j
 ||fS )Nr  r   )r9   r;   r<   rm   rn   r6   rR   r   Tr   r   r  )rP   r&   rx   r   r   r   r   rM   rN   r   rK   )r[   r  r   rh   r\   r\   r]   
_edit_page	  s&    

 zTestIssue3982._edit_pagec                    sJ   |  tjjdd\} |  j | t fdd|jd D  dS )zr
        Edit a page under the site root, check the flash message has a valid
        "View live" button.
        r2   r  c                 3   s$   | ]}d |j ko j|j kV  qdS r  r  r  r   r\   r]   r  
  s   z5TestIssue3982.test_edit_accessible.<locals>.<genexpr>r   N)	r  r   rM   rN   rg   r  r   r  r   r   r\   r   r]   test_edit_accessible	  s    z"TestIssue3982.test_edit_accessiblec                 C   sF   |  tjjdd\}}| |j | tdd |jd D  dS )z{
        Edit a page outside of the site root, check the flash message does
        not have a "View live" button.
        r`   r  c                 s   s   | ]}d |j kV  qdS r  r  r  r\   r\   r]   r  
  s   z7TestIssue3982.test_edit_inaccessible.<locals>.<genexpr>r   N)	r  r   rM   rN   r   r  r   r  r   r  r\   r\   r]   test_edit_inaccessible
  s    z$TestIssue3982.test_edit_inaccessible)rm  rn  ro  r  r^   r  r  r  r  r  r  __classcell__r\   r\   r  r]   r  	  s   r  c                   @   s:   e Zd ZdgZdd Zdd Zdd Zdd	 Zd
d ZdS )TestParentalM2Mr  c                 C   sN   t jjdd| _t jjdd| _|  | _tjjdd| _	tjjdd| _
d S )N/home/events/Zurl_path/home/events/christmas/ZHolidayr   zMen with beards)r   rM   rN   events_indexchristmas_pagerY   rZ   r    r   holiday_categorymen_with_beards_categoryrA  r\   r\   r]   r^   
  s    
zTestParentalM2M.setUpc                 C   s   dddddddddddddddddddddd| j j| jjgd}| jtd	d
d| jjfd|}tjj	dd}| 
|td|jfd | }| | j |j  | | j|j  d S )NPresidents' Day
2017-02-20presidents-dayrC   America$1r   r9   rJ   r:   rH   rG   rI   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  
categoriesr  r  	eventpagern   /home/events/presidents-day/r  rm   )r  r4   r  rx   r   r   r  r!   rM   rN   r   get_latest_revision_as_objectr   r  r  )r[   r   rh   created_pagecreated_revisionr\   r\   r]   test_create_and_save'
  sN     z$TestParentalM2M.test_create_and_savec                 C   s   ddddddddddddddddddddddd| j j| jjgd	}| jtd
dd| jjfd|}| |td| jjfd tj	j
dd}| | j |j  | | j|j  d S )Nr   r  r  r  rC   r  r  r   r   r9   rJ   r:   rH   rG   rI   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rn   r   r  r  )r  r4   r  rx   r   r   r  r   r!   rM   rN   r   r  r  )r[   r   rh   r  r\   r\   r]   test_create_and_publishQ
  sN     z'TestParentalM2M.test_create_and_publishc                 C   s   dddddddddddddddddddddd| j j| jjgd}| jtd	| jjfd
|}| |td	| jjfd
 tj	j
| jjd}| }| | j |j  | | j|j  | d|j  d S )N	Christmas
2017-12-25	christmasrC   The North PoleFreer   r  rm   rn   r3   )r  r4   r  rx   r   r   r  r   r!   rM   rN   r  r   r  r  ry   rb   )r[   r   rh   updated_pager  r\   r\   r]   test_edit_and_save{
  sJ     z"TestParentalM2M.test_edit_and_savec                 C   s   ddddddddddddddddddddddd| j j| jjgd	}| jtd
| jjfd|}| |td| jjfd t	j
j| jjd}| d|j  | | j |j  | | j|j  d S )Nr   r  r  r  rC   r  r  r   r  rm   rn   r   r3   r2   )r  r4   r  rx   r   r   r  r   r  r!   rM   rN   ry   r  rb   r   r  )r[   r   rh   r  r\   r\   r]   test_edit_and_publish
  sJ     z%TestParentalM2M.test_edit_and_publishN)	rm  rn  ro  r  r^   r  r  r  r  r\   r\   r\   r]   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 )TestValidationErrorMessagesr  c                 C   s.   t jjdd| _t jjdd| _|  | _d S )Nr  r  r  )r   rM   rN   r  r  rY   rZ   rA  r\   r\   r]   r^   
  s    z!TestValidationErrorMessages.setUpc                 C   s   ddddddddddddddddddddddd}| j td	| jjfd
|}| |jd | |d | j|ddd | j|ddd dS )zSField errors should be shown against the relevant fields, not in the header messager  r  r  rC   r  r  r   )r9   rJ   r:   rH   rG   rI   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rm   rn   rp   4The page could not be saved due to validation errorserror-messager`   rw   zThis field is requiredNrx   r   r   r  r4   ry   rz   r{   r$  r\   r\   r]   test_field_error
  sD     z,TestValidationErrorMessages.test_field_errorc                 C   s~   dddddddddddddddddddddddd	}| j td
| jjfd|}| |jd | |d | j|ddd dS )z6Non-field errors should be shown in the header messager  r  
2017-12-24r  rC   r  r  r   r9   rJ   date_tor:   rH   rG   rI   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rm   rn   rp   r   2<li>The end date must be after the start date</li>r`   rw   Nr  r$  r\   r\   r]   test_non_field_error
  sL       z0TestValidationErrorMessages.test_non_field_errorc                 C   s   dddddddddddddddddddddddd	}| j td
| jjfd|}| |jd | |d | j|ddd | j|ddd | j|ddd dS )z
        If both field and non-field errors exist, all errors should be shown in the header message
        with appropriate context to identify the field; and field errors should also be shown
        against the relevant fields.
        r  r  r  r  rC   r  r  r   r  rm   rn   rp   r   r  r`   rw   r  z'<li>Title: This field is required.</li>Nr  r$  r\   r\   r]   test_field_and_non_field_error$  sX         z:TestValidationErrorMessages.test_field_and_non_field_errorN)rm  rn  ro  r  r^   r  r  r	  r\   r\   r\   r]   r  
  s
   '(r  c                   @   s*   e Zd ZdgZdd Zdd Zdd ZdS )	TestNestedInlinePanelr  c                 C   sb   t jjdd| _tjjdd| _| jj | _| jj	j
dtdddd | j  |  | _d S )	Nr  r  r  zBeard Of The Yeari     r  rT   date_awarded)r   rM   rN   r  r!   r  speakersr  speakerawardsr   r   r   r   rY   rZ   rA  r\   r\   r]   r^   [  s     
zTestNestedInlinePanel.setUpc                 C   st   | j td| jjfd}| |jd | j|dddd | j|dddd | j|d	d
dd | j|dddd d S )Nrm   rn   rp   z~<input type="text" name="speakers-0-awards-0-name" value="Beard Of The Year" maxlength="255" id="id_speakers-0-awards-0-name">r`   T)rb   rj   zj<input type="hidden" name="speakers-0-awards-TOTAL_FORMS" value="1" id="id_speakers-0-awards-TOTAL_FORMS">zm<input type="text" name="speakers-0-awards-1-name" value="" maxlength="255" id="id_speakers-0-awards-1-name">r   z<input type="text" name="speakers-0-awards-0-date_awarded" value="1997-12-25" autocomplete="off" id="id_speakers-0-awards-0-date_awarded">)rx   rN   r   r  r4   ry   rz   r{   r   r\   r\   r]   r  e  s8    z(TestNestedInlinePanel.test_get_edit_formc                 C   s
  t dddddddtg t| jjddt| jj jdd	d
dddgdddgddtg tg dd}| jtd| j	jfd|}| 
|td| jjfd tjjdd}| |j jd |j j }| t|d | |d jd | |d jd d S )Nr  r  r  rC   r  r  ZJeffzBeard Of The Centuryz
1997-12-25)r4   rT   r  z Bobsleigh Olympic gold medallistz
2018-02-01r  r`   )initial)r4   
first_name	last_namer  r   )r9   rJ   r  r:   rH   rG   rI   rv  r  Zrelated_linksZhead_countsr   rm   rn   r   r  r  r2   r   )r-   r,   r  r4   r  r  rx   r   r   r  r   r  r!   rM   rN   ry   r  r  r  lenrT   )r[   r   rh   Znew_christmas_pager  r\   r\   r]   test_post_edit  s^    ' z$TestNestedInlinePanel.test_post_editN)rm  rn  ro  r  r^   r  r  r\   r\   r\   r]   r
  X  s   
"r
  TZWAGTAIL_I18N_ENABLEDc                   @   s<   e Zd ZdgZdd Zdd Zedddd	 Zd
d ZdS )TestLocaleSelectorr  c                 C   sB   t jjdd| _tjjdd| _| jj| jdd| _| 	 | _
d S )Nr  r  frrc  T)Zcopy_parents)r!   rM   rN   r  r   r   Z	fr_localeZcopy_for_translationtranslated_christmas_pagerY   rZ   rA  r\   r\   r]   r^     s     zTestLocaleSelector.setUpc                 C   sP   | j td| jjgd}| |d td| jjgd}| |d| d d S )Nrm   rn   id="status-sidebar-english"href="r  )rx   rN   r   r  r4   r{   r  r[   rh   edit_translation_urlr\   r\   r]   test_locale_selector  s     z'TestLocaleSelector.test_locale_selectorFr  c                 C   sP   | j td| jjgd}| |d td| jjgd}| |d| d d S )Nrm   rn   zPage Locale:r  r  )rx   rN   r   r  r4   r|   r  r  r\   r\   r]   3test_locale_selector_not_present_when_i18n_disabled  s     zFTestLocaleSelector.test_locale_selector_not_present_when_i18n_disabledc                 C   s   t jjdd}tjjdd}tjj||dd d| j_| jj	t
jjdd	d
 | jj	| | j  | jtd| jjgd}| |d td| jjgd}| |d| d d S )Nr  r  Z
Moderatorsr   Zchange)groupr   Zpermission_typeFr   r   r   rm   rn   r  r  r  )r   rM   rN   r   r   r   rZ   r   r   r   r   r   r   rx   r   r  r4   r{   r  r|   )r[   Zen_events_indexr   rh   r  r\   r\   r]   ;test_locale_dropdown_not_present_without_permission_to_edit  s2     
 zNTestLocaleSelector.test_locale_dropdown_not_present_without_permission_to_editN)	rm  rn  ro  r  r^   r  r   r  r!  r\   r\   r\   r]   r    s   
r  c                   @   sX   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zedddd Z	edddd Z
dS )TestPageSubscriptionSettingsc                 C   sX   t jjdd| _tdddd}| jj|d |   tjj|jd| _	| 
 | _d S )Nr2   r3   r5   r6   r7   r8   r<   )r   rM   rN   rO   r&   rP   rQ   rR   r4   rS   rY   rZ   r  r\   r\   r]   r^     s    z"TestPageSubscriptionSettings.setUpc                 C   sX   | j td| jjgd}| |jd | |d | t	j
j| j| jdd  d S )Nrm   rn   rp   R<input type="checkbox" name="comment_notifications" id="id_comment_notifications">Fr   rZ   comment_notifications)rx   rN   r   rS   r4   ry   rz   r{   r   r   rM   r   rZ   r   r   r\   r\   r]   'test_comment_notifications_switched_off  s      zDTestPageSubscriptionSettings.test_comment_notifications_switched_offc                 C   sN   t jj| j| jdd | jtd| jjgd}| 	|j
d | |d d S )NTr$  rm   rn   rp   zZ<input type="checkbox" name="comment_notifications" id="id_comment_notifications" checked>)r   rM   r   rS   rZ   rx   rN   r   r4   ry   rz   r{   r   r\   r\   r]   &test_comment_notifications_switched_on%  s      zCTestPageSubscriptionSettings.test_comment_notifications_switched_onc                 C   s   ddddd}| j td| jjgd|}| |td| jjgd tjj| j	j
ddj}|j }| |j| j | |j d S )	Nr   r   r6   onr9   r;   r:   r%  rm   rn   r  )rx   r   r   rS   r4   r   r   rM   rN   rO   r   r  Zsubscribersry   rZ   r   r%  )r[   r   rh   r   subscriptionr\   r\   r]   0test_post_with_comment_notifications_switched_on4  s(       
zMTestPageSubscriptionSettings.test_post_with_comment_notifications_switched_onc                 C   sp   t jj| j| jdd}dddd}| jtd| jjgd|}| 	|td| jjgd |
  | |j d S )	NTr$  r   r   r6   r   rm   rn   )r   rM   r   rS   rZ   rx   r   r   r4   r   rM  r   r%  )r[   r*  r   rh   r\   r\   r]   1test_post_with_comment_notifications_switched_offK  s&        zNTestPageSubscriptionSettings.test_post_with_comment_notifications_switched_offFZWAGTAILADMIN_COMMENTS_ENABLEDc                 C   sD   | j td| jjgd}| |d | |jd | |d d S )Nrm   rn   z!data-side-panel-toggle="comments"rp   r#  )rx   rN   r   rS   r4   r|   ry   rz   r   r\   r\   r]   test_comments_disableda  s    z3TestPageSubscriptionSettings.test_comments_disabledc                 C   sZ   ddddd}| j td| jjgd|}| |td| jjgd | tj	 j
 d S )Nr   r   r6   r(  r)  rm   rn   )rx   r   r   rS   r4   r   r   r   rM   rN   r%  r$  r\   r\   r]   test_post_comments_disabledm  s      z8TestPageSubscriptionSettings.test_post_comments_disabledN)rm  rn  ro  r^   r&  r'  r+  r,  r   r.  r/  r\   r\   r\   r]   r"    s   
r"  c                   @   s   e Zd ZdZdd 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dd Zdd Zdd Zdd Zdd Zd S )!TestCommentingz\
    Tests both the comment notification and audit logging logic of the edit page view.
    c                 C   s   t jjdd| _tdddd}| jj|d |   tjj|jd| _	| 
 | _| d| _| d	| _| d
| _| d| _tjj| j	| jdd tjj| j	| jdd tjj| j| jdd}tjj| j|dd d S )Nr2   r3   r5   r6   r7   r8   r<   
subscriberznon-subscriberznon-subscriber-2znever-emailedTr$  z	a comment)r   rZ   r  za reply)rZ   commentr  )r   rM   rN   rO   r&   rP   rQ   rR   r4   rS   rY   rZ   r   r1  non_subscribernon_subscriber_2never_emailed_userr   r   r   r   )r[   rS   Zcomment_on_other_pager\   r\   r]   r^     sD    
        zTestCommenting.setUpc                 C   s    |  | jjdd tjD  d S )Nc                 S   s   g | ]}|j D ]}|qqS r\   to)rx  emailr7  r\   r\   r]   rz    s       z>TestCommenting.assertNeverEmailedWrongUser.<locals>.<listcomp>)ZassertNotInr5  r8  r   outboxrA  r\   r\   r]   assertNeverEmailedWrongUser  s    z*TestCommenting.assertNeverEmailedWrongUserc                 C   sr   | j td| jjgd}| |jd | |j}|	d}| d|d  | 
d|d  | d	|d
  d S )Nrm   rn   rp   [data-edit-form]page-edit-formr4   w-initdata-controllerzw-comments:initdata-w-init-event-valuerx   rN   r   rS   r4   ry   rz   re   r;   rf   r   r[   rh   rk   r   r\   r\   r]    test_comments_enabled_by_default  s    
z/TestCommenting.test_comments_enabled_by_defaultFr-  c                 C   sr   | j td| jjgd}| |jd | |j}|	d}| d|d  | 
d|d  | d	|d
  d S )Nrm   rn   rp   r;  r<  r4   r=  r>  r  r?  r@  rA  r\   r\   r]   r.    s    
z%TestCommenting.test_comments_disabledc                 C   sn  dddddddddddddddddd	}| j td
| jjgd|}| |td
| jjgd | j  | jj }| 	|j
d | 	ttjd |   | 	tjd j| jjg | 	tjd jd | dtjd j tjjdd}| 	|j| jj | 	|j| j | 	|j| j  | 	|jd d |j | 	|jd d |j | 	|jd d |j
 d S )Nr   r   r6   r  r  r  r9   A test commentr9   r;   r:   r   r   r   r   comments-0-DELETEcomments-0-resolvedcomments-0-idcomments-0-contentpathcomments-0-textcomments-0-positioncomments-0-replies-TOTAL_FORMS comments-0-replies-INITIAL_FORMS comments-0-replies-MIN_NUM_FORMS comments-0-replies-MAX_NUM_FORMSrm   rn   r`   r   Htest@email.com has updated comments on "I've been edited! (simple page)"z#New comments:
 - "A test comment"

zwagtail.comments.createactionr2  r4   contentpathr  )rx   r   r   rS   r4   r   rM  wagtail_admin_commentsrN   ry   r  r  r   r9  r:  r7  r1  r8  subjectr   r   r   rM   r   page_ptrrZ   revisionr   datarR  )r[   r   rh   r2  	log_entryr\   r\   r]   test_new_comment  sX      

zTestCommenting.test_new_commentc                 C   s>  t jj| j| jddd}ddddddd	d	d	t|jdd
d	ddddd}| jt	d| jjgd|}| 
|t	d| jjgd | j  |  | |jd
 | ttjd tjjdd}| |j| jj | |j| j | |j| j  | |jd d |j | |jd d |j | |jd d |j d S )NrC  r9   r   rZ   r  rR  r   r   r6   r  r  r  EditedrD  rm   rn   r   wagtail.comments.editrP  r2  r4   rR  r  )r   rM   r   rS   rZ   r   r4   rx   r   r   r   rM  ry   r  r  r   r9  r   rN   r   rU  rV  r   rW  rR  r[   r2  r   rh   rX  r\   r\   r]   test_edit_comment  sV      
z TestCommenting.test_edit_commentc                 C   s   t jj| j| jddd}ddddddd	d	d	t|jdd
d	ddddd}| jt	d| jjgd|}| 
|jd jd jddgig | j  |  | |jd
 | tjjdd  d S )NrC  r9   rZ  r   r   r6   r  r  r  r[  rD  rm   rn   r   comments__all__z'You cannot edit another user's comment.r\  rP  )r   rM   r   rS   r1  r   r4   rx   r   r   ry   r   ZformsetserrorsrM  r   r  r   r   r   r   )r[   r2  r   rh   r\   r\   r]   test_edit_another_users_comment=  sL     

z.TestCommenting.test_edit_another_users_commentc                 C   s  t jj| j| jddd}ddddddd	d	d
t|jddd	ddddd}| jt	d| jjgd|}| 
|t	d| jjgd | j  |  | |j | |j| j | ttjd |   | tjd j| jjg | tjd jd | dtjd j | tjd j| jjg | tjd jd | dtjd j tjjdd}| |j| jj | |j| j | |j| j   | |j!d d |j | |j!d d |j" | |j!d d |j# d S )NrC  r9   rZ  r   r   r6   r  r  r  r(  rD  rm   rn   r2   r   rO  z(Resolved comments:
 - "A test comment"

r`   zwagtail.comments.resolverP  r2  r4   rR  r  )$r   rM   r   rS   r3  r   r4   rx   r   r   r   rM  r   Zresolved_atry   Zresolved_byrZ   r  r   r9  r:  r7  r8  rT  r   r   r1  r   rN   r   rU  rV  r   rW  rR  r  r]  r\   r\   r]   test_resolve_commentn  s~      

 

 
z#TestCommenting.test_resolve_commentc                 C   s  t jj| j| jddd}ddddddd	d
d	t|jddd	ddddd}| jt	d| jjgd|}| 
|t	d| jjgd | j  | | jj  | ttjd |   | tjd j| jjg | tjd jd | dtjd j tjjdd}| |j| jj | |j| j | |j| j  | |j d d |j | |j d d |j! | |j d d |j" d S )NrC  r9   rZ  r   r   r6   r  r  r  r(  rD  rm   rn   r`   r   rO  z'Deleted comments:
 - "A test comment"

zwagtail.comments.deleterP  r2  r4   rR  r  )#r   rM   r   rS   rZ   r   r4   rx   r   r   r   rM  r   rS  r   ry   r  r   r9  r:  r7  r1  r8  rT  r   r   r   rN   r   rU  rV  r   rW  rR  r  r]  r\   r\   r]   test_delete_comment  sb      

z"TestCommenting.test_delete_commentc                 C   s
  t jj| j| jddd}tjj|| jdd}dddd	d	d
dddt|jddddd	d
dt|jdddd}| j	
td| jjgd|}| |td| jjgd | j  |  | |j jd | ttjd |   dd tjD }| | jjg| | | jjg| | | jjg| | tjd jd | dtjd j tjjdd}| |j| jj | |j| j | |j | j!  | |j"d d |j | |j"d d |j# | |j"d d |j | $|j"d d |j | |j"d d d d S )NrC  r9   rZ  an old replyr2  rZ   r  r   r   r6   r  r  r  r  za new reply)r9   r;   r:   r   r   r   r   rE  rF  rG  rH  rI  rJ  rK  rL  rM  rN  comments-0-replies-0-idcomments-0-replies-0-textzcomments-0-replies-1-idzcomments-0-replies-1-textrm   rn   rv   c                 S   s   g | ]
}|j qS r\   r6  )rx  r   r\   r\   r]   rz  ,  s     z1TestCommenting.test_new_reply.<locals>.<listcomp>r2   rO  z5  New replies to: "A test comment"
   - "a new reply"zwagtail.comments.create_replyrP  r2  r4   rR  r  reply)%r   rM   r   rS   r3  r   r4  r   r4   rx   r   r   r   rM  ry   replieslastr  r  r   r9  r:  r   r8  r1  rT  r   r   rN   r   rU  rZ   rV  r   rW  rR  r   )r[   r2  ri  r   rh   Z
recipientsrX  r\   r\   r]   test_new_reply  s        


zTestCommenting.test_new_replyc                 C   s  t jj| j| jddd}tjj|| jdd}dddd	d	d
dddt|jdddd	d	d
dt|jdd}| j	
td| jjgd|}| |td| jjgd | j  |  | |jd | ttjd tjjdd}| |j| jj | |j| j | |j| j  | |jd d |j | |jd d |j | |jd d |j | |jd d |j | |jd d d d S )NrC  r9   rZ  re  rf  r   r   r6   r  r  r  zan edited reply)r9   r;   r:   r   r   r   r   rE  rF  rG  rH  rI  rJ  rK  rL  rM  rN  rg  rh  rm   rn   r   zwagtail.comments.edit_replyrP  r2  r4   rR  r  ri  )r   rM   r   rS   r3  r   rZ   r   r4   rx   r   r   r   rM  ry   r  r  r   r9  r   rN   r   rU  rV  r   rW  rR  r[   r2  ri  r   rh   rX  r\   r\   r]   test_edit_replyH  sh        
zTestCommenting.test_edit_replyc                 C   s  t jj| j| jddd}tjj|| jdd}dddd	d	d
dddt|jdddd	d	d
dt|jddd}| j	
td| jjgd|}| |td| jjgd | j  | |j  | ttjd tjjdd}| |j| jj | |j| j | |j| j  | |jd d |j | |jd d |j | |jd d |j | |jd d |j | |jd d |j d S )NrC  r9   rZ  re  rf  r   r   r6   r  r  r  r(  )r9   r;   r:   r   r   r   r   rE  rF  rG  rH  rI  rJ  rK  rL  rM  rN  rg  rh  zcomments-0-replies-0-DELETErm   rn   r   zwagtail.comments.delete_replyrP  r2  r4   rR  r  ri  )r   rM   r   rS   r3  r   rZ   r   r4   rx   r   r   r   rM  r   rj  r   ry   r  r   r9  r   rN   r   rU  rV  r   rW  rR  r  rm  r\   r\   r]   test_delete_reply  sh        
z TestCommenting.test_delete_replyc                 C   s   t | j}d|_|  dddddddddddd	dddddd
}| jtd| jj	gd|}| 
|td| jj	gd | jj }| |jd	 | ttjd d S NFr   r   r6   r  r  r  r9   rC  rD  rm   rn   r   )r/   Zget_for_userr1  Zupdated_comments_notificationsr   rx   r   r   rS   r4   r   rS  rN   ry   r  r  r   r9  )r[   Zprofiler   rh   r2  r\   r\   r]   3test_updated_comments_notifications_profile_setting  s@      zBTestCommenting.test_updated_comments_notifications_profile_settingc                 C   s   d| j _| j   dddddddddddd	dddddd
}| jtd| jjgd|}| |td| jjgd | jj	
 }| |jd	 | ttjd d S rp  )r1  Z	is_activer   rx   r   r   rS   r4   r   rS  rN   ry   r  r  r   r9  )r[   r   rh   r2  r\   r\   r]   5test_updated_comments_notifications_active_users_only  s>    
  zDTestCommenting.test_updated_comments_notifications_active_users_onlyN)rm  rn  ro  r  r^   r:  rB  r   r.  rY  r^  rb  rc  rd  rl  rn  ro  rq  rr  r\   r\   r\   r]   r0    s    )
771J=S??)r0  c                   @   s    e Zd ZdZdd Zdd ZdS )TestCommentOutputzO
    Test that the correct set of comments is output on the edit page view
    c                 C   sZ   t jjdd| _tddddddd	gd
| _| jj| jd | j   | 	 | _
d S )Nr2   r3   r5   Z234productz
Cuddly toyz$9.95)rT   Zprice)r4   typevalue)r9   r   r<   )r   rM   rN   rO   r)   rS   rP   rQ   rR   rY   rZ   rA  r\   r\   r]   r^     s    
zTestCommentOutput.setUpc                 C   s   t jj| j| jddd t jj| j| jddd t jj| j| jddd t jj| j| jdd	d | jtd
| jjgd}| 	|j
}|dj}t|}dd |d D }|  | |ddg d S )NrC  r9   )rZ   r   r  rR  z'A comment on a field that doesn't existZ
sillytitlezThis is quite expensivezbody.234.pricez'A comment on a block that doesn't existzbody.234.colourrm   rn   z#comments-datac                 S   s   g | ]}|d  qS )r  r\   )rx  r2  r\   r\   r]   rz  S  s     zSTestCommentOutput.test_only_comments_with_valid_paths_are_shown.<locals>.<listcomp>r_  )r   rM   r   rZ   rS   rx   rN   r   r4   re   r;   rf   stringjsonloadssortry   )r[   rh   rk   Zcomments_data_jsonZcomments_dataZcomment_textr\   r\   r]   -test_only_comments_with_valid_paths_are_shown2  sB    
z?TestCommentOutput.test_only_comments_with_valid_paths_are_shownN)rm  rn  ro  r  r^   r{  r\   r\   r\   r]   rs    s   rs  )Tr   rx  r   Zunittestr   Zdjango.confr   Zdjango.contrib.auth.modelsr   r   Zdjango.corer   Zdjango.core.files.baser   Zdjango.httpr   r	   Zdjango.testr
   r   r   Zdjango.urlsr   Zdjango.utilsr   Zdjango.utils.translationr   rN  Zwagtail.admin.admin_url_finderr   Zwagtail.exceptionsr   Zwagtail.modelsr   r   r   r   r   r   r   r   r   Zwagtail.signalsr   Zwagtail.test.testapp.modelsr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   Zwagtail.test.utilsr+   Zwagtail.test.utils.form_datar,   r-   Zwagtail.test.utils.timestampsr.   Zwagtail.users.modelsr/   Zwagtail.utils.timestampsr0   r1   rq  r  r  r  r  r  r  r
  r  r"  r0  rs  r\   r\   r\   r]   <module>   sx   ,D                z' %@k 3 gC}     