a
    DgÂ                    @   s*  d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZmZmZ d d
lmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z#m$Z$m%Z% d dl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZW d dlXmYZY d dlZm[Z[ dd Z\G dd deZ]eg ddG dd deZ^G dd deZ_ed d!d"g d#d$d%gd&G d'd( d(e_Z`G d)d* d*eZaG d+d, d,eZbG d-d. d.eZcG d/d0 d0eZdG d1d2 d2eZeG d3d4 d4eZfG d5d6 d6eZgG d7d8 d8eZhG d9d: d:eZiG d;d< d<eZjG d=d> d>eYeZkG d?d@ d@eZlG dAdB dBeZmG dCdD dDeZnG dEdF dFeZoG dGdH dHeZpG dIdJ dJeZqG dKdL dLeZrG dMdN dNeZsG dOdP dPeZtG dQdR dReZuG dSdT dTeZvG dUdV dVeZwG dWdX dXeZxG dYdZ dZeZyed"d[G d\d] d]eZzG d^d_ d_eZ{G d`da daeZ|G dbdc dceZ}G ddde deeeYZ~dS )f    N)Mock)settings)get_user_model)AnonymousUserGroup)ContentType)ValidationError)Http404)ClientTestCaseoverride_settings)RequestFactory)reverse)timezonetranslation)freeze_time)ParentNotTranslatedError)get_dummy_request)	BasicLockScheduledForPublishLockWorkflowLock)CommentGroupApprovalTaskLocalePagePageLogEntryPageManagerPageViewRestrictionSiteWorkflowWorkflowTaskget_page_modelsget_translatable_models)page_published)"AbstractPageAdvertAlwaysShowInMenusPageBlogCategoryBlogCategoryBlogPageBusinessChildBusinessIndexBusinessNowherePageBusinessSubIndexCustomManagerCustomManagerPageCustomPageQuerySetEventCategory
EventIndex	EventPageEventPageSpeakerGenericSnippetPageManyToManyBlogPageMTIBasePageMTIChildPageMyCustomPageOneToOnePagePageWithExcludedCopyFieldPageWithGenericRelationRelatedGenericRelationSimpleChildPage
SimplePageSimpleParentPageSingleEventPageSingletonPageStandardIndex
StreamPageTaggedGrandchildPage
TaggedPage)WagtailTestUtils)RouteResultc                 C   s   t j| S N)r   objectsget_for_model)model rL   \/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/tests/test_page_model.pyget_ctK   s    rN   c                   @   sv   e Zd Zdg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d Zdd Zdd ZdS )TestValidation	test.jsonc                 C   sJ   t jjdd}tdddd}|j|d t jj|jd}| |jd d	S )
z6
        Check that basic page creation works
        /home/url_pathHello worldhello-worldhellotitleslugcontentinstanceidN)r   rI   getr>   	add_childr^   assertEqualrX   selfhomepage
hello_pageretrieved_pagerL   rL   rM   test_can_createR   s    zTestValidation.test_can_createc                 C   s   t jjdd}tddd}| t |j|d W d    n1 sF0    Y  tdddd}| t |j|d W d    n1 s0    Y  d S )	NrQ   rR   rU   rV   )rY   rZ   r[    rW   r   rI   r_   r>   assertRaisesr   r`   )rc   rd   re   rL   rL   rM   test_title_is_required`   s    *z%TestValidation.test_title_is_requiredc                 C   s~   t jjdd}tddd}|j|d t jj|jd}| |jd td	dd}|j|d t jj|jd}| |jd
 d S )NrQ   rR   rT   rV   rX   rZ   r[   r]   rU   Eventszevents-2)r   rI   r_   r>   r`   r^   ra   rY   )rc   rd   re   rf   events_pagerL   rL   rM   test_slug_is_autogeneratedk   s    z)TestValidation.test_slug_is_autogeneratedc                 C   sV   t jjdd}tdddd}| t |j|d W d    n1 sH0    Y  d S )NrQ   rR   rm   eventsrV   rW   r[   ri   )rc   rd   rn   rL   rL   rM   &test_slug_must_be_unique_within_parentz   s    z5TestValidation.test_slug_must_be_unique_within_parentc                 C   sF   t jjdd}tdddd}|j|d | t jj|jd  d S )	NrQ   rR   	Christmas	christmasrV   rW   r[   r]   )	r   rI   r_   r>   r`   
assertTruefilterr^   exists)rc   rd   christmas_pagerL   rL   rM   &test_slug_can_duplicate_other_sections   s    z5TestValidation.test_slug_can_duplicate_other_sectionsT)ZWAGTAIL_ALLOW_UNICODE_SLUGSc                 C   s,   t dd}t  j|d | |jd d S )N   A mööse bit me öncerX   r[   u   a-mööse-bit-me-öncer   Zget_first_root_noder`   ra   rY   rc   pagerL   rL   rM   2test_slug_generation_respects_unicode_setting_true   s    
zATestValidation.test_slug_generation_respects_unicode_setting_trueFc                 C   s,   t dd}t  j|d | |jd d S )Nry   rz   r[   za-moose-bit-me-oncer{   r|   rL   rL   rM   3test_slug_generation_respects_unicode_setting_false   s    
zBTestValidation.test_slug_generation_respects_unicode_setting_falsec                 C   s$   t jjdd}| |j|  d S )NrQ   rR   )r   rI   r_   ra   draft_titleget_admin_display_titlerc   rd   rL   rL   rM   test_get_admin_display_title   s    z+TestValidation.test_get_admin_display_titlec                 C   s:   t jjddjddd t jjdd}| | d d S )NrQ   rR   z
live titlerh   )rX   r   )r   rI   ru   updater_   ra   r   r   rL   rL   rM   3test_get_admin_display_title_with_blank_draft_title   s
    zBTestValidation.test_get_admin_display_title_with_blank_draft_titlec                 C   s   t jjdd}tddd}|j|d t jj|jd}| |jd tdddd	}|j|d t jj|jd}| |jd d S )
NrQ   rR   rT   rV   rl   r[   r]   zHello world edited)rX   r   rZ   )r   rI   r_   r>   r`   r^   ra   r   rb   rL   rL   rM   !test_draft_title_is_autopopulated   s    z0TestValidation.test_draft_title_is_autopopulatedN)__name__
__module____qualname__fixturesrg   rk   ro   rq   rx   r   r~   r   r   r   r   rL   rL   rL   rM   rO   O   s   

rO   )	localhostevents.example.comabout.example.comunknown.site.comZALLOWED_HOSTSc                   @   s   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d Zdd Zdd Zd S )!TestSiteRoutingrP   c                 C   s   t jjdd| _tjjdd}tjjdd}t jjd|d| _t jjd|dd	| _t jjd
|d| _t jj| jj	d| jj
d| _d| _d| _d S )NTZis_default_site/home/events/rR   /home/about-us/r   hostname	root_pageZ8765)r   r   portr   )r   r   r   Z8000r   )r   rI   r_   default_siter   createevents_sitealternate_port_events_site
about_siter   r   Zalternate_port_default_siteunrecognised_portunrecognised_hostname)rc   rn   Z
about_pagerL   rL   rM   setUp   s&    zTestSiteRouting.setUpc                 C   s   t | jd}| d t||j W d    n1 s:0    Y  | d t||j W d    n1 sr0    Y  d S )Nsite   r   )r   r   assertNumQueriesr   route_for_requestpathrc   requestrL   rL   rM   "test_route_for_request_query_count   s
    ,z2TestSiteRouting.test_route_for_request_query_countc                 C   s   t | jd}| t|d t||j}| t|t	 | 
|d |d |d f| jjjg i f | t|d | |j| d S )Nr   _wagtail_route_for_requestr      r   )r   r   assertFalsehasattrr   r   r   rt   
isinstancerG   ra   r   specificassertIsr   )rc   r   resultrL   rL   rM   test_route_for_request_value   s    z,TestSiteRouting.test_route_for_request_valuec                 C   s\   t | jd}t }||_| d& | t||j| W d    n1 sN0    Y  d S )Nr   r   )	r   r   r   r   r   ra   r   r   r   )rc   r   mrL   rL   rM   test_route_for_request_cached   s
    z-TestSiteRouting.test_route_for_request_cachedc                 C   s&   t d| jd}| t||j d S )Ndoes-not-existr   r   )r   r   assertIsNoner   r   r   r   rL   rL   rM   %test_route_for_request_suppresses_404   s    z5TestSiteRouting.test_route_for_request_suppresses_404c                 C   sP   t | jd}| t||j| jjj t d| jd}| t||jd  d S )Nr   r   r   )r   r   ra   r   find_for_requestr   r   r   )rc   Zrequest_200Zrequest_404rL   rL   rM   test_find_for_request   s    z%TestSiteRouting.test_find_for_requestc                 C   sN   t | jd}| d$ | t|| j W d    n1 s@0    Y  d S Nr   r   )r   r   r   ra   r   r   r   rL   rL   rM   )test_valid_headers_route_to_specific_site  s    z9TestSiteRouting.test_valid_headers_route_to_specific_sitec                 C   sN   t | jd}| d$ | t|| j W d    n1 s@0    Y  d S r   )r   r   r   ra   r   r   r   rL   rL   rM   +test_ports_in_request_headers_are_respected
  s
    z;TestSiteRouting.test_ports_in_request_headers_are_respectedc                 C   sT   t  }| j|jd< | d$ | t|| j W d    n1 sF0    Y  d S )N	HTTP_HOSTr   )r   r   METAr   ra   r   r   r   r   rL   rL   rM   4test_unrecognised_host_header_routes_to_default_site  s    zDTestSiteRouting.test_unrecognised_host_header_routes_to_default_sitec                 C   sZ   t | jd}| j|jd< | d$ | t|| j W d    n1 sL0    Y  d S Nr   SERVER_PORTr   )r   r   r   r   r   ra   r   r   r   rL   rL   rM   >test_unrecognised_port_and_default_host_routes_to_default_site  s    zNTestSiteRouting.test_unrecognised_port_and_default_host_routes_to_default_sitec                 C   s`   t  }| j|jd< | j|jd< | d$ | t|| j W d    n1 sR0    Y  d S Nr   r   r   )	r   r   r   r   r   ra   r   r   r   r   rL   rL   rM   Ctest_unrecognised_port_and_unrecognised_host_routes_to_default_site   s
    zSTestSiteRouting.test_unrecognised_port_and_unrecognised_host_routes_to_default_sitec                 C   sb   t  }| jj|jd< | j|jd< | d$ | t|| j W d    n1 sT0    Y  d S r   )	r   r   r   r   r   r   ra   r   r   r   rL   rL   rM   Etest_unrecognised_port_on_known_hostname_routes_there_if_no_ambiguity)  s
    zUTestSiteRouting.test_unrecognised_port_on_known_hostname_routes_there_if_no_ambiguityc                 C   sZ   t | jd}| j|jd< | d$ | t|| j W d    n1 sL0    Y  d S r   )	r   r   r   r   r   ra   r   r   r   r   rL   rL   rM   Ltest_unrecognised_port_on_known_hostname_routes_to_default_site_if_ambiguity2  s    z\TestSiteRouting.test_unrecognised_port_on_known_hostname_routes_to_default_site_if_ambiguityc                 C   sp   t  }d| jj| jj|jd< | jj|jd< | d$ | t	
|| j W d    n1 sb0    Y  d S )Nz{}:{}r   r   r   )r   formatr   r   r   r   r   r   ra   r   r   r   rL   rL   rM   (test_port_in_http_host_header_is_ignored=  s    
z8TestSiteRouting.test_port_in_http_host_header_is_ignoredc                 C   sR   t  }d|jd< | d$ | t|| j W d    n1 sD0    Y  d S )Nzdisallowed:80r   r   )r   r   r   ra   r   r   r   r   rL   rL   rM   test_site_with_disallowed_hostJ  s    
z.TestSiteRouting.test_site_with_disallowed_hostN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rL   rL   rL   rM   r      s    				r   c                   @   s   e Zd ZdgZdd Zdd Zdd Zdd	 Zeg d
ddd Z	edddd Z
edddd Zdd Zdd Zdd Zdd Zedddiid ed!gdd"d# Zd$d% Zd&S )'TestRoutingrP   c                 C   s   ddl m} |  d S Nr   )clear_url_cachesdjango.urlsr   rc   r   rL   rL   rM   r   V  s    zTestRouting.setUpc                 C   s   ddl m} |  d S r   r   r   rL   rL   rM   tearDown[  s    zTestRouting.tearDownc                 C   s   t jjdd}tjjdd}tjjdd}| | |jddf | |jd | |jd | |	|d | |
 | | | |jdd	f | |jd
 | |jd	 | |	|d	 | |
 | d S )NTr   rQ   rR   /home/events/christmas/http://localhost/http://localhost//events/christmas/z"http://localhost/events/christmas/r   rI   r_   r   ra   get_url_partsr^   full_urlurlrelative_urlget_siterc   r   rd   rw   rL   rL   rM   	test_urls`  s(    

zTestRouting.test_urlsc                 C   sd   t jjdd}tjjdd}| |  | |j | |j | || | |	  d S )Nr   rR   Tr   )
r   rI   r_   r   r   r   r   r   r   r   )rc   rootr   rL   rL   rM   test_page_with_no_urly  s    z!TestRouting.test_page_with_no_urlr   Z
testserverr   second-events.example.comr   c           	      C   sx  t jjdd}tjjd|d}tjjd|d}tjjdd}t jjdd}t jjd	d}| | |jd
df | |jd | |j	d | |
|d | |
|d | | | | | |jddf | |jd | |j	d | |
|d | |
|d | | | t|d}| |j|d|jddf t|d}| |j|d|jddf d S )Nr   rR   r   r   r   Tr   rQ   r   r   r   r   http://events.example.com/christmas/z$http://events.example.com/christmas/r   r    http://second-events.example.comr   rI   r_   r   r   ra   r   r^   r   r   r   r   r   	rc   rn   r   Zsecond_events_siter   rd   rw   r   Zrequest2rL   rL   rM   test_urls_with_multiple_sites  sT    	






z)TestRouting.test_urls_with_multiple_siteswagtail.test.non_root_urlsROOT_URLCONFc                 C   s   t jjdd}tjjdd}tjjdd}| | |jddf | |jd | |jd | |	|d | |
 | | | |jdd	f | |jd
 | |jd	 | |	|d	 | |
 | d S )NTr   rQ   rR   r   r   z/site/zhttp://localhost/site//site/events/christmas/z'http://localhost/site/events/christmas/r   r   rL   rL   rM   test_urls_with_non_root_urlconf  s,    

z+TestRouting.test_urls_with_non_root_urlconfzwagtail.test.headless_urlsc                 C   sP   t jjdd}tjjdd}| | |jd d f | |j | |j	 d S )NTr   rQ   rR   )
r   rI   r_   r   ra   r   r^   r   r   r   )rc   r   rd   rL   rL   rM   test_urls_headless  s
    zTestRouting.test_urls_headlessc                 C   sL   t jjdd}tjjdd}tdd}||ddg\}}}| || d S )NrQ   rR   r   r   r   rp   rs   )r   rI   r_   r2   r   routera   )rc   rd   rw   r   
found_pageargskwargsrL   rL   rM   test_request_routing  s
    
z TestRouting.test_request_routingc                 C   s`   t jjdd}ttj d}t |_||}| 	|j
d | 	|jd | | |d d S )Nr   rR   r      rc   <h2>Event</h2>)r2   rI   r_   r   r   firstr   userZservera   status_codecontext_dataassertContains)rc   rw   r   responserL   rL   rM   test_request_serving  s    
z TestRouting.test_request_servingc                 C   sV   t jjdd}tdd}| t  ||ddg W d    n1 sH0    Y  d S )NrQ   rR   /events/quinquagesima/r   rp   Zquinquagesimar   rI   r_   r   rj   r	   r   rc   rd   r   rL   rL   rM   &test_route_to_unknown_page_returns_404  s    
z2TestRouting.test_route_to_unknown_page_returns_404c                 C   sV   t jjdd}tdd}| t  ||ddg W d    n1 sH0    Y  d S )NrQ   rR   $/events/tentative-unpublished-event/r   rp   ztentative-unpublished-eventr   r   rL   rL   rM   *test_route_to_unpublished_page_returns_404  s    
z6TestRouting.test_route_to_unpublished_page_returns_404defaultBACKEND+django.core.cache.backends.dummy.DummyCacheZCACHESdummyc                 C   s  t jjdd}tjjdd}| d  | | d W d    n1 sL0    Y  | d  | | d W d    n1 s0    Y  | d  | | d W d    n1 s0    Y  t }| d$ | |j|d	d W d    n1 s0    Y  | d$ | |j|d	d W d    n1 sF0    Y  | d$ | |j|d	d W d    n1 s0    Y  d S )
NrQ   rR   r   r   r   r   r   r   r   r   rI   r_   r2   r   ra   get_urlr   rc   rd   rw   r   rL   rL   rM   (test_request_scope_site_root_paths_cache  s"    ...44z4TestRouting.test_request_scope_site_root_paths_cachec           	      C   s   t jjdd}tjjdd}tdd}||ddg\}}}| || t jjddj}| d	( |j	d
d}| || W d    n1 s0    Y  d S )NrQ   rR   r   r   r   rp   rs   r   r   Fr   )
r   rI   r_   r2   r   r   ra   r   r   
get_parent)	rc   rd   rw   r   r   r   r   rn   parentrL   rL   rM   test_cached_parent_obj_set-  s    
z&TestRouting.test_cached_parent_obj_setN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  rL   rL   rL   rM   r   Q  s.   

7


	

r   zwagtail.test.urls_multilangenTr  ZEnglish)en-uszEnglish (United States)frZFrenchr  r  )r   ZLANGUAGE_CODEWAGTAIL_I18N_ENABLEDZ	LANGUAGESWAGTAIL_CONTENT_LANGUAGESc                   @   s   e Zd ZdddZdd Zdd Zeg dd	d
d Zdd Zdd Z	eg dddd Z
edddiidedgddd ZdS )TestRoutingWithI18Nr  c                 C   s   t jjdd}tjjdd}tjjdd}| |jd| d | |jd| d | ||d| d | | | | |	 |j
dd| d	f | |jd| d	 | |jd| d	 | ||d| d	 | | | d S )
NTr   rQ   rR   r   r   r   r   r   )r   rI   r_   r   ra   r   r   r   r   r   r^   )rc   expected_language_coder   rd   rw   rL   rL   rM   r   K  s<    


zTestRoutingWithI18N.test_urlsc                 C   s6   t d |   W d    n1 s(0    Y  d S Nr  r   overrider   rc   rL   rL   rM   $test_urls_with_translation_activateds  s    z8TestRoutingWithI18N.test_urls_with_translation_activatedc                 C   s:   t d | jdd W d    n1 s,0    Y  d S )Nr  )r  r  r  rL   rL   rM   4test_urls_with_region_specific_translation_activatedy  s    zHTestRoutingWithI18N.test_urls_with_region_specific_translation_activatedr  )r  c                 C   s6   t d |   W d    n1 s(0    Y  d S )Nr  r  r  rL   rL   rM   Wtest_urls_with_region_specific_translation_activated_thats_in_wagtail_content_languages  s    zkTestRoutingWithI18N.test_urls_with_region_specific_translation_activated_thats_in_wagtail_content_languagesc                 C   s6   t d |   W d    n1 s(0    Y  d S )Nser  r  rL   rL   rM   8test_urls_with_language_not_in_wagtail_content_languages  s    zLTestRoutingWithI18N.test_urls_with_language_not_in_wagtail_content_languagesc                 C   s  t jjdd}tjjdd}tjjdd}tjjdd}||}|j|dd}d	|_|jd
gd | 	|
 |jddf | 	|jd | 	|jd | 	||d | 	| | | 	|
 |jddf | 	|jd | 	|jd | 	||d | 	| | d S )NTr   rQ   rR   r   r  language_codeZcopy_parentsZnoelrY   Zupdate_fieldsr   z/fr/zhttp://localhost/fr/z/fr/events/noel/z http://localhost/fr/events/noel/)r   rI   r_   r   r   r   copy_for_translationrY   savera   r   r^   r   r   r   r   )rc   r   rd   rw   	fr_localefr_homepageZfr_christmas_pagerL   rL   rM   &test_urls_with_different_language_tree  s6    


z:TestRoutingWithI18N.test_urls_with_different_language_treer   r   c           	      C   sx  t jjdd}tjjd|d}tjjd|d}tjjdd}t jjdd}t jjd	d}| | |jd
df | |jd | |j	d | |
|d | |
|d | | | | | |jddf | |jd | |j	d | |
|d | |
|d | | | t|d}| |j|d|jddf t|d}| |j|d|jddf d S )Nr   rR   r   r   r   Tr   rQ   r   r   /en/zhttp://localhost/en/r   z/en/christmas/z'http://events.example.com/en/christmas/r   r   r   r   r   rL   rL   rM   r     sZ    	





z1TestRoutingWithI18N.test_urls_with_multiple_sitesr  r  r  r  r  c                 C   s  t jjdd}tjjdd}| d  | | d W d    n1 sL0    Y  | d  | | d W d    n1 s0    Y  | d  | | d W d    n1 s0    Y  t }| d$ | |j|d	d W d    n1 s0    Y  | d$ | |j|d	d W d    n1 sF0    Y  | d$ | |j|d	d W d    n1 s0    Y  d S )
NrQ   rR   r   r   r-  r   z/en/events/christmas/   r   r	  r  rL   rL   rM   r    s"    ...44z<TestRoutingWithI18N.test_request_scope_site_root_paths_cacheN)r  )r   r   r   r   r  r   r   r!  r#  r,  r   r  rL   rL   rL   rM   r  <  s$   
(

!
>

r  c                   @   s   e Zd ZdgZdd Zdd Zdd Zedd	d
d Zdd Z	dd Z
eddgddd Zdd Zdd Zdd Zdd ZdS )TestServeViewrP   c                 C   s   t   ddlm} |  d S r   )r   Zclear_site_root_paths_cacher   r   r   rL   rL   rM   r   #  s    zTestServeView.setUpc                 C   s   ddl m} |  d S r   r   r   rL   rL   rM   r   /  s    zTestServeView.tearDownc                 C   sj   | j d}| |jd | |jd jd tjjdd}| |jd | | 	|d | 	|d	 d S )
Nr   r   r   tests/event_page.htmlr   rR   rc   <h1>Christmas</h1>r   
clientr_   ra   r   	templatesnamer2   rI   contextr   rc   r   rw   rL   rL   rM   
test_serve4  s    zTestServeView.test_server   r   c                 C   sj   | j d}| |jd | |jd jd tjjdd}| |jd | | 	|d | 	|d	 d S )
Nr   r   r   r0  r   rR   rc   r1  r   r2  r7  rL   rL   rM   test_serve_with_non_root_urls?  s    z+TestServeView.test_serve_with_non_root_urlsc                 C   s   | j d}| |jd d S )Nr     r3  r_   ra   r   rc   r   rL   rL   rM   #test_serve_unknown_page_returns_404K  s    z1TestServeView.test_serve_unknown_page_returns_404c                 C   s   | j d}| |jd d S )Nr  r:  r;  r<  rL   rL   rM   'test_serve_unpublished_page_returns_404O  s    z5TestServeView.test_serve_unpublished_page_returns_404r   r   r   c                 C   s   t jjdd}tjjd|d | jjddd}| |jd | |jd j	d	 t
jjd
d}| |jd | | |d | |d t }|jddd}| |jd d S )Nr   rR   r   r   r   )r   r   r   r0  r   rc   r1  r   r   r:  )r   rI   r_   r   r   r3  ra   r   r4  r5  r2   r6  r   r
   )rc   rn   r   rw   crL   rL   rM   test_serve_with_multiple_sitesS  s    z,TestServeView.test_serve_with_multiple_sitesc                 C   sZ   dt _t jjdd}| jd}| |jd | | |jd | | |jd | d S )N
event_pager   rR   r   r}   rc   )r2   Zcontext_object_namerI   r_   r3  ra   r6  )rc   rw   r   rL   rL   rM   #test_serve_with_custom_context_namef  s    z1TestServeView.test_serve_with_custom_context_namec                 C   s6   | j d}| |jd | |d | |d d S )N/events/r   <h1>Events</h1>*<a href="/events/christmas/">Christmas</a>)r3  r_   ra   r   r   r<  rL   rL   rM   test_serve_with_custom_contextq  s    z,TestServeView.test_serve_with_custom_contextc                 C   s:   | j jddd}| |jd | |d | |d d S )NrC  ZXMLHttpRequest)ZHTTP_X_REQUESTED_WITHr   rD  rE  )r3  r_   ra   r   ZassertNotContainsr   r<  rL   rL   rM   test_ajax_response{  s    z TestServeView.test_ajax_responsec                 C   s    | j jddd}| |d d S )NrC  Z	GoogleBot)HTTP_USER_AGENTzbad googlebot no cookie)r3  r_   r   r<  rL   rL   rM   test_before_serve_hook  s    z$TestServeView.test_before_serve_hookN)r   r   r   r   r   r   r8  r   r9  r=  r>  r@  rB  rF  rG  rI  rL   rL   rL   rM   r/     s   


r/  c                   @   s   e Zd ZdgZdd ZdS )TestMovePagerP   c                 C   s   t jjdd}tjjdd}|j|dd tjj|jd}| |jd | |jd | |	 j|j |
 jd	d
}| |jd | |jd d S )Nr   rR   r   
last-childposr]   z/home/about-us/events/   rs   rY      z /home/about-us/events/christmas/)r>   rI   r_   r1   mover^   ra   rS   depthr  get_children)rc   Zabout_us_pageevents_indexrs   rL   rL   rM   test_move_page  s    zTestMovePage.test_move_pageN)r   r   r   r   rU  rL   rL   rL   rM   rJ    s   rJ  c                   @   s*   e Zd ZdgZdd Zdd Zdd ZdS )	TestPrevNextSiblingsrP   c                 C   s,   t jjdd}| | jdd  d S )Nr   rR   /home/events/final-event/)r   rI   r_   rt   get_next_siblingsru   rv   rc   christmas_eventrL   rL   rM   test_get_next_siblings  s    z+TestPrevNextSiblings.test_get_next_siblingsc                 C   s*   t jjdd}| |jdd | d S )Nr   rR   TZ	inclusive)r   rI   r_   ra   rX  r   rY  rL   rL   rM    test_get_next_siblings_inclusive  s    z5TestPrevNextSiblings.test_get_next_siblings_inclusivec                 C   sD   t jjdd}| | jdd  | |jdd | d S )NrW  rR   r   Tr\  )	r   rI   r_   rt   Zget_prev_siblingsru   rv   ra   r   )rc   Zfinal_eventrL   rL   rM   test_get_prev_siblings  s    z+TestPrevNextSiblings.test_get_prev_siblingsN)r   r   r   r   r[  r]  r^  rL   rL   rL   rM   rV    s   rV  c                   @   s   e Zd ZdgZdd ZdS )TestSaveRevisionrP   c                 C   sX   t jjdd}| t}|  W d    n1 s60    Y  | |jjd d d S )Nr   rR   r   ztpage.save_revision() must be called on the specific version of the page. Call page.specific.save_revision() instead.)	r   rI   r_   rj   RuntimeErrorsave_revisionra   	exceptionr   )rc   rZ  erL   rL   rM   +test_raises_error_if_non_specific_page_used  s    &
z<TestSaveRevision.test_raises_error_if_non_specific_page_usedN)r   r   r   r   rd  rL   rL   rL   rM   r_    s   r_  c                   @   sb   e Zd ZdgZeddd Zeddd Zeddd Zd	d
 Zdd Z	eddd Z
dS )TestLiveRevisionrP   z2017-01-01 12:00:00c                 C   s   t jjdd}| }|  |  | |j| tj	r| |j
tjddddddtjjd | |jtjddddddtjjd nJ| |j
tdddddd | |jttjddddddtjjd d S )	Nr   r]     r      r   tzinfo  )r   rI   r_   ra  publishrefresh_from_dbra   live_revisionr   USE_TZlast_published_atdatetimer   utcfirst_published_at
make_naiverc   r}   revisionrL   rL   rM   *test_publish_method_will_set_live_revision  s4    z;TestLiveRevision.test_publish_method_will_set_live_revisionc                 C   s   t jjdd}| }|  |  |  |  | |j t	j
r| |jtjddddddtjjd | |jtjddddddtjjd nJ| |jttjddddddtjjd | |jtdddddd d S )	Nr   r]   rj  r   rg  r   rh  rf  )r   rI   r_   ra  rk  rl  	unpublishr   rm  r   rn  ra   rr  rp  r   rq  ro  rs  rt  rL   rL   rM   .test_unpublish_method_will_clean_live_revision  s8    	z?TestLiveRevision.test_unpublish_method_will_clean_live_revisionc                 C   s  t jjdd}| }|  |jddddd}| |j | |j|j t	j
r| |jtjdd	d	d
ddtjjd | |jtjdd	d	d
ddtjjd n<| |jtdd	d	d
dd | |jtdd	d	d
dd |  | |jd | |jd d S )Nr   rR   TNew about usnew-about-usrX   rY   Z	keep_liveupdate_attrsrf  r   rg  r   rh  )r>   rI   r_   ra  rk  copyassertIsNotNonerm  assertNotEqualr   rn  ra   rr  rp  r   rq  ro  rl  rX   r   rc   about_usru  new_about_usrL   rL   rM   9test_copy_method_with_keep_live_will_update_live_revision  s6    zJTestLiveRevision.test_copy_method_with_keep_live_will_update_live_revisionc                 C   s   t jjdd}| }|  |  | |j |jddddd}| 	|j | 	|j
 | 	|j |  | |jd | |jd d S )Nr   rR   Fry  rz  r{  r|  )r>   rI   r_   ra  rk  rl  r  rm  r~  r   rr  ro  ra   rX   r   r  rL   rL   rM   @test_copy_method_without_keep_live_will_not_update_live_revision@  s    zQTestLiveRevision.test_copy_method_without_keep_live_will_not_update_live_revisionc                 C   s   t jjdd}d|_|  |  | | jd |jddddd}| }| |jd |  | |j	d | |j
d d S )	Nr   rR   zWe are even better than beforeFry  rz  r{  r|  )r>   rI   r_   rZ   ra  rl  ra   get_latest_revision_as_objectr~  rX   r   )rc   r  r  Znew_about_us_draftrL   rL   rM   'test_copy_method_copies_latest_revisionT  s"    z8TestLiveRevision.test_copy_method_copies_latest_revisionc                 C   s*  t jjdd}tjr4tjddddddtjjd|_ntdddddd|_|	 }|
  |  | |j | |j tjr| |jtjddddddtjjd | |jtjdd	ddddtjjd nX| |jttjddddddtjjd | |jttjdd	ddddtjjd d S )
Nr   rR   i  r   rg  r   rh  rj  r   )r>   rI   r_   r   rn  rp  r   rq  
go_live_atra  rk  rl  r   liver   rm  ra   rr  ro  rs  )rc   r  ru  rL   rL   rM   ;test_publish_with_future_go_live_does_not_set_live_revisionk  sH    
zLTestLiveRevision.test_publish_with_future_go_live_does_not_set_live_revisionN)r   r   r   r   r   rv  rx  r  r  r  r  rL   rL   rL   rM   re    s   
#
&
$re  c                       sb   e Zd ZdgZ 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  ZS )TestPageGetSpecificrP   c                    s:   t    tjjdd| _d| j_ddi| j_d| j_d S )Nr   rR   ABCkeyvalue  )	superr   r   rI   r_   r}   foobarbazr  	__class__rL   rM   r     s
    
zTestPageGetSpecific.setUpc              	   C   s  |  d | j }W d    n1 s*0    Y  | |t |  d4 | |j| jj | |j| jj W d    n1 s0    Y  |  d | |j	 W d    n1 s0    Y  dD ]L}| j
|d* | t||t| j| W d    q1 s
0    Y  qd S )Nr   r   r  r  r  	attributer   r}   get_specificassertIsInstancer>   ra   r^   rX   rt   rZ   subTestr   getattrrc   r   attrrL   rL   rM   test_default  s    (0*z TestPageGetSpecific.test_defaultc              	   C   s  |  d | jjdd}W d    n1 s.0    Y  | |t |  d4 | |j| jj | |j| jj W d    n1 s0    Y  |  d | |j	 W d    n1 s0    Y  dD ]L}| j
|d* | t||t| j| W d    q1 s0    Y  qd S )Nr   T)deferredr   r  r  r  r  rL   rL   rM   test_deferred  s    ,0*z!TestPageGetSpecific.test_deferredc                 C   sJ   | j jddgd}| |j| j j | |j| j j | t|d d S )Nr  r  Z
copy_attrsr  r}   r  r   r  r  r   r   rc   r   rL   rL   rM   test_copy_attrs  s    z#TestPageGetSpecific.test_copy_attrsc              	   C   sX   | j jdd}dD ]@}| j|d  | t|| W d    q1 sH0    Y  qd S )NrL   r  r  r  )r}   r  r  r   r   r  rL   rL   rM   test_copy_attrs_with_empty_list  s    z3TestPageGetSpecific.test_copy_attrs_with_empty_listc                 C   sH   | j jdgd}| |j| j j | |j| j j | t|d d S )Nr  Zcopy_attrs_excluder  r  rL   rL   rM   test_copy_attrs_exclude  s    z+TestPageGetSpecific.test_copy_attrs_excludec              	   C   sb   | j jdd}dD ]J}| j|d* | t||t| j | W d    q1 sR0    Y  qd S )NrL   r  r  r  )r}   r  r  r   r  r  rL   rL   rM   'test_copy_attrs_exclude_with_empty_list  s    z;TestPageGetSpecific.test_copy_attrs_exclude_with_empty_listc                 C   s   |  d@ | jj}| jj}| jj}| || | || W d    n1 sP0    Y  | |t |  d | |j W d    n1 s0    Y  d S )Nr   r   )r   r}   r   r   r  r>   rt   rZ   rc   r   Zresult_2Zresult_3rL   rL   rM   test_specific_cached_property  s    *z1TestPageGetSpecific.test_specific_cached_propertyc                 C   s   |  d@ | jj}| jj}| jj}| || | || W d    n1 sP0    Y  | |t |  d | |j W d    n1 s0    Y  d S )Nr   r   )r   r}   Zspecific_deferredr   r  r>   rt   rZ   r  rL   rL   rM   &test_specific_deferred_cached_property  s    *z:TestPageGetSpecific.test_specific_deferred_cached_property)r   r   r   r   r   r  r  r  r  r  r  r  r  __classcell__rL   rL   r  rM   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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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHS )ITestCopyPagerP   c                 C   sj   t jjdd}|jdddd}| |t  | |jd | |jd | |j	|j	 | |j
d d S )Nr   rR   ry  rz  r{  r}  /home/new-about-us/)r>   rI   r_   r~  r  ra   rX   rY   r  r^   rS   rc   r  r  rL   rL   rM   test_copy_page_copies  s    z"TestCopyPage.test_copy_page_copiesc                 C   st   t jjdd}|jdddd}| |j dd | |j dd	 | |j dd
 | |j dd d S )Nr   rR   New christmas eventnew-christmas-eventr{  r  r   Child objects weren't copied1Child objects were removed from the original page6Child objects defined on the superclass weren't copiedKChild objects defined on the superclass were removed from the original page)r2   rI   r_   r~  ra   speakerscountadvert_placementsrc   rZ  new_christmas_eventrL   rL   rM   #test_copy_page_copies_child_objects(  s,    z0TestCopyPage.test_copy_page_copies_child_objectsc                 C   s   t jjdd}tjjdd}tjjdd}||f|_|  |jdddd	}| |j	 d
d | |j	 d
d | |j
  |j
   dS )LTest that a page will be copied with parental many to many relations intact.r   rR   Summerr5  Holidaysr  r  r{  r  r   cChild objects (parental many to many) defined on the superclass were removed from the original page4Child objects (parental many to many) weren't copiedN)r2   rI   r_   r0   r   
categoriesr)  r~  ra   r  allin_bulkrc   rZ  Zsummer_categoryZholiday_categoryr  rL   rL   rM   (test_copy_page_copies_parental_relationsI  s,    
z5TestCopyPage.test_copy_page_copies_parental_relationsc                 C   sf   t jjdd}td|jdg|_|  |jdddd}| |j	 d	d
 | j
|j dd d S )Nr   rR   test)textr   r  r  r{  r  r   z,Comments were removed from the original pagezComments were copiedmsg)r2   rI   r_   r   ownerZwagtail_admin_commentsr)  r~  ra   r  r   rv   r  rL   rL   rM   %test_copy_page_does_not_copy_commentsl  s     z2TestCopyPage.test_copy_page_does_not_copy_commentsc                 C   sx   t jjdd}|jddddgd}| |j dd	 | |j dd
 | j|j	 dd | |j dd d S )Nr   rR   r  r  r{  r  )r}  Zexclude_fieldsr   r  r  zSChild objects were copied despite accessor_name being specified in `exclude_fields`r  r  )
r2   rI   r_   r~  ra   r  r  r   r  rv   r  rL   rL   rM   Mtest_copy_page_does_not_copy_child_objects_if_accessor_name_in_exclude_fields  s0    	zZTestCopyPage.test_copy_page_does_not_copy_child_objects_if_accessor_name_in_exclude_fieldsc                 C   s   t  }tjjdd}|jdddd}|j|dd |jd	d
d|dd}tjd}|j }|	|||| tjd}|j
 }|	|||| |  j}|j
 }|	|||| d S )Nr   rR   zChild christmas eventzchild-christmas-eventr{  r  rK  rL  r  r  T)r}  Zprocess_child_object	recursiver  speaker)r   r2   rI   r_   r~  rQ  Z_meta	get_fieldr  Zassert_any_callr  rS  r   )rc   Zmodify_childZ	old_eventZchild_eventZ	new_eventZrelationshipZchild_objectZnew_child_eventrL   rL   rM   1test_copy_page_with_process_child_object_supplied  s4    


z>TestCopyPage.test_copy_page_with_process_child_object_suppliedc                 C   s  t jjdd}|  |jdddd}| |j d | |j dd	 | }| |j	d | |j
d |  }| |j	d | |j
d |j }|j}| |d
 |j | |d d d |j t|jjddd}dd |d D }| j||dd d S )Nr   rR   r  r  r{  r  r   r   -Revisions were removed from the original pagepkr  r   r}   r^   TZflatc                 S   s   h | ]}|d  qS )r  rL   ).0r  rL   rL   rM   	<setcomp>  s   z?TestCopyPage.test_copy_page_copies_revisions.<locals>.<setcomp>z;Child objects in revisions were not given a new primary keyr  )r2   rI   r_   ra  r~  ra   	revisionsr  r  rX   rY   get_latest_revisionZ	as_objectr   rZ   r^   setr  values_listr   intersection)rc   rZ  r  latest_revisionZnew_revisionZnew_revision_contentZold_speakers_idsZnew_speakers_idsrL   rL   rM   test_copy_page_copies_revisions  s>    
z,TestCopyPage.test_copy_page_copies_revisionsc              	   C   s   t jjdd}|  | }tjddddddtjjd|_|	  |j
ddd	d
}|jd j}|jd j}| || d S )Nr   rR   rj  r   r   rh  r  r  r{  r  
created_at)r2   rI   r_   ra  r  rp  r   rq  r  r)  r~  r  order_byr   ra   )rc   rZ  ru  r  Zchristmas_event_created_atZnew_christmas_event_created_atrL   rL   rM   <test_copy_page_copies_revisions_and_doesnt_change_created_at
  s    zITestCopyPage.test_copy_page_copies_revisions_and_doesnt_change_created_atc                 C   s   t jjdd}tjr:|jtjddddddtjjdd	 n|jtddddddd	 |j	d
ddd}tjr| 
|jd jtjddddddtjjd n*| 
|jd jtdddddd | |jd j d S )Nr   rR   rj  	      rg  r   rh  )approved_go_live_atr  r  r{  r  r  )r2   rI   r_   r   rn  ra  rp  r   rq  r~  ra   r  r  r   r  r   r  rL   rL   rM   3test_copy_page_copies_revisions_and_doesnt_schedule#  s2    z@TestCopyPage.test_copy_page_copies_revisions_and_doesnt_schedulec                 C   sT   t jjdd}|  |jddddd}| |j d | |j dd	 d S )
Nr   rR   r  r  r{  F)r}  copy_revisionsr   r  )r2   rI   r_   ra  r~  ra   r  r  r  rL   rL   rM   9test_copy_page_doesnt_copy_revisions_if_told_not_to_do_soL  s    
zFTestCopyPage.test_copy_page_doesnt_copy_revisions_if_told_not_to_do_soc                 C   sD   t jjdd}|jdddd}| |t | |j dd d S )	Nr   rR   r  r  r{  r  r   r  )	r   rI   r_   r~  r  r2   ra   r  r  r  rL   rL   rM   :test_copy_page_copies_child_objects_with_nonspecific_classd  s    zGTestCopyPage.test_copy_page_copies_child_objects_with_nonspecific_classc                 C   st   t jjdd}|jddddd}| jdd	 }| jdd	 }| |d
 | |d | |j	d d S )Nr   rR   TNew events indexnew-events-indexr{  r  r}  rs   rO  Child pages weren't copied+Child pages were removed from original page!/home/new-events-index/christmas/)
r1   rI   r_   r~  rS  ru   r   r  ra   rS   rc   rT  new_events_indexold_christmas_eventr  rL   rL   rM   !test_copy_page_copies_recursivelyu  s     z.TestCopyPage.test_copy_page_copies_recursivelyc                 C   sz   t jjdd}|jddddd}| jdd	 }| jdd	 }| |jj	
 d
d | |jj	
 d
d d S )Nr   rR   Tr  r  r{  r  rs   rO  r   r  r  )r1   rI   r_   r~  rS  ru   r   ra   r   r  r  r  rL   rL   rM   4test_copy_page_copies_recursively_with_child_objects  s&    

zATestCopyPage.test_copy_page_copies_recursively_with_child_objectsc                 C   s   t jjdd}| jdd j}|  |jddddd	}| jdd }| 	|jj
 d
 | 	|jj
 dd d S )Nr   rR   rs   rO  Tr  r  r{  r  r   r   r  r1   rI   r_   rS  ru   r   r   ra  r~  ra   r  r  rc   rT  r  r  r  rL   rL   rM   0test_copy_page_copies_recursively_with_revisions  s     
z=TestCopyPage.test_copy_page_copies_recursively_with_revisionsc                 C   s   t jjdd}| jdd }|j  |jddddd	d
}| jdd }| 	|jj
 d | 	|jj
 dd d S )Nr   rR   rs   rO  Tr  r  r{  F)r  r}  r  r   r  r  r  rL   rL   rM   Ptest_copy_page_copies_recursively_but_doesnt_copy_revisions_if_told_not_to_do_so  s"    

z]TestCopyPage.test_copy_page_copies_recursively_but_doesnt_copy_revisions_if_told_not_to_do_soc                 C   s   t jjdd}| jdd j}|  | t	&}|j
dddd|d	 W d    n1 sb0    Y  | t|jd
 d S )Nr   rR   rs   rO  Tr  r  r{  )r  r}  to5You cannot copy a tree branch recursively into itself)r1   rI   r_   rS  ru   r   r   ra  rj   	Exceptionr~  ra   strrb  rc   rT  r  rb  rL   rL   rM   2test_copy_page_copies_recursively_to_the_same_tree  s    $z?TestCopyPage.test_copy_page_copies_recursively_to_the_same_treec                 C   s^   t  jjdd}tjjdd}|  |jddd|d}| |j| | | j	| d S )	Neventmoderator@example.comemailr   rR   r  r  r{  )r}  r   )
r   rI   r_   r2   ra  r~  ra   r  r  r   rc   Zevent_moderatorrZ  r  rL   rL   rM   test_copy_page_updates_user  s    	
z(TestCopyPage.test_copy_page_updates_userc                 C   s   t jjdd}|jddid}| |t  | |j|j | |j|j | |j	j|j	j | |j	j
j|j	j
j | |jd | tjj|jdt | tjj|jdt d S )N/home/events/saint-patrick/rR   rY   new-saint-patrickr  /home/events/new-saint-patrick/r]   )r@   rI   r_   r~  r  ra   excerptr  r^   eventpage_ptrpage_ptrrS   r2   r   rc   Zsaint_patrick_eventZnew_saint_patrick_eventrL   rL   rM   !test_copy_multi_table_inheritance  s0    z.TestCopyPage.test_copy_multi_table_inheritancec                    s   t jjdd}tddd}|jdd |j|d |   d	d
 |j	
 D  | t d | t
  t jjdd}|j|d}| |j|j dd
 |j	
 D }| t|d | t
| | t
 fdd|D  d S )Nr   rR   My tagged pagemy-tagged-pager{  wagtailbirdr[   c                 S   s   g | ]
}|j qS rL   r]   r  itemrL   rL   rM   
<listcomp>C      z;TestCopyPage.test_copy_page_copies_tags.<locals>.<listcomp>r   rQ   r  c                 S   s   g | ]
}|j qS rL   r]   r  rL   rL   rM   r  O  r  c                 3   s   | ]}| vV  qd S rH   rL   r  Zitem_idZold_tagged_item_idsrL   rM   	<genexpr>U  r  z:TestCopyPage.test_copy_page_copies_tags.<locals>.<genexpr>)r   rI   r_   rE   tagsaddr`   ra  rk  tagged_itemsr  ra   lenrt   r~  r  r^   rc   event_indexZtagged_pagerd   Znew_tagged_pagenew_tagged_item_idsrL   r  rM   test_copy_page_copies_tags;  s"    z'TestCopyPage.test_copy_page_copies_tagsc                    s   t jjdd}tddd}|jdd |j|d |   d	d
 |j	
 D  | t d | t
  t jjdd}|j|d}| |j|j dd
 |j	
 D }| t|d | t
| | t
 fdd|D  d S )Nr   rR   zMy very special tagged pagezmy-special-tagged-pager{  r  r  r[   c                 S   s   g | ]
}|j qS rL   r]   r  rL   rL   rM   r  b  r  zFTestCopyPage.test_copy_subclassed_page_copies_tags.<locals>.<listcomp>r   rQ   r  c                 S   s   g | ]
}|j qS rL   r]   r  rL   rL   rM   r  n  s   c                 3   s   | ]}| vV  qd S rH   rL   r  r  rL   rM   r  v  r  zETestCopyPage.test_copy_subclassed_page_copies_tags.<locals>.<genexpr>)r   rI   r_   rD   r  r  r`   ra  rk  r  r  ra   r  rt   r~  r  r^   )rc   r  Zsub_tagged_pagerd   Znew_sub_tagged_pager   rL   r  rM   %test_copy_subclassed_page_copies_tagsX  s*    z2TestCopyPage.test_copy_subclassed_page_copies_tagsc                 C   s   t jjdd}tjjdd}tjjddd}tdd	d
}|j|d |j	| t
jj||d |   t jjdd}|j|d}| |j|j d S )Nr   rR   Birdsr  http://www.heinz.com/beanz meanz heinzr   r  My blog pagemy-blog-pager{  r[   categoryr}   rQ   r  )r   rI   r_   r'   r   r%   r5   r`   advertsr  r(   ra  rk  r~  r  r^   rc   r  r*  advertZ	blog_pagerd   Znew_blog_pagerL   rL   rM   !test_copy_page_with_m2m_relationsy  s    z.TestCopyPage.test_copy_page_with_m2m_relationsc                 C   s   t jjdd}tjjddd}tddd}||_|j|d	 | 	  t jjd
d}|j
|d}| |j|j | |j| d S )Nr   rR   r$  r%  r&  My snippet pagemy-snippet-pager{  r[   rQ   r  )r   rI   r_   r%   r   r4   snippet_content_objectr`   ra  rk  r~  r  r^   ra   rc   r  r-  r}   rd   new_pagerL   rL   rM   'test_copy_page_with_generic_foreign_key  s    z4TestCopyPage.test_copy_page_with_generic_foreign_keyc                 C   sT   t jjdd}tddd}|j|d t jjdd}|j|d}| |j|j d S )	Nr   rR   My pagemy-pager{  r[   rQ   r  )r   rI   r_   r9   r`   r~  r  r^   rc   r  r}   rd   r3  rL   rL   rM    test_copy_page_with_o2o_relation  s    z-TestCopyPage.test_copy_page_with_o2o_relationc                 C   s   t jjdd}|jtdddddd}|  |j|d	d
id}|jjd }| 	|j
|j
 | |j|j | |j|j | |j|j | 	|j| d S )NrQ   rR   	DiscoverydiscoNCC-1031Context is for KingsrX   rY   rZ   special_fieldr[   rY   disco-2r  r}  r>  )r   rI   r_   r`   r:   ra  r~  r  rZ   ra   rX   r  r^   r   r>  )rc   rd   r}   r3  Zexclude_fieldrL   rL   rM   .test_copy_page_with_additional_excluded_fields  s"    z;TestCopyPage.test_copy_page_with_additional_excluded_fieldsc                 C   sr   t jjdd}|jtdddddd}tjj|d	 | |j	  |j
|d
|j did}| |j	  dS )zfTest that a page with a GenericRelation will have that relation ignored when
        copying.
        rQ   rR   r;   zpage-with-generic-relationTF)rX   rY   r  has_unpublished_changesr[   )Zcontent_objectrY   z-2r@  N)r   rI   r_   r`   r;   r<   r   r  Zgeneric_relationr   r~  rY   r   )rc   rd   original_pageZ	page_copyrL   rL   rM   test_page_with_generic_relation  s    z,TestCopyPage.test_page_with_generic_relationc                 C   s   zg dt _t jjdd}tjjdd}tjjdd}d|_||f|_|  |j	dd	d
d}| 
|jd | 
|jd | 
|j dd | 
|j dd | 
|j dd | 
|j dd W g t _ng t _0 dS )VTest that a page will be copied with parental and child relations removed if excluded.r  r  signup_linkr   rR   r  r  r  %https://christmas-is-awesome.com/rsvpr  r  r{  r  rh   r   r  r   HChild objects (parental many to many) were copied but should be excludedr   HChild objects defined on the original superclass were edited when copiedEChild objects defined on the superclass were copied and should not beN)r2   exclude_fields_in_copyrI   r_   r0   r   rG  r  r)  r~  ra   r  r  r  rL   rL   rM   9test_copy_page_with_excluded_parental_and_child_relations  sL    

zFTestCopyPage.test_copy_page_with_excluded_parental_and_child_relationsc                 C   sB   t ddd}| t |  W d   n1 s40    Y  dS )z*Test that unsaved page will not be copied.ZtestpurpZtestpurpose)rY   rX   N)r>   rj   r`  r~  )rc   r3  rL   rL   rM   test_copy_unsaved_page  s    z#TestCopyPage.test_copy_unsaved_pagec                 C   st   t jjdd}|jtddd |  |   |j	dddd	}|   | 
|j j|j j d
S )zn
        Test that a page with orderables can be copied and the translation
        keys are updated.
        r   rR   ZSantaZClausZ
first_name	last_namezOrderable Pageztranslated-orderable-pager{  r  N)r2   rI   r_   r  r  r3   r)  ra  rk  r~  r  r   translation_key)rc   rw   r3  rL   rL   rM   .test_copy_page_with_unique_uuids_in_orderables$  s&    

z;TestCopyPage.test_copy_page_with_unique_uuids_in_orderablesc              	      sv   t jjdd}d d fdd}t| z6|jddd	d
}|   | | W t| nt| 0 dS )zDTest that copying of a published page emits a page_published signal.r   rR   FNc                    s   d |d S NTrL   Zsenderr\   r   signal_firedZsignal_pagerL   rM   page_published_handlerG  s    zMTestCopyPage.test_copy_published_emits_signal.<locals>.page_published_handlerzNew christmasznew-christmasr{  r  )	r2   rI   r_   r#   connectr~  rt   ra   
disconnect)rc   rw   rW  Z	copy_pagerL   rU  rM    test_copy_published_emits_signal@  s    

z-TestCopyPage.test_copy_published_emits_signalc              	      sp   t jjdd}d|_|  d  fdd}t| z(|jddid |   W t	| nt	| 0 d	S )
zKTest that copying of an unpublished page not emits a page_published signal.rQ   rR   Fc                    s   d d S rS  rL   rT  rV  rL   rM   rW  `  s    zSTestCopyPage.test_copy_unpublished_not_emits_signal.<locals>.page_published_handlerrY   new_slugr  N)
r   rI   r_   r  r)  r#   rX  r~  r   rY  rc   rd   rW  rL   r[  rM   &test_copy_unpublished_not_emits_signalX  s    
z3TestCopyPage.test_copy_unpublished_not_emits_signalc              	      sd   t jjdd}d  fdd}z4t| |jdddid |   W t| nt| 0 d	S )
zXTest that copying of a live page with keep_live=False not emits a page_published signal.rQ   rR   Fc                    s   d d S rS  rL   rT  r[  rL   rM   rW  q  s    zWTestCopyPage.test_copy_keep_live_false_not_emits_signal.<locals>.page_published_handlerrY   r\  r|  N)r   rI   r_   r#   rX  r~  r   rY  r]  rL   r[  rM   *test_copy_keep_live_false_not_emits_signall  s    
z7TestCopyPage.test_copy_keep_live_false_not_emits_signalc                 C   sr   t jjdd}|jdd}|jddid}| |t  | |jd | |j	|j	 | |j
d | |j d S )	Nr   rR   zabout-us-aliasupdate_slugrY   zabout-us-alias-copyr  z/home/about-us-alias-copy/)r>   rI   r_   create_aliasr~  r  ra   rY   r  r^   rS   r   alias_of)rc   r  Zabout_us_aliasZabout_us_alias_copyrL   rL   rM   test_copy_alias_page}  s    z!TestCopyPage.test_copy_alias_pagec                 C   sf   t jjdd}tdddd}|j|d tjj|dd	 |jd
ddd}| tjj	|d
  dS )MTest that view restrictions attached to a page are copied along with the pagerQ   rR   Child Page 1child-page-1hello child page 1rW   r[   rV   r}   passwordChild Page 2child-page-2r{  r  r}   N)r   rI   r_   r>   r`   r   r   r~  rt   ru   rv   )rc   rd   child_page_1child_page_2rL   rL   rM   !test_copy_page_copies_restriction  s    z.TestCopyPage.test_copy_page_copies_restrictionc                 C   s   t jjdd}tdddd}|j|d tjj|dd	 td
ddd}|j|d tdddd}|j|d |j|dddd}| tjj	|d
  dS )STest that view restrictions on a page's ancestor are NOT copied along with the pagerQ   rR   Parent 1parent-1hello parent 1rW   r[   rV   ri  Parent 2parent-2hello parent 2rf  rg  rh  rk  rl  r{  r@  rm  Nr   rI   r_   r>   r`   r   r   r~  r   ru   rv   rc   rd   Zorigin_parentZdestination_parentrn  ro  rL   rL   rM   5test_copy_page_does_not_copy_restrictions_from_parent  s&    zBTestCopyPage.test_copy_page_does_not_copy_restrictions_from_parentc                 C   s   t jjdd}tdddd}|j|d tdd	d
d}|j|d tjj|dd tdddd}|j|d tjj|dd |j|dddd}| tjj	|d
  dS )rq  rQ   rR   rr  rs  rt  rW   r[   ru  rv  rw  rV   ri  rf  rg  rh  rk  rl  r{  r@  rm  Nrx  ry  rL   rL   rM   Itest_copy_page_does_not_copy_restrictions_when_new_parent_has_one_already  s(    zVTestCopyPage.test_copy_page_does_not_copy_restrictions_when_new_parent_has_one_alreadyN)'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.  r4  r8  rA  rD  rM  rN  rR  rZ  r^  r_  rd  rp  rz  r{  rL   rL   rL   rM   r    sH   !#&+2) $!E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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ejdd Zejd d! Zd"d# Zd$d% Zd&d' Zd(S ))TestCreateAliasrP   c                 C   s   t jjdd}d|_|jdgd |jdd}| |t  | |jd | |jd | 	|j
|j
 | |jd	 | |j| d S )
Nr   rR   zDraft titler   r'  rz  r`  zAbout usr  )r>   rI   r_   r   r)  rb  r  ra   rY   r  r^   rS   rc  r  rL   rL   rM   test_create_alias  s    z!TestCreateAlias.test_create_aliasc                 C   sn   t jjdd}|jdd}| |j dd | |j dd | |j dd | |j dd	 d S )
Nr   rR   r  r`  r   r  r  r  r  )r2   rI   r_   rb  ra   r  r  r  r  rL   rL   rM   &test_create_alias_copies_child_objects  s,    z6TestCreateAlias.test_create_alias_copies_child_objectsc                 C   s   t jjdd}tjjdd}tjjdd}||f|_|  |jdd}| |j	 dd	 | |j	 dd
 | |j
  |j
   dS )r  r   rR   r  r  r  r  r`  r   r  r  N)r2   rI   r_   r0   r   r  r)  rb  ra   r  r  r  r  rL   rL   rM   +test_create_alias_copies_parental_relations	  s,    
z;TestCreateAlias.test_create_alias_copies_parental_relationsc                 C   s8   t jjdd}|  |jdd}| |j d d S )Nr   rR   r  r`  r   )r2   rI   r_   ra  rb  ra   r  r  r  rL   rL   rM   'test_create_alias_doesnt_copy_revisions<	  s    z7TestCreateAlias.test_create_alias_doesnt_copy_revisionsc                 C   s>   t jjdd}|jdd}| |t | |j dd d S )Nr   rR   r  r`  r   r  )	r   rI   r_   rb  r  r2   ra   r  r  r  rL   rL   rM   =test_create_alias_copies_child_objects_with_nonspecific_classH	  s    zMTestCreateAlias.test_create_alias_copies_child_objects_with_nonspecific_classc                 C   s|   t jjdd}|jddd}| jdd }| jdd }| |d | |d	 | |j	d
 | |j
| d S )Nr   rR   Tr  r  ra  rs   rO  r  r  r  )r1   rI   r_   rb  rS  ru   r   r  ra   rS   rc  r  rL   rL   rM   $test_create_alias_copies_recursivelyY	  s     z4TestCreateAlias.test_create_alias_copies_recursivelyc                 C   st   t jjdd}|jddd}| jdd }| jdd }| |jj	
 dd	 | |jj	
 dd
 d S )Nr   rR   Tr  r  rs   rO  r   r  r  )r1   rI   r_   rb  rS  ru   r   ra   r   r  r  r  rL   rL   rM   7test_create_alias_copies_recursively_with_child_objectsw	  s$    

zGTestCreateAlias.test_create_alias_copies_recursively_with_child_objectsc                 C   sz   t jjdd}| jdd j}|  | t	}|j
d|d W d    n1 sZ0    Y  | t|jd d S )Nr   rR   rs   rO  T)r  r  r  )r1   rI   r_   rS  ru   r   r   ra  rj   r  rb  ra   r  rb  r  rL   rL   rM   :test_create_alias_doesnt_copy_recursively_to_the_same_tree	  s    ,zJTestCreateAlias.test_create_alias_doesnt_copy_recursively_to_the_same_treec                 C   sF   t  jjdd}tjjdd}|  |jd|d}| |j| d S )Nr  r  r   rR   r  )ra  r   )r   rI   r_   r2   ra  rb  ra   r  r  rL   rL   rM   test_create_alias_updates_user	  s    z.TestCreateAlias.test_create_alias_updates_userc                 C   s   t jjdd}|jdd}| |t  | |j|j | |j|j | |j	j|j	j | |j	j
j|j	j
j | |jd | tjj|jdt | tjj|jdt d S )Nr  rR   r  r`  r  r]   )r@   rI   r_   rb  r  ra   r	  r  r^   r
  r  rS   r2   r   r  rL   rL   rM   )test_create_alias_multi_table_inheritance	  s0    z9TestCreateAlias.test_create_alias_multi_table_inheritancec                    s   t jjdd}tddd}|jdd |j|d |   d	d
 |j	
 D  | t d | t
  t jjdd}|j|d}| |j|j dd
 |j	
 D }| t|d | t
| | t
 fdd|D  d S )Nr   rR   r  r  r{  r  r  r[   c                 S   s   g | ]
}|j qS rL   r]   r  rL   rL   rM   r  	  r  zATestCreateAlias.test_create_alias_copies_tags.<locals>.<listcomp>r   rQ   r  c                 S   s   g | ]
}|j qS rL   r]   r  rL   rL   rM   r  	  r  c                 3   s   | ]}| vV  qd S rH   rL   r  r  rL   rM   r  	  r  z@TestCreateAlias.test_create_alias_copies_tags.<locals>.<genexpr>)r   rI   r_   rE   r  r  r`   ra  rk  r  r  ra   r  rt   rb  r  r^   r  rL   r  rM   test_create_alias_copies_tags	  s"    z-TestCreateAlias.test_create_alias_copies_tagsc                 C   s   t jjdd}tjjdd}tjjddd}tdd	d
}|j|d |j	| t
jj||d |   t jjdd}|j|d}| |j|j d S )Nr   rR   r#  r  r$  r%  r&  r'  r(  r{  r[   r)  rQ   r  )r   rI   r_   r'   r   r%   r5   r`   r+  r  r(   ra  rk  rb  r  r^   r,  rL   rL   rM   $test_create_alias_with_m2m_relations	  s    z4TestCreateAlias.test_create_alias_with_m2m_relationsc                 C   s   t jjdd}tjjddd}tddd}||_|j|d	 | 	  t jjd
d}|j
|d}| |j|j | |j| d S )Nr   rR   r$  r%  r&  r/  r0  r{  r[   rQ   r  )r   rI   r_   r%   r   r4   r1  r`   ra  rk  rb  r  r^   ra   r2  rL   rL   rM   *test_create_alias_with_generic_foreign_key
  s    z:TestCreateAlias.test_create_alias_with_generic_foreign_keyc                 C   sT   t jjdd}tddd}|j|d t jjdd}|j|d}| |j|j d S )	Nr   rR   r5  r6  r{  r[   rQ   r  )r   rI   r_   r9   r`   rb  r  r^   r7  rL   rL   rM   #test_create_alias_with_o2o_relation
  s    z3TestCreateAlias.test_create_alias_with_o2o_relationc                 C   sx   t jjdd}|jtdddddd}|j|d	d
}| |j|j | |j	|j	 | |j
|j
 | |j|j d S )NrQ   rR   r9  r:  r;  r<  r=  r[   r?  r  ra  )r   rI   r_   r`   r:   rb  ra   rX   r  r^   r   r>  )rc   rd   r}   r3  rL   rL   rM   1test_create_alias_with_additional_excluded_fields+
  s    zATestCreateAlias.test_create_alias_with_additional_excluded_fieldsc                 C   s   zg dt _t jjdd}tjjdd}tjjdd}d|_||f|_|  |j	dd	}| 
|jd | 
|jd
 | 
|j dd | 
|j dd | 
|j dd | 
|j dd W g t _ng t _0 dS )rE  rF  r   rR   r  r  r  rH  r  r`  rh   r   r  r   rI  r   rJ  rK  N)r2   rL  rI   r_   r0   r   rG  r  r)  rb  ra   r  r  r  rL   rL   rM   <test_create_alias_with_excluded_parental_and_child_relations>
  sH    

zLTestCreateAlias.test_create_alias_with_excluded_parental_and_child_relationsc                 C   s   t jjdd}tdddd}|j|d tjjdd	}tjj|tjd
}|j	
| |jdd}tjj|d}| t|j	jddd|jg dS )re  rQ   rR   rf  rg  rh  rW   r[   z
Test Groupr  )r}   restriction_typerl  r`  rm  r^   Tr  N)r   rI   r_   r>   r`   r   r   r   ZGROUPSgroupsr  rb  ra   listr  r  )rc   rd   rn  groupZrestrictionro  Zcopied_restrictionrL   rL   rM   "test_alias_page_copies_restriction
  s    z2TestCreateAlias.test_alias_page_copies_restrictionc                 C   s   t jjdd}tdddd}|j|d tjj|dd	 td
ddd}|j|d tdddd}|j|d |j|dd}| tjj	|d
  dS )rq  rQ   rR   rr  rs  rt  rW   r[   rV   ri  ru  rv  rw  rf  rg  rh  rl  r  rm  Nr   rI   r_   r>   r`   r   r   rb  r   ru   rv   ry  rL   rL   rM   6test_alias_page_does_not_copy_restrictions_from_parent
  s&    zFTestCreateAlias.test_alias_page_does_not_copy_restrictions_from_parentc                 C   s   t jjdd}tdddd}|j|d tdd	d
d}|j|d tjj|dd tdddd}|j|d tjj|dd |j|dd}| tjj	|d
  dS )rq  rQ   rR   rr  rs  rt  rW   r[   ru  rv  rw  rV   ri  rf  rg  rh  rl  r  rm  Nr  ry  rL   rL   rM   Jtest_alias_page_does_not_copy_restrictions_when_new_parent_has_one_already
  s(    zZTestCreateAlias.test_alias_page_does_not_copy_restrictions_when_new_parent_has_one_alreadyN)r   r   r   r   r}  r~  r  r  r  r  r  r  r  r  r  r  r  r  unittestZexpectedFailurer  r  r  r  r  rL   rL   rL   rM   r|    s,   !#$

Br|  c                   @   s"   e Zd ZdgZdd Zdd ZdS )TestUpdateAliasesrP   c                 C   sX  t jjdd}|jdd}|jdd}d|_d|_|jtdd	d
 |	  |
  |
  | |jd | |jd | |j d | |j d tj   |  |
  |
  | |jd | |jd | |j d | |j d | |jd | |jd | tjj|dd  | tjj|dd  d S )Nr   rR   new-event-pager`  new-event-page-2zUpdated titlezA different draft titleZTedZCrillyrO  rr   r   r   wagtail.publishr}   action)r2   rI   r_   rb  rX   r   r  r  r3   r)  rl  ra   r  r   r  deleteupdate_aliasesr   ru   rv   rc   rA  aliasZalias_aliasrL   rL   rM   test_update_aliases
  sH    z%TestUpdateAliases.test_update_aliasesc                 C   s  t jjdd}d|_d|_|jdd |jdd}|jdd}| |j | |j d|_d|_|jdd |  |  | |j | |j t	j
   |  |  |  | |j | |j | t	jj|d	d
  | t	jj|d	d
  d S )Nr   rR   FTcleanr  r`  r  r  r  )r2   rI   r_   r  rB  r)  rb  r   rl  r   r  r  r  rt   ru   rv   r  rL   rL   rM   $test_update_aliases_publishes_drafts  s:    z6TestUpdateAliases.test_update_aliases_publishes_draftsN)r   r   r   r   r  r  rL   rL   rL   rM   r  
  s   2r  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S )TestCopyForTranslationrP   c                 C   sR   t jjddj| _tjjdd| _tjjdd| _| j	 | _
tjjdd| _d S )NrQ   rR   r   r   r  r$  )r   rI   r_   r   en_homepager1   en_eventindexr2   en_eventpager  r   r   r   r*  r  rL   rL   rM   r   <  s
    zTestCopyForTranslation.setUpc                 C   s   | j | j}| | j j|j | |j| j | |j| j j | |jd | 	|j
 | |j tjjdd}| |jd d d | |jd d d d	 | |jd
 d S )Nhome-frwagtail.copy_for_translationr  source_localer%  r  r}   localer  z*Copied for translation from Root (English))r  r(  r*  r  r^   ra   r  rQ  rY   r   r  rt   rB  r   rI   r_   datamessage)rc   r+  	log_entryrL   rL   rM   test_copy_homepageC  s    z)TestCopyForTranslation.test_copy_homepagec                 C   s8   | j jtddddd | j| j}| |jd d S )NzOld french homepager  zTest contentrW   r[   z	home-fr-1)r   r`   r>   r  r(  r*  ra   rY   )rc   r+  rL   rL   rM   test_copy_homepage_slug_existsY  s    z5TestCopyForTranslation.test_copy_homepage_slug_existsc                 C   s   | j jtdd| j| jjdd}| j| j}| | jj	|j	 | 
|j| j | 
|j| jj | 
| | | 
| jj|j tjjdd}| 
|jd d d	 | 
|jd
 d d d | 
|jd d S )Nfrench homepager  rX   rY   r  rQ  r[   r  r  r  r%  r  r}   r  r  zGCopied for translation from Welcome to the Wagtail test site! (English))r   r`   r   r*  r  rQ  r  r(  r  r^   ra   r  r  rY   r   rI   r_   r  r  )rc   r+  fr_eventindexr  rL   rL   rM   test_copy_childpagee  s.    	
z*TestCopyForTranslation.test_copy_childpagec                 C   s<   |  t | j| j W d    n1 s.0    Y  d S rH   )rj   r   r  r(  r*  r  rL   rL   rM   "test_copy_childpage_without_parent  s    z9TestCopyForTranslation.test_copy_childpage_without_parentc                 C   s   | j j| jdd}| | j j|j | |j| j | |j| j j | | j j|j |	 }| | j
j|j | |j| j | |j| j
j | |jd d S )NTr&  r  )r  r(  r*  r  r^   ra   r  rQ  rY   r  r  )rc   r  r+  rL   rL   rM   %test_copy_childpage_with_copy_parents  s    
z<TestCopyForTranslation.test_copy_childpage_with_copy_parentsc                 C   s   | j jtdd| j| jjdd}|jtdd| j| jjdd | jj	
 }| j| j}|j	
 }| |j| j | |j|j | t| |g d S )Nr  r  r  r[   rm   rp   )r   r`   r   r*  r  rQ  r1   r  r  r  r_   r(  ra   r  r  Zget_translations)rc   r+  Z
en_speakerfr_eventpageZ
fr_speakerrL   rL   rM   .test_copy_page_with_translatable_child_objects  s,    	
zETestCopyForTranslation.test_copy_page_with_translatable_child_objectsc                 C   sP   | j j| jdd}| }| |j| j | |j| jj | |j| j d S )NTr&  )	r  r(  r*  r  ra   r  rQ  r  rc  )rc   r  r  rL   rL   rM   &test_copies_missing_parents_as_aliases  s    
z=TestCopyForTranslation.test_copies_missing_parents_as_aliasesN)r   r   r   r   r   r  r  r  r  r  r  r  rL   rL   rL   rM   r  9  s   "*r  c                   @   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S )TestSubpageTypeBusinessRulesc                 C   s   |  tt  |  tt  | tt  | tt  | tt  | tt  | tt  |  tt  d S rH   )assertInr>   Zallowed_subpage_modelsr*   assertNotInr,   r)   r  rL   rL   rM   test_allowed_subpage_models  s    z8TestSubpageTypeBusinessRules.test_allowed_subpage_modelsc                 C   sd   |  tt  | tt  | tt  | tt  | tt  |  tt  d S rH   )	r  r>   Zallowed_parent_page_modelsr  r)   r+   rB   r,   r*   r  rL   rL   rM   test_allowed_parent_page_models  s    z<TestSubpageTypeBusinessRules.test_allowed_parent_page_modelsc                 C   s   |  tt  |  tt  | tt  |  tt  |  tt  |  tt  | tt  | tt  | tt  d S rH   )	rt   r>   Zcan_exist_underrB   r   r   r,   r*   r)   r  rL   rL   rM   test_can_exist_under   s    z1TestSubpageTypeBusinessRules.test_can_exist_underc                 C   s   |  tt  | tt  | tt  |  tt  | tt  | tt  | tt  |  tt  |  tt  d S rH   )	r   r   can_create_atrt   r>   rB   r,   r*   r)   r  rL   rL   rM   test_can_create_at  s    z/TestSubpageTypeBusinessRules.test_can_create_atc                 C   s~   t jjdd}|jtdddd}|jtdddd}| t| |jtdd	dd | t| | t| d S )
NrQ   rR   zsimple parentzsimple-parentr{  r[   zsimple-parent-2zsimple childzsimple-child)	r   rI   r_   r`   r?   rt   r=   r  r   )rc   r   Zparent1Zparent2rL   rL   rM   ;test_can_create_at_with_max_count_per_parent_limited_to_one#  s    


zXTestSubpageTypeBusinessRules.test_can_create_at_with_max_count_per_parent_limited_to_onec                 C   s   |  t t  |  t t  | t t  |  t t  |  t t  |  t t  | t t  | t t  d S rH   )	rt   r>   Zcan_move_torB   r   r   r,   r*   r)   r  rL   rL   rM   test_can_move_to:  s    z-TestSubpageTypeBusinessRules.test_can_move_toc                 C   sF   t jjdd}| t| |jtdddd | t| d S )NrQ   rR   Z	singletonr{  r[   )r   rI   r_   rt   rA   r  r`   r   rc   r   rL   rL   rM   test_singleton_page_creationI  s    z9TestSubpageTypeBusinessRules.test_singleton_page_creationN)
r   r   r   r  r  r  r  r  r  r  rL   rL   rL   rM   r    s   r  c                   @   s   e Zd ZdZdgZdd ZdS )TestIssue735z~
    Issue 735 reports that URL paths of child pages are not
    updated correctly when slugs of parent pages are updated
    rP   c                 C   sR   t jjddj}tjjdd}d|_|   tjj|jd}| 	|j
d d S )Nr   rR   r   z
old-eventsr]   z/home/old-events/christmas/)r   rI   r_   r   r2   rY   ra  rk  r^   ra   rS   )rc   r  rZ  r  rL   rL   rM   )test_child_urls_updated_on_parent_publish^  s    z6TestIssue735.test_child_urls_updated_on_parent_publishN)r   r   r   __doc__r   r  rL   rL   rL   rM   r  V  s   r  c                   @   s   e Zd ZdZdd ZdS )TestIssue756z
    Issue 756 reports that the latest_revision_created_at
    field was getting clobbered whenever a revision was published
    c                 C   sJ   t jjdd }| t jjddj |  | t jjddj d S )Nr   r]   )r   rI   r_   ra  r  latest_revision_created_atrk  )rc   ru  rL   rL   rM   >test_publish_revision_doesnt_remove_latest_revision_created_atq  s    zKTestIssue756.test_publish_revision_doesnt_remove_latest_revision_created_atN)r   r   r   r  r  rL   rL   rL   rM   r  k  s   r  c                   @   s   e Zd ZdZdgZdd ZdS )TestIssue1216zG
    Test that url paths greater than 255 characters are supported
    rP   c                 C   s   t jjddj}tjjddj}dd }||_|   dd }||_|   tjj|jd}d	||}| 
|j| d S )	Nr   rR   r   zchristmas-%s-christmasZ01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789zevents-%s-eventsr]   z/home/{}/{}/)r   rI   r_   r   r2   rY   ra  rk  r^   r   ra   rS   )rc   r  rZ  Znew_christmas_slugZnew_event_index_slugr  Zexpected_url_pathrL   rL   rM   'test_url_path_can_exceed_255_characters  s    z5TestIssue1216.test_url_path_can_exceed_255_charactersN)r   r   r   r  r   r  rL   rL   rL   rM   r    s   r  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestIsCreatablec                 C   s   |  tj | tt  dS )z%By default, pages should be creatableN)rt   r>   is_creatabler  r!   r  rL   rL   rM   test_is_creatable_default  s    z)TestIsCreatable.test_is_creatable_defaultc                 C   s   |  tj | tt  dS )z3Page types should be able to disable their creationN)r   r6   r  r  r!   r  rL   rL   rM   test_is_creatable_false  s    z'TestIsCreatable.test_is_creatable_falsec                 C   s   |  tj | tt  dS )z
        is_creatable should not be inherited in the normal manner, and should
        default to True unless set otherwise
        N)rt   r7   r  r  r!   r  rL   rL   rM   test_is_creatable_not_inherited  s    z/TestIsCreatable.test_is_creatable_not_inheritedc                 C   s   |  tj | tt  dS )z9
        Abstract models should not be creatable
        N)r   r$   r  r  r!   r  rL   rL   rM   test_abstract_pages  s    z#TestIsCreatable.test_abstract_pagesN)r   r   r   r  r  r  r  rL   rL   rL   rM   r    s   r  c                   @   s   e Zd Zdd ZdS )TestDeferredPageClassesc                 C   s2   t tjd dd t D }| |tg dS )z
        In Django <1.10, a call to `defer` such as `SimplePage.objects.defer('content')`
        will dynamically create a subclass of SimplePage. Ensure that these subclasses
        are not registered in the get_page_models() list
        rZ   c                 S   s   g | ]}t |tr|qS rL   )
issubclassr>   )r  clsrL   rL   rM   r    s   zYTestDeferredPageClasses.test_deferred_page_classes_are_not_registered.<locals>.<listcomp>N)r  r>   rI   deferr!   ra   )rc   Zsimplepage_subclassesrL   rL   rM   -test_deferred_page_classes_are_not_registered  s
    zETestDeferredPageClasses.test_deferred_page_classes_are_not_registeredN)r   r   r   r  rL   rL   rL   rM   r    s   r  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestPageManagerc                 C   s   |  ttjt dS )z=
        Assert that the Page class uses PageManager
        N)r   typer   rI   r   r  rL   rL   rM   test_page_manager  s    z!TestPageManager.test_page_managerc                 C   s   |  ttjt dS )z
        Assert that Page subclasses get a PageManager without having to do
        anything special. MTI subclasses do *not* inherit their parents Manager
        by default.
        N)r   r  r>   rI   r   r  rL   rL   rM   test_page_subclass_manager  s    z*TestPageManager.test_page_subclass_managerc                 C   s   |  ttjt dS )z
        Subclasses should be able to override their default Manager, and
        Wagtail should respect this. It is up to the developer to ensure their
        custom Manager inherits from PageManager.
        N)r   r  r.   rI   r-   r  rL   rL   rM   test_custom_page_manager  s    z(TestPageManager.test_custom_page_managerc                 C   sd   |  ttj t |  ttj t |  ttj  t |  ttj  t dS )z
        Managers that are constructed from a custom PageQuerySet
        (via PageManager.from_queryset(CustomPageQuerySet)) should return
        querysets of that type
        N)r   r  r.   rI   r  r/   Z
about_spamr  rL   rL   rM   test_custom_page_queryset  s    z)TestPageManager.test_custom_page_querysetc                 C   s   |  ttjt dS )z
        Abstract base classes should be able to override their default Manager,
        and Wagtail should respect this. It is up to the developer to ensure
        their custom Manager inherits from PageManager.
        N)r   r  r8   rI   r-   r  rL   rL   rM   test_abstract_base_page_manager  s    z/TestPageManager.test_abstract_base_page_managerN)r   r   r   r  r  r  r  r  rL   rL   rL   rM   r    s
   r  c                   @   s   e Zd ZdZdgZdd ZdS )TestIssue2024zP
    This tests that deleting a content type can't delete any Page objects.
    rP   c                 C   sD   t jjdd}|j}|  t jjdd}| |jtjt  d S )Nr   rR   )r   rI   r_   content_typer  ra   r   rJ   )rc   r  Zevent_index_content_typerL   rL   rM   test_delete_content_type  s    z&TestIssue2024.test_delete_content_typeN)r   r   r   r  r   r  rL   rL   rL   rM   r    s   r  c                   @   sb   e Zd ZdgZdd Zdd Zdd Zdd	 Zed
gddd Z	edgddd Z
dd ZdS )TestMakePreviewRequestrP   c                 C   s(  t jjdd}| }| |jd |jd }| |jd | |jd d | |j	d d	 | |j	d
 d | |j	d d | |j	d d | |j	d d | |j	d d | |j	d d | |j	d d | 
d|j	 | 
d|j	 | 
d|j	 | 
d|j	 | 
d|j	 d S )Nr   rR   r   r   rC  hostr   REQUEST_METHODGETSCRIPT_NAMErh   	PATH_INFOSERVER_NAMEr   P   SERVER_PROTOCOLHTTP/1.1wsgi.versionr   r   wsgi.url_schemehttp
wsgi.inputwsgi.errorswsgi.multithreadwsgi.multiprocesswsgi.run_once)r   rI   r_   make_preview_requestra   r   r   r   headersr   r  rc   r  r   r   rL   rL   rM   -test_make_preview_request_for_accessible_page  s&    
zDTestMakePreviewRequest.test_make_preview_request_for_accessible_pagec                 C   s6  t jjdd tjjdd}| }| |jd |jd }| |j	d | |j
d d	 | |jd
 d | |jd d | |jd d | |jd d	 | |jd d | |jd d | |jd d | |jd d | d|j | d|j | d|j | d|j | d|j d S )Ni  r   r   rR   r   r   rC  r  r   r  r  r  rh   r  r  r   r  r  r  r  r  httpsr  r  r  r  r  r   rI   r   r   r_   r  ra   r   r   r   r  r   r  r  rL   rL   rM   3test_make_preview_request_for_accessible_page_https+  s(    
zJTestMakePreviewRequest.test_make_preview_request_for_accessible_page_httpsc                 C   s6  t jjdd tjjdd}| }| |jd |jd }| |j	d | |j
d d	 | |jd
 d | |jd d | |jd d | |jd d | |jd d | |jd d | |jd d | |jd d | d|j | d|j | d|j | d|j | d|j d S )Ni"  r  r   rR   r   r   rC  r  zlocalhost:8888r  r  r  rh   r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r   r  rL   rL   rM   ?test_make_preview_request_for_accessible_page_non_standard_portF  s(    
zVTestMakePreviewRequest.test_make_preview_request_for_accessible_page_non_standard_portc                 C   s  t jjdd}dddddd}tf i |}|d}||}| |jd	 |jd
 }| |jd |jd  | |j	d |jd  | |j	d |jd  | |j	d |jd  | |j	d |jd  | |jd d | |jd d | |jd d | |jd d | |jd d | |jd d | |jd  d! | |jd" d# | 
d$|j | 
d%|j | 
d&|j | 
d'|j | 
d(|j d S ))Nr   rR   z192.168.0.1z192.168.0.2,192.168.0.3ztest=1;blah=2z
Test AgentzBasic V2FndGFpbDpXYWd0YWlsCg==)REMOTE_ADDRHTTP_X_FORWARDED_FORHTTP_COOKIErH  HTTP_AUTHORIZATIONr   r   r  zx-forwarded-forr  cookier  z
user-agentrH  authorizationr  r  r  r  rh   r  rC  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  )r   rI   r_   r   r  ra   r   r   r   r  r  )rc   r  Zoriginal_headersfactoryZoriginal_requestr   r   rL   rL   rM   Ctest_make_preview_request_for_accessible_page_with_original_requesta  sT    


zZTestMakePreviewRequest.test_make_preview_request_for_accessible_page_with_original_requestproduction.example.comr   c                 C   sD   t jjdd}| }| |jd |jd }| |jd d d S )Nr   rR   r   r   r  r  )r   rI   r_   r  ra   r   r   r  rc   r   r   r   rL   rL   rM   Etest_make_preview_request_for_inaccessible_page_should_use_valid_host  s
    
z\TestMakePreviewRequest.test_make_preview_request_for_inaccessible_page_should_use_valid_host*c                 C   sD   t jjdd}| }| |jd |jd }| |jd d d S )Nr   rR   r   r   r  r  )	r   rI   r_   r  ra   r   r   r  r  r  rL   rL   rM   Ktest_make_preview_request_for_inaccessible_page_with_wildcard_allowed_hosts  s
    
zbTestMakePreviewRequest.test_make_preview_request_for_inaccessible_page_with_wildcard_allowed_hostsc                 C   s   t jjdd}tddgd}|j|d t jj|jd}| d | |  W d    n1 sf0    Y  | d	 | |  W d    n1 s0    Y  | d | 	|  W d    n1 s0    Y  d S )
Nr   rR   zstream page)r  rV   )rX   bodyr[   r]   r   r   )
r   rI   r_   rC   r`   r^   r   r   Zis_previewablert   )rc   r  Zstream_pageZplain_stream_pagerL   rL   rM   test_is_previewable  s    ,,z*TestMakePreviewRequest.test_is_previewableN)r   r   r   r   r  r  r  r
  r   r  r  r  rL   rL   rL   rM   r    s   1



r  c                   @   s&   e Zd ZdZdgZdd Zdd ZdS )TestShowInMenusDefaultOptionzQ
    This tests that a page model can define the default for 'show_in_menus'
    rP   c                 C   s   t ddd}| |j d S NzMy Awesome Pagezmy-awesome-pager{  )r   r   show_in_menusr|   rL   rL   rM   test_show_in_menus_default  s    z7TestShowInMenusDefaultOption.test_show_in_menus_defaultc                 C   s   t ddd}| |j d S r  )r&   rt   r  r|   rL   rL   rM   #test_show_in_menus_default_override  s    z@TestShowInMenusDefaultOption.test_show_in_menus_default_overrideN)r   r   r   r  r   r  r  rL   rL   rL   rM   r    s   r  c                   @   s   e Zd ZdgZdd ZdS )TestPageWithContentJSONrP   c                 C   s   t jjdd}tjt}| }|jdddd|jd |j	d |j
d |jd dd	d	|j d
dd	|j |j|j dd ||}dD ]}| t||t|| qdD ]}| t||t|| q| |jd d S )Nr   rR   z
About themz
about-themz/home/some-section/about-them/r  ZABCDEFz<p>They are not as good</p>z2000-01-01T00:00:00ZTr   )rX   r   rY   rS   r  numchildrR  r   rZ   rr  ro  r  locked	locked_by	locked_atrB  r  r  r  )rX   rY   rZ   rS   r  )r  r   rR  r  r  r   r  rB  r  r  r  r  r  rr  z/home/about-them/)r>   rI   r_   r   rJ   r2   Zserializable_datar   r  r  rR  r   r  rB  r^   r  Zwith_content_jsonr  r  ra   rS   )rc   rC  Zeventpage_content_typerZ   Zupdated_page	attr_namerL   rL   rM   'test_with_content_json_preserves_values  sD    
z?TestPageWithContentJSON.test_with_content_json_preserves_valuesN)r   r   r   r   r  rL   rL   rL   rM   r    s   r  c                   @   s"   e Zd ZdgZdd Zdd ZdS )TestUnpublishrP   c                 C   s<   t jjdd}|jtddddd}|jdd	 |  d S )
Nr   r]   ZHomepageZhome2rV   rW   r[   Fr  )r   rI   r_   r`   r>   r)  rw  )rc   r   Z	home_pagerL   rL   rM   1test_unpublish_doesnt_call_full_clean_before_save  s    z?TestUnpublish.test_unpublish_doesnt_call_full_clean_before_savec                 C   s   t jjdd}|jdd}|jdd}| |j | |j | |j tj   |	  |
  |
  | |j | |j | |j | tjj|dd  | tjj|dd  d S )Nr   rR   r  r`  r  zwagtail.unpublishr  )r2   rI   r_   rb  rt   r  r   r  r  rw  rl  r   ru   rv   r  rL   rL   rM   'test_unpublish_also_unpublishes_aliases&  s*    z5TestUnpublish.test_unpublish_also_unpublishes_aliasesN)r   r   r   r   r  r   rL   rL   rL   rM   r    s   
r  c                   @   s    e Zd ZdZdd Zdd ZdS )TestCachedContentTypez"Tests for Page.cached_content_typec                 C   s4   t j }|jtddddd| _tjt| _d S NTest1test1r  rW   r[   )	r   rI   r   r`   r>   r}   r   rJ   Zspecific_page_ctyper  rL   rL   rM   r   H  s
    
zTestCachedContentType.setUpc                 C   sP   |  d | jj}W d   n1 s(0    Y  | |tjj| jjd dS )z
        The return value should match the value you'd get
        if fetching the ContentType from the database,
        and shouldn't trigger any database queries when
        the ContentType is already in memory.
        r   Nr]   )r   r}   Zcached_content_typera   r   rI   r_   Zcontent_type_idr  rL   rL   rM   test_golden_pathO  s    &z&TestCachedContentType.test_golden_pathN)r   r   r   r  r   r%  rL   rL   rL   rM   r!  E  s   r!  c                   @   s   e Zd Zdd Zdd ZdS )TestGetTranslatableModelsc                 C   sF   t  }| t| | t| | t| | t| | t| d S rH   )r"   r  r2   r  r   r3   r   r%   rc   Ztranslatable_modelsrL   rL   rM   test_get_translatable_models\  s    z6TestGetTranslatableModels.test_get_translatable_modelsc                 C   sJ   t dd}| t| | t| | t| | t| | t| d S )NT)Zinclude_subclasses)r"   r  r2   r   r3   r  r   r%   r'  rL   rL   rM   /test_get_translatable_models_include_subclassesg  s    
zITestGetTranslatableModels.test_get_translatable_models_include_subclassesN)r   r   r   r(  r)  rL   rL   rL   rM   r&  [  s   r&  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestDefaultLocalec                 C   s   t j | _d S rH   )r   rI   r   r   r  rL   rL   rM   r   s  s    zTestDefaultLocale.setUpc                 C   s.   | j jtddddd}| |j| j j d S r"  )r   r`   r>   ra   r  r|   rL   rL   rM   test_default_localev  s    z%TestDefaultLocale.test_default_localec                 C   s:   t jjdd}| jjtddd|dd}| |j| d S )Nr  r$  r#  r$  r  rX   rY   rZ   r  r[   r   rI   r   r   r`   r>   ra   r  )rc   r*  r}   rL   rL   rM   test_override_default_locale}  s    z.TestDefaultLocale.test_override_default_localec                 C   sP   t jjdd}| jjtddd|dd}|jtddddd}| |j| d S )	Nr  r$  r#  r$  r  r,  r[   rW   r-  )rc   r*  Zfr_pager}   rL   rL   rM   %test_always_defaults_to_parent_locale  s    z7TestDefaultLocale.test_always_defaults_to_parent_localeN)r   r   r   r   r+  r.  r/  rL   rL   rL   rM   r*  r  s   r*  r  c                   @   sT   e Zd Zdg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S )TestLocalizedrP   c                 C   s^   t jjdd| _tjjdd| _| jj| jdd| _d| j_	| jj
dgd	 | j   d S )
Nr  r$  r   rR   Tr&  u   NoëlrX   r'  )r   rI   r   r*  r   r_   rA  r(  fr_event_pagerX   r)  ra  rk  r  rL   rL   rM   r     s    zTestLocalized.setUpc                 C   s(   |  | jj| j |  | jj| j d S rH   )ra   rA  	localizedlocalized_draftr  rL   rL   rM   test_localized_same_language  s    z*TestLocalized.test_localized_same_languagec                 C   sV   t d8 | | jj| jj | | jj| jj W d    n1 sH0    Y  d S r  )r   r  ra   rA  r3  r2  r  r4  r  rL   rL   rM   !test_localized_different_language  s
    z/TestLocalized.test_localized_different_languageFr0  c                 C   sR   t d4 | | jj| j | | jj| j W d   n1 sD0    Y  dS )z<Should return the same page if WAGTAIL_I18N_ENABLED is Falser  N)r   r  ra   rA  r3  r4  r  rL   rL   rM   Atest_localized_different_language_with_wagtail_i18n_enabled_false  s    zOTestLocalized.test_localized_different_language_with_wagtail_i18n_enabled_falsec                 C   sh   | j   | j   td6 | | jj| j | | jj| j j	 W d    n1 sZ0    Y  d S r  )
r2  rw  r)  r   r  ra   rA  r3  r4  r  r  rL   rL   rM   -test_localized_different_language_unpublished  s    

z;TestLocalized.test_localized_different_language_unpublishedc                 C   sz   t d\ | | jj| j | | jj| jj | | jj| j | | jj| jj W d    n1 sl0    Y  d S )Nde)r   r  ra   rA  r3  r2  r   r4  r  rL   rL   rM   -test_localized_with_non_content_active_locale  s    z;TestLocalized.test_localized_with_non_content_active_localec                 C   s   t jjdd}d|_|  tdX | | jj	| j | | j
j	| j
 | | jj| j | | j
j| j
 W d    n1 s0    Y  d S )Nr  r$  plr9  )r   rI   r_   r%  r)  r   r  ra   rA  r3  r2  r4  )rc   Z	en_localerL   rL   rM   *test_localized_with_missing_default_locale  s    z8TestLocalized.test_localized_with_missing_default_localeN)r   r   r   r   r   r5  r6  r   r7  r8  r:  r<  rL   rL   rL   rM   r1    s   


r1  c                   @   sL   e Zd ZdgZdd Zdd Zdd Zedd	d
d Zdd Z	dd Z
dS )TestGetLockrP   c                 C   s    t jjdd}| |  d S )Nr   rR   )r2   rI   r_   r   get_lockrY  rL   rL   rM   test_when_unlocked  s    zTestGetLock.test_when_unlockedc              	   C   s   t  jjdd}tjjdd}d|_||_tjrPtjdddd	d
dtj	j
d|_ntdddd	d
d|_| }| |t | ||j | || tjrd}nd}| ||jdt| d| d | ||d| d d S Nr  r  r   rR   Ti        rg     r   rh  zJuly 29, 2022, 9:19 p.m.zJuly 29, 2022, 12:19 p.m.z$<b>'Christmas' was locked</b> by <b>z</b> on <b>z</b>.z2<b>'Christmas' was locked</b> by <b>you</b> on <b>)r   rI   r_   r2   r  r  r   rn  rp  r   rq  r  r>  r  r   rt   for_userr  r   ra   get_messager  rc   	moderatorrZ  lockexpected_date_stringrL   rL   rM   test_when_locked  s0    


zTestGetLock.test_when_lockedc                 C   s\   t  jjdd}tjjdd}d|_||_| }| ||j	d | ||d d S )Nr  r  r   rR   Tz<b>'Christmas' is locked</b>.z+<b>'Christmas' is locked</b> by <b>you</b>.)
r   rI   r_   r2   r  r  r>  ra   rE  r  )rc   rG  rZ  rH  rL   rL   rM   "test_when_locked_without_locked_at  s    
z.TestGetLock.test_when_locked_without_locked_atT)ZWAGTAILADMIN_GLOBAL_EDIT_LOCKc              	   C   s   t  jjdd}tjjdd}d|_||_tjrPtjdddd	d
dtj	j
d|_ntdddd	d
d|_| }| |t | ||j | || tjrd}nd}| ||jdt| d| d | ||d| d d S r@  )r   rI   r_   r2   r  r  r   rn  rp  r   rq  r  r>  r  r   rt   rD  r  ra   rE  r  rF  rL   rL   rM   test_when_locked_globally  s0    


z%TestGetLock.test_when_locked_globallyc                 C   s  t  jjdd}tjjdd}|  tjjdd}tjjdd}|j	t
jjdd tjj||d	d
 ||| | }| |t | ||j | || | ||jd | || tjjdd}tjj||dd
 | }| ||jd d S )Nr  r  r   rR   Ztest_workflowr  Z	test_taskzEvent moderatorsr   )workflowtaskZ
sort_orderz[This page is currently awaiting moderation. Only reviewers for this task can edit the page.Zanother_taskr   zThis page is awaiting <b>'test_task'</b> in the <b>'test_workflow'</b> workflow. Only reviewers for this task can edit the page.)r   rI   r_   r2   ra  r   r   r   r  r  r   r    startr>  r  r   rt   rD  r  r   ra   rE  r   )rc   rG  rZ  rM  rN  rH  Z
other_taskrL   rL   rM   test_when_locked_by_workflow;  s0    

z(TestGetLock.test_when_locked_by_workflowc              	   C   s   t jjdd}tjr4tjddddddtjjd	|_ntdddddd|_|	 }|
  | }| |t | ||j tjrd
}nd}| ||jd|  t jjdd}| || d S )Nr   rR   i  rA  rB  r      r   rh  zJuly 30, 2030, 1:32 a.m.zJuly 29, 2030, 4:32 p.m.z@Page 'Christmas' is locked and has been scheduled to go live at zsuperuser@example.comr  )r2   rI   r_   r   rn  rp  r   rq  r  ra  rk  r>  r  r   rt   rD  r  ra   rE  r   )rc   rZ  ZrvnrH  rI  Z	superuserrL   rL   rM   test_when_scheduled_for_publish]  s(    

z+TestGetLock.test_when_scheduled_for_publishN)r   r   r   r   r?  rJ  rK  r   rL  rP  rR  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 )TestPageCacheKeyrP   c                 C   s   t j | _t j | _d S rH   )r   rI   lastr}   r   
other_pager  rL   rL   rM   r     s    zTestPageCacheKey.setUpc                 C   s,   |  | jj| jj |  | jj| jj d S rH   )ra   r}   	cache_keyrU  r  rL   rL   rM   test_cache_key_consistent  s    z*TestPageCacheKey.test_cache_key_consistentc                 C   s>   |  d  | jj | jj W d    n1 s00    Y  d S )Nr   )r   r}   rV  rU  r  rL   rL   rM   test_no_queries  s    z TestPageCacheKey.test_no_queriesc                 C   s.   | j j}d| j _| j   | | j j| d S )Nzsomething-else)r}   rV  rY   r)  r  )rc   Zoriginal_cache_keyrL   rL   rM   test_changes_when_slug_changes  s    
z/TestPageCacheKey.test_changes_when_slug_changesN)r   r   r   r   r   rW  rX  rY  rL   rL   rL   rM   rS  }  s
   rS  c                   @   s   e Zd ZdgZdd ZdS )TestPageCachedParentObjExistsrP   c                 C   s2   t jjdd}d|_|jdd}| |dd d S )NrQ   rR   Z_cached_parent_obj_existsFr  zZPage.get_parent() (treebeard) no longer uses _cached_parent_obj to cache the parent object)r   rI   r_   Z_cached_parent_objr  ra   )rc   rd   r  rL   rL   rM   test_cached_parent_obj_exists  s    z;TestPageCachedParentObjExists.test_cached_parent_obj_existsN)r   r   r   r   r[  rL   rL   rL   rM   rZ    s   rZ  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
$TestPageServeWithPasswordRestrictionc                 C   sJ   t jjdd| _t ddd| _| jj| jd tjj| jtjdd| _	d S )	Nr   r]   z	Test Pager  r{  r[   password123)r}   r  rj  )
r   rI   r_   r   	test_pager`   r   r   ZPASSWORDpassword_restrictionr  rL   rL   rM   r     s    z*TestPageServeWithPasswordRestriction.setUpc                 C   s   t d| jj| jjgd}| j|ddd}| |d | jd}| d|v  | 	d|d  | 	d|d  | 	d	|d  | 	d
|d  | 	d|d  | d|v  d S )NZ&wagtailcore_authenticate_with_password)r   r]  /test/)rj  Z
return_urlCache-Control	max-age=0no-cacheno-storemust-revalidateprivateExpires)
r   r_  r^   r^  r3  postZassertRedirectsr_   rt   r  )rc   Zauth_urlZpost_responser   rL   rL   rM   Ctest_page_with_password_restriction_authenticated_has_cache_headers  s&    zhTestPageServeWithPasswordRestriction.test_page_with_password_restriction_authenticated_has_cache_headersc                 C   s|   | j d}| d|v  | d|d  | d|d  | d|d  | d|d  | d|d  | d|v  d S )	Nr`  ra  rb  rc  rd  re  rf  rg  )r3  r_   rt   r  r<  rL   rL   rM   5test_page_with_password_restriction_has_cache_headers  s    zZTestPageServeWithPasswordRestriction.test_page_with_password_restriction_has_cache_headersc                 C   s6   | j   | jd}| d|v  | d|v  d S )Nr`  ra  rg  )r_  r  r3  r_   r   r<  rL   rL   rM   ;test_page_without_password_restriction_has_no_cache_headers  s    
z`TestPageServeWithPasswordRestriction.test_page_without_password_restriction_has_no_cache_headersN)r   r   r   r   ri  rj  rk  rL   rL   rL   rM   r\    s   r\  )rp  r  Zunittest.mockr   Zdjango.confr   Zdjango.contrib.authr   Zdjango.contrib.auth.modelsr   r   Z"django.contrib.contenttypes.modelsr   Zdjango.core.exceptionsr   Zdjango.httpr	   Zdjango.testr
   r   r   Zdjango.test.clientr   r   r   Zdjango.utilsr   r   Z	freezegunr   Z$wagtail.actions.copy_for_translationr   Zwagtail.coreutilsr   Zwagtail.locksr   r   r   Zwagtail.modelsr   r   r   r   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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   Zwagtail.test.utilsrF   Zwagtail.url_routingrG   rN   rO   r   r   r  r/  rJ  rV  r_  re  r  r  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r&  r*  r1  r=  rS  rZ  r\  rL   rL   rL   rM   <module>   s   8$i  l Zh! Lz       O     c $z / 1D,&F 