U
    |hx                    @   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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-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZU d dlVmWZW d dlXmYZY dd ZZG dd deZ[eddddgdG dd deZ\G d d! d!eZ]ed"d#d$d%d&d'gd%d'gd(G d)d* d*e]Z^G d+d, d,eZ_G d-d. d.eZ`G d/d0 d0eZaG d1d2 d2eZbG d3d4 d4eZcG d5d6 d6eZdG d7d8 d8eZeG d9d: d:eZfG d;d< d<eZgG d=d> d>eZhG d?d@ d@eWeZiG dAdB dBeZjG dCdD dDeZkG dEdF dFeZlG dGdH dHeZmG dIdJ dJeZnG dKdL dLeZoG dMdN dNeZpG dOdP dPeZqG dQdR dReZrG dSdT dTeZsG dUdV dVeZtG dWdX dXeZuG dYdZ dZeZvG d[d\ d\eZwed$d]G d^d_ d_eZxG d`da daeZyG dbdc dceZzG ddde deeZ{dS )f    N)Mock)settings)get_user_model)AnonymousUserGroup)ContentType)ValidationError)Http404)ClientTestCaseoverride_settings)RequestFactory)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 rK   e/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/tests/test_page_model.pyget_ctJ   s    rM   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   rH   getr=   	add_childr]   assertEqualrW   selfhomepage
hello_pageretrieved_pagerK   rK   rL   test_can_createQ   s      zTestValidation.test_can_createc              	   C   sp   t jjdd}tddd}| t |j|d W 5 Q R X tdddd}| t |j|d W 5 Q R X d S )	NrP   rQ   rT   rU   )rX   rY   rZ    rV   r   rH   r^   r=   assertRaisesr   r_   )rb   rc   rd   rK   rK   rL   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 )NrP   rQ   rS   rU   rW   rY   rZ   r\   rT   Eventszevents-2)r   rH   r^   r=   r_   r]   r`   rX   )rb   rc   rd   re   events_pagerK   rK   rL   test_slug_is_autogeneratedj   s    z)TestValidation.test_slug_is_autogeneratedc              	   C   sB   t jjdd}tdddd}| t |j|d W 5 Q R X d S )NrP   rQ   rl   eventsrU   rV   rZ   rh   )rb   rc   rm   rK   rK   rL   &test_slug_must_be_unique_within_parenty   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 )	NrP   rQ   	Christmas	christmasrU   rV   rZ   r\   )	r   rH   r^   r=   r_   
assertTruefilterr]   exists)rb   rc   christmas_pagerK   rK   rL   &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rW   rZ   u   a-mööse-bit-me-öncer   Zget_first_root_noder_   r`   rX   rb   pagerK   rK   rL   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 )Nrx   ry   rZ   za-moose-bit-me-oncerz   r{   rK   rK   rL   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 )NrP   rQ   )r   rH   r^   r`   draft_titleget_admin_display_titlerb   rc   rK   rK   rL   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 )NrP   rQ   z
live titlerg   )rW   r   )r   rH   rt   updater^   r`   r   r   rK   rK   rL   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 )
NrP   rQ   rS   rU   rk   rZ   r\   zHello world edited)rW   r   rY   )r   rH   r^   r=   r_   r]   r`   r   ra   rK   rK   rL   !test_draft_title_is_autopopulated   s      z0TestValidation.test_draft_title_is_autopopulatedN)__name__
__module____qualname__fixturesrf   rj   rn   rp   rw   r   r}   r~   r   r   r   rK   rK   rK   rL   rN   N   s   

rN   	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S )TestSiteRoutingrO   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/rQ   /home/about-us/r   hostname	root_pageZ8765)r   r   portr   )r   r   r   Z8000r   )r   rH   r^   default_siter   createevents_sitealternate_port_events_site
about_siter   r   Zalternate_port_default_siteunrecognised_portunrecognised_hostname)rb   rm   Z
about_pagerK   rK   rL   setUp   s.        zTestSiteRouting.setUpc              	   C   sX   t | jd}| d t||j W 5 Q R X | d t||j W 5 Q R X d S )Nsite   r   )r   r   assertNumQueriesr   route_for_requestpathrb   requestrK   rK   rL   "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   rs   
isinstancerF   r`   r   specificassertIsr   )rb   r   resultrK   rK   rL   test_route_for_request_value   s    z,TestSiteRouting.test_route_for_request_valuec              	   C   sH   t | jd}t }||_| d | t||j| W 5 Q R X d S )Nr   r   )	r   r   r   r   r   r`   r   r   r   )rb   r   mrK   rK   rL   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   rK   rK   rL   %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   r`   r   find_for_requestr   r   r   )rb   Zrequest_200Zrequest_404rK   rK   rL   test_find_for_request   s    z%TestSiteRouting.test_find_for_requestc              	   C   s:   t | jd}| d | t|| j W 5 Q R X d S Nr   r   )r   r   r   r`   r   r   r   rK   rK   rL   )test_valid_headers_route_to_specific_site  s    z9TestSiteRouting.test_valid_headers_route_to_specific_sitec              	   C   s:   t | jd}| d | t|| j W 5 Q R X d S r   )r   r   r   r`   r   r   r   rK   rK   rL   +test_ports_in_request_headers_are_respected	  s     z;TestSiteRouting.test_ports_in_request_headers_are_respectedc              	   C   s@   t  }| j|jd< | d | t|| j W 5 Q R X d S )N	HTTP_HOSTr   )r   r   METAr   r`   r   r   r   r   rK   rK   rL   4test_unrecognised_host_header_routes_to_default_site  s    zDTestSiteRouting.test_unrecognised_host_header_routes_to_default_sitec              	   C   sF   t | jd}| j|jd< | d | t|| j W 5 Q R X d S Nr   SERVER_PORTr   )r   r   r   r   r   r`   r   r   r   rK   rK   rL   >test_unrecognised_port_and_default_host_routes_to_default_site  s    zNTestSiteRouting.test_unrecognised_port_and_default_host_routes_to_default_sitec              	   C   sL   t  }| j|jd< | j|jd< | d | t|| j W 5 Q R X d S Nr   r   r   )	r   r   r   r   r   r`   r   r   r   r   rK   rK   rL   Ctest_unrecognised_port_and_unrecognised_host_routes_to_default_site  s
    zSTestSiteRouting.test_unrecognised_port_and_unrecognised_host_routes_to_default_sitec              	   C   sN   t  }| jj|jd< | j|jd< | d | t|| j W 5 Q R X d S r   )	r   r   r   r   r   r   r`   r   r   r   rK   rK   rL   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   sF   t | jd}| j|jd< | d | t|| j W 5 Q R X d S r   )	r   r   r   r   r   r`   r   r   r   r   rK   rK   rL   Ltest_unrecognised_port_on_known_hostname_routes_to_default_site_if_ambiguity1  s    z\TestSiteRouting.test_unrecognised_port_on_known_hostname_routes_to_default_site_if_ambiguityc              	   C   s\   t  }d| jj| jj|jd< | jj|jd< | d | t	
|| j W 5 Q R X d S )Nz{}:{}r   r   r   )r   formatr   r   r   r   r   r   r`   r   r   r   rK   rK   rL   (test_port_in_http_host_header_is_ignored<  s    
 z8TestSiteRouting.test_port_in_http_host_header_is_ignoredN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rK   rK   rK   rL   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d
dddg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 )*TestRoutingrO   c                 C   s   ddl m} |  d S Nr   )clear_url_cachesdjango.urlsr   rb   r   rK   rK   rL   r   O  s    zTestRouting.setUpc                 C   s   ddl m} |  d S r   r   r   rK   rK   rL   tearDownT  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   rP   rQ   /home/events/christmas/http://localhost/http://localhost//events/christmas/z"http://localhost/events/christmas/r   rH   r^   r   r`   get_url_partsr]   full_urlurlrelative_urlget_siterb   r   rc   rv   rK   rK   rL   	test_urlsY  s,     

 zTestRouting.test_urlsc                 C   sd   t jjdd}tjjdd}| |  | |j | |j | || | |	  d S )Nr   rQ   Tr   )
r   rH   r^   r   r   r   r   r   r   r   )rb   rootr   rK   rK   rL   test_page_with_no_urlr  s    z!TestRouting.test_page_with_no_urlr   
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   rQ   r   r   r   Tr   rP   r   r   r   r   http://events.example.com/christmas/z$http://events.example.com/christmas/r   r    http://second-events.example.comr   rH   r^   r   r   r`   r   r]   r   r   r   r   r   	rb   rm   r   Zsecond_events_siter   rc   rv   r   Zrequest2rK   rK   rL   test_urls_with_multiple_sites|  s\    	   

 





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   rP   rQ   r   r   z/site/zhttp://localhost/site//site/events/christmas/z'http://localhost/site/events/christmas/r   r   rK   rK   rL   test_urls_with_non_root_urlconf  s2     

  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   rP   rQ   )
r   rH   r^   r   r`   r   r]   r   r   r   )rb   r   rc   rK   rK   rL   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 )NrP   rQ   r   r   r   ro   rr   )r   rH   r^   r1   r   router`   )rb   rc   rv   r   
found_pageargskwargsrK   rK   rL   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   rQ   r      rb   <h2>Event</h2>)r1   rH   r^   r   r   firstr   userZserver`   status_codecontext_dataassertContains)rb   rv   r   responserK   rK   rL   test_request_serving  s    
z TestRouting.test_request_servingc              	   C   sB   t jjdd}tdd}| t ||ddg W 5 Q R X d S )NrP   rQ   /events/quinquagesima/r   ro   Zquinquagesimar   rH   r^   r   ri   r	   r   rb   rc   r   rK   rK   rL   &test_route_to_unknown_page_returns_404  s    
z2TestRouting.test_route_to_unknown_page_returns_404c              	   C   sB   t jjdd}tdd}| t ||ddg W 5 Q R X d S )NrP   rQ   $/events/tentative-unpublished-event/r   ro   ztentative-unpublished-eventr   r   rK   rK   rL   *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 5 Q R X | d | | d W 5 Q R X | d | | d W 5 Q R X t }| d | |j|d	d W 5 Q R X | d | |j|d	d W 5 Q R X | d | |j|d	d W 5 Q R X d S )
NrP   rQ   r   r   r   r   r   r   r   r   rH   r^   r1   r   r`   get_urlr   rb   rc   rv   r   rK   rK   rL   (test_request_scope_site_root_paths_cache  s$    
 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 5 Q R X d S )NrP   rQ   r   r   r   ro   rr   r   r   Fr   )
r   rH   r^   r1   r   r   r`   r   r   
get_parent)	rb   rc   rv   r   r   r   r   rm   parentrK   rK   rL   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  rK   rK   rK   rL   r   J  s6   

7


	

r   zwagtail.test.urls_multilangenTr  ZEnglishen-uszEnglish (United States)frZFrench)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dd	d
gddd Zdd Zdd Z	eddddg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   rP   rQ   r   r   r   r   r   )r   rH   r^   r   r`   r   r   r   r   r   r]   )rb   expected_language_coder   rc   rv   rK   rK   rL   r   D  sB     
 


 

zTestRoutingWithI18N.test_urlsc              	   C   s"   t d |   W 5 Q R X d S Nr  r   overrider   rb   rK   rK   rL   $test_urls_with_translation_activatedl  s    z8TestRoutingWithI18N.test_urls_with_translation_activatedc              	   C   s&   t d | jdd W 5 Q R X d S )Nr  )r  r  r  rK   rK   rL   4test_urls_with_region_specific_translation_activatedr  s    zHTestRoutingWithI18N.test_urls_with_region_specific_translation_activatedr  r  r  )r  c              	   C   s"   t d |   W 5 Q R X d S )Nr  r  r  rK   rK   rL   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   s"   t d |   W 5 Q R X d S )Nser  r  rK   rK   rL   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   rP   rQ   r   r  language_codeZcopy_parentsZnoelrX   Zupdate_fieldsr   z/fr/zhttp://localhost/fr/z/fr/events/noel/z http://localhost/fr/events/noel/)r   rH   r^   r   r   r   copy_for_translationrX   saver`   r   r]   r   r   r   r   )rb   r   rc   rv   	fr_localefr_homepageZfr_christmas_pagerK   rK   rL   &test_urls_with_different_language_tree  s<    
  

 z:TestRoutingWithI18N.test_urls_with_different_language_treer   r   r   r   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   rQ   r   r   r   Tr   rP   r   r   /en/zhttp://localhost/en/r   z/en/christmas/z'http://events.example.com/en/christmas/r   r   r   r   r   rK   rK   rL   r     sb    	   

 




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 5 Q R X | d | | d W 5 Q R X | d | | d W 5 Q R X t }| d | |j|d	d W 5 Q R X | d | |j|d	d W 5 Q R X | d | |j|d	d W 5 Q R X d S )
NrP   rQ   r   r   r+  r   z/en/events/christmas/   r   r  r	  rK   rK   rL   r
    s$    
 z<TestRoutingWithI18N.test_request_scope_site_root_paths_cacheN)r  )r   r   r   r   r  r  r   r  r!  r*  r   r
  rK   rK   rK   rL   r  5  s2   
(

!
>

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 )TestServeViewrO   c                 C   s   t   ddlm} |  d S r   )r   Zclear_site_root_paths_cacher   r   r   rK   rK   rL   r     s    zTestServeView.setUpc                 C   s   ddl m} |  d S r   r   r   rK   rK   rL   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   rQ   rb   <h1>Christmas</h1>r   
clientr^   r`   r   	templatesnamer1   rH   contextr   rb   r   rv   rK   rK   rL   
test_serve-  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   r.  r   rQ   rb   r/  r   r0  r5  rK   rK   rL   test_serve_with_non_root_urls8  s    z+TestServeView.test_serve_with_non_root_urlsc                 C   s   | j d}| |jd d S )Nr     r1  r^   r`   r   rb   r   rK   rK   rL   #test_serve_unknown_page_returns_404D  s    z1TestServeView.test_serve_unknown_page_returns_404c                 C   s   | j d}| |jd d S )Nr   r8  r9  r:  rK   rK   rL   'test_serve_unpublished_page_returns_404H  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   rQ   r   r   r   )r   r   r   r.  r   rb   r/  r   r   r8  )r   rH   r^   r   r   r1  r`   r   r2  r3  r1   r4  r   r
   )rb   rm   r   rv   crK   rK   rL   test_serve_with_multiple_sitesL  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   rQ   r   r|   rb   )r1   Zcontext_object_namerH   r^   r1  r`   r4  )rb   rv   r   rK   rK   rL   #test_serve_with_custom_context_name_  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>)r1  r^   r`   r   r   r:  rK   rK   rL   test_serve_with_custom_contextj  s    z,TestServeView.test_serve_with_custom_contextc                 C   s:   | j jddd}| |jd | |d | |d d S )NrA  ZXMLHttpRequest)ZHTTP_X_REQUESTED_WITHr   rB  rC  )r1  r^   r`   r   ZassertNotContainsr   r:  rK   rK   rL   test_ajax_responset  s    z TestServeView.test_ajax_responsec                 C   s    | j jddd}| |d d S )NrA  Z	GoogleBot)HTTP_USER_AGENTzbad googlebot no cookie)r1  r^   r   r:  rK   rK   rL   test_before_serve_hook|  s    z$TestServeView.test_before_serve_hookN)r   r   r   r   r   r   r6  r   r7  r;  r<  r>  r@  rD  rE  rG  rK   rK   rK   rL   r-    s   


r-  c                   @   s   e Zd ZdgZdd ZdS )TestMovePagerO   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   rQ   r   
last-childposr\   z/home/about-us/events/   rr   rX      z /home/about-us/events/christmas/)r=   rH   r^   r0   mover]   r`   rR   depthr  get_children)rb   Zabout_us_pageevents_indexrr   rK   rK   rL   test_move_page  s    zTestMovePage.test_move_pageN)r   r   r   r   rS  rK   rK   rK   rL   rH    s   rH  c                   @   s*   e Zd ZdgZdd Zdd Zdd ZdS )	TestPrevNextSiblingsrO   c                 C   s,   t jjdd}| | jdd  d S )Nr   rQ   /home/events/final-event/)r   rH   r^   rs   get_next_siblingsrt   ru   rb   christmas_eventrK   rK   rL   test_get_next_siblings  s    z+TestPrevNextSiblings.test_get_next_siblingsc                 C   s*   t jjdd}| |jdd | d S )Nr   rQ   TZ	inclusive)r   rH   r^   r`   rV  r   rW  rK   rK   rL    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 )NrU  rQ   r   TrZ  )	r   rH   r^   rs   Zget_prev_siblingsrt   ru   r`   r   )rb   Zfinal_eventrK   rK   rL   test_get_prev_siblings  s     z+TestPrevNextSiblings.test_get_prev_siblingsN)r   r   r   r   rY  r[  r\  rK   rK   rK   rL   rT    s   rT  c                   @   s   e Zd ZdgZdd ZdS )TestSaveRevisionrO   c              	   C   sD   t jjdd}| t}|  W 5 Q R X | |jjd d d S )Nr   rQ   r   ztpage.save_revision() must be called on the specific version of the page. Call page.specific.save_revision() instead.)	r   rH   r^   ri   RuntimeErrorsave_revisionr`   	exceptionr   )rb   rX  erK   rK   rL   +test_raises_error_if_non_specific_page_used  s    
z<TestSaveRevision.test_raises_error_if_non_specific_page_usedN)r   r   r   r   rb  rK   rK   rK   rL   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 )TestLiveRevisionrO   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   rH   r^   r_  publishrefresh_from_dbr`   live_revisionr   USE_TZlast_published_atdatetimer   utcfirst_published_at
make_naiverb   r|   revisionrK   rK   rL   *test_publish_method_will_set_live_revision  s@          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\   rh  r   re  r   rf  rd  )r   rH   r^   r_  ri  rj  	unpublishr   rk  r   rl  r`   rp  rn  r   ro  rm  rq  rr  rK   rK   rL   .test_unpublish_method_will_clean_live_revision  sD          	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   rQ   TNew about usnew-about-usrW   rX   Z	keep_liveupdate_attrsrd  r   re  r   rf  )r=   rH   r^   r_  ri  copyassertIsNotNonerk  assertNotEqualr   rl  r`   rp  rn  r   ro  rm  rj  rW   r   rb   about_usrs  new_about_usrK   rK   rL   9test_copy_method_with_keep_live_will_update_live_revision  s:      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   rQ   Frw  rx  ry  rz  )r=   rH   r^   r_  ri  rj  r}  rk  r|  r   rp  rm  r`   rW   r   r  rK   rK   rL   @test_copy_method_without_keep_live_will_not_update_live_revision9  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   rQ   zWe are even better than beforeFrw  rx  ry  rz  )r=   rH   r^   rY   r_  rj  r`   get_latest_revision_as_objectr|  rW   r   )rb   r  r  Znew_about_us_draftrK   rK   rL   'test_copy_method_copies_latest_revisionM  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   rQ   i  r   re  r   rf  rh  r   )r=   rH   r^   r   rl  rn  r   ro  
go_live_atr_  ri  rj  r   liver   rk  r`   rp  rm  rq  )rb   r  rs  rK   rK   rL   ;test_publish_with_future_go_live_does_not_set_live_revisiond  sl          
            zLTestLiveRevision.test_publish_with_future_go_live_does_not_set_live_revisionN)r   r   r   r   r   rt  rv  r  r  r  r  rK   rK   rK   rL   rc    s   
#
&
$rc  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 )TestPageGetSpecificrO   c                    s:   t    tjjdd| _d| j_ddi| j_d| j_d S )Nr   rQ   ABCkeyvalue  )	superr   r   rH   r^   r|   foobarbazr  	__class__rK   rL   r     s
    
zTestPageGetSpecific.setUpc              
   C   s   |  d | j }W 5 Q R X | |t |  d* | |j| jj | |j| jj W 5 Q R X |  d | |j	 W 5 Q R X dD ]6}| j
|d  | t||t| j| W 5 Q R X qd S )Nr   r   r  r  r  	attributer   r|   get_specificassertIsInstancer=   r`   r]   rW   rs   rY   subTestr   getattrrb   r   attrrK   rK   rL   test_default  s    z TestPageGetSpecific.test_defaultc              
   C   s   |  d | jjdd}W 5 Q R X | |t |  d* | |j| jj | |j| jj W 5 Q R X |  d | |j	 W 5 Q R X dD ]6}| j
|d  | t||t| j| W 5 Q R X qd S )Nr   T)deferredr   r  r  r  r  rK   rK   rL   test_deferred  s    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   rb   r   rK   rK   rL   test_copy_attrs  s    z#TestPageGetSpecific.test_copy_attrsc              
   C   sD   | j jdd}dD ],}| j|d | t|| W 5 Q R X qd S )NrK   r  r  r  )r|   r  r  r   r   r  rK   rK   rL   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  rK   rK   rL   test_copy_attrs_exclude  s    z+TestPageGetSpecific.test_copy_attrs_excludec              
   C   sN   | j jdd}dD ]6}| j|d  | t||t| j | W 5 Q R X qd S )NrK   r  r  r  )r|   r  r  r   r  r  rK   rK   rL   'test_copy_attrs_exclude_with_empty_list  s    z;TestPageGetSpecific.test_copy_attrs_exclude_with_empty_listc              	   C   sx   |  d6 | jj}| jj}| jj}| || | || W 5 Q R X | |t |  d | |j W 5 Q R X d S )Nr   r   )r   r|   r   r   r  r=   rs   rY   rb   r   Zresult_2Zresult_3rK   rK   rL   test_specific_cached_property  s    z1TestPageGetSpecific.test_specific_cached_propertyc              	   C   sx   |  d6 | jj}| jj}| jj}| || | || W 5 Q R X | |t |  d | |j W 5 Q R X d S )Nr   r   )r   r|   Zspecific_deferredr   r  r=   rs   rY   r  rK   rK   rL   &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__rK   rK   r  rL   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TestCopyPagerO   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   rQ   rw  rx  ry  r{  /home/new-about-us/)r=   rH   r^   r|  r  r`   rW   rX   r~  r]   rR   rb   r  r  rK   rK   rL   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   rQ   New christmas eventnew-christmas-eventry  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)r1   rH   r^   r|  r`   speakerscountadvert_placementsrb   rX  new_christmas_eventrK   rK   rL   #test_copy_page_copies_child_objects!  s0      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   rQ   Summerr3  Holidaysr  r  ry  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)r1   rH   r^   r/   r   
categoriesr'  r|  r`   r  allin_bulkrb   rX  Zsummer_categoryZholiday_categoryr  rK   rK   rL   (test_copy_page_copies_parental_relationsB  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   rQ   test)textr   r  r  ry  r  r   z,Comments were removed from the original pagezComments were copiedmsg)r1   rH   r^   r   ownerZwagtail_admin_commentsr'  r|  r`   r  r   ru   r  rK   rK   rL   %test_copy_page_does_not_copy_commentse  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   rQ   r  r  ry  r  )r{  Zexclude_fieldsr   r  r  zSChild objects were copied despite accessor_name being specified in `exclude_fields`r  r  )
r1   rH   r^   r|  r`   r  r  r   r  ru   r  rK   rK   rL   Mtest_copy_page_does_not_copy_child_objects_if_accessor_name_in_exclude_fields  s4    	  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   rQ   zChild christmas eventzchild-christmas-eventry  r  rI  rJ  r  r  T)r{  Zprocess_child_object	recursiver  speaker)r   r1   rH   r^   r|  rO  _meta	get_fieldr  Zassert_any_callr  rQ  r   )rb   Zmodify_childZ	old_eventZchild_eventZ	new_eventZrelationshipZchild_objectZnew_child_eventrK   rK   rL   1test_copy_page_with_process_child_object_supplied  s:    


   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   rQ   r  r  ry  r  r   r   -Revisions were removed from the original pagepkr  r   r|   r]   TZflatc                 S   s   h | ]}|d  qS )r  rK   ).0r  rK   rK   rL   	<setcomp>  s    z?TestCopyPage.test_copy_page_copies_revisions.<locals>.<setcomp>z;Child objects in revisions were not given a new primary keyr  )r1   rH   r^   r_  r|  r`   	revisionsr  r  rW   rX   get_latest_revisionZ	as_objectr   rY   r]   setr  values_listr   intersection)rb   rX  r  latest_revisionZnew_revisionZnew_revision_contentZold_speakers_idsZnew_speakers_idsrK   rK   rL   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   rQ   rh  r   r   rf  r  r  ry  r  
created_at)r1   rH   r^   r_  r  rn  r   ro  r  r'  r|  r  order_byr   r`   )rb   rX  rs  r  Zchristmas_event_created_atZnew_christmas_event_created_atrK   rK   rL   <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   rQ   rh  	      re  r   rf  )approved_go_live_atr  r  ry  r  r  )r1   rH   r^   r   rl  r_  rn  r   ro  r|  r`   r  r  r   r  r   r  rK   rK   rL   3test_copy_page_copies_revisions_and_doesnt_schedule  s>          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   rQ   r  r  ry  F)r{  copy_revisionsr   r  )r1   rH   r^   r_  r|  r`   r  r  r  rK   rK   rL   9test_copy_page_doesnt_copy_revisions_if_told_not_to_do_soE  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   rQ   r  r  ry  r  r   r  )	r   rH   r^   r|  r  r1   r`   r  r  r  rK   rK   rL   :test_copy_page_copies_child_objects_with_nonspecific_class]  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   rQ   TNew events indexnew-events-indexry  r  r{  rr   rM  Child pages weren't copied+Child pages were removed from original page!/home/new-events-index/christmas/)
r0   rH   r^   r|  rQ  rt   r   r}  r`   rR   rb   rR  new_events_indexold_christmas_eventr  rK   rK   rL   !test_copy_page_copies_recursivelyn  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   rQ   Tr  r  ry  r  rr   rM  r   r  r  )r0   rH   r^   r|  rQ  rt   r   r`   r   r  r  r  rK   rK   rL   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   rQ   rr   rM  Tr  r  ry  r  r   r   r  r0   rH   r^   rQ  rt   r   r   r_  r|  r`   r  r  rb   rR  r  r  r  rK   rK   rL   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   rQ   rr   rM  Tr  r  ry  F)r  r{  r  r   r  r  r  rK   rK   rL   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   sn   t jjdd}| jdd j}|  | t	}|j
dddd|d	 W 5 Q R X | t|jd
 d S )Nr   rQ   rr   rM  Tr  r  ry  )r  r{  to5You cannot copy a tree branch recursively into itself)r0   rH   r^   rQ  rt   r   r   r_  ri   	Exceptionr|  r`   strr`  rb   rR  r  r`  rK   rK   rL   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   rQ   r  r  ry  )r{  r   )
r   rH   r^   r1   r_  r|  r`   r  r  r   rb   Zevent_moderatorrX  r  rK   rK   rL   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/rQ   rX   new-saint-patrickr  /home/events/new-saint-patrick/r\   )r?   rH   r^   r|  r  r`   excerptr~  r]   eventpage_ptrpage_ptrrR   r1   r   rb   Zsaint_patrick_eventZnew_saint_patrick_eventrK   rK   rL   !test_copy_multi_table_inheritance  s4      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   rQ   My tagged pagemy-tagged-pagery  wagtailbirdrZ   c                 S   s   g | ]
}|j qS rK   r\   r  itemrK   rK   rL   
<listcomp><  s     z;TestCopyPage.test_copy_page_copies_tags.<locals>.<listcomp>r   rP   r  c                 S   s   g | ]
}|j qS rK   r\   r  rK   rK   rL   r  H  s     c                 3   s   | ]}| kV  qd S rG   rK   r  Zitem_idZold_tagged_item_idsrK   rL   	<genexpr>N  s     z:TestCopyPage.test_copy_page_copies_tags.<locals>.<genexpr>)r   rH   r^   rD   tagsaddr_   r_  ri  tagged_itemsr  r`   lenrs   r|  r~  r]   rb   event_indexZtagged_pagerc   Znew_tagged_pagenew_tagged_item_idsrK   r  rL   test_copy_page_copies_tags4  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   rQ   zMy very special tagged pagezmy-special-tagged-pagery  r  r  rZ   c                 S   s   g | ]
}|j qS rK   r\   r  rK   rK   rL   r  [  s     zFTestCopyPage.test_copy_subclassed_page_copies_tags.<locals>.<listcomp>r   rP   r  c                 S   s   g | ]
}|j qS rK   r\   r  rK   rK   rL   r  g  s    c                 3   s   | ]}| kV  qd S rG   rK   r  r  rK   rL   r  o  s     zETestCopyPage.test_copy_subclassed_page_copies_tags.<locals>.<genexpr>)r   rH   r^   rC   r  r  r_   r_  ri  r  r  r`   r  rs   r|  r~  r]   )rb   r  Zsub_tagged_pagerc   Znew_sub_tagged_pager  rK   r  rL   %test_copy_subclassed_page_copies_tagsQ  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   rQ   Birdsr  http://www.heinz.com/beanz meanz heinzr   r  My blog pagemy-blog-pagery  rZ   categoryr|   rP   r  )r   rH   r^   r&   r   r$   r4   r_   advertsr  r'   r_  ri  r|  r~  r]   rb   r  r(  advertZ	blog_pagerc   Znew_blog_pagerK   rK   rL   !test_copy_page_with_m2m_relationsr  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   rQ   r"  r#  r$  My snippet pagemy-snippet-pagery  rZ   rP   r  )r   rH   r^   r$   r   r3   snippet_content_objectr_   r_  ri  r|  r~  r]   r`   rb   r  r+  r|   rc   new_pagerK   rK   rL   '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   rQ   My pagemy-pagery  rZ   rP   r  )r   rH   r^   r8   r_   r|  r~  r]   rb   r  r|   rc   r1  rK   rK   rL    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 )NrP   rQ   	DiscoverydiscoNCC-1031Context is for KingsrW   rX   rY   special_fieldrZ   rX   disco-2r  r{  r<  )r   rH   r^   r_   r9   r_  r|  r  rY   r`   rW   r~  r]   r   r<  )rb   rc   r|   r1  Zexclude_fieldrK   rK   rL   .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.
        rP   rQ   r:   zpage-with-generic-relationTF)rW   rX   r  has_unpublished_changesrZ   )Zcontent_objectrX   z-2r>  N)r   rH   r^   r_   r:   r;   r   r}  Zgeneric_relationr   r|  rX   r   )rb   rc   original_pageZ	page_copyrK   rK   rL   test_page_with_generic_relation  s      z,TestCopyPage.test_page_with_generic_relationc                 C   s   zdddg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 5 g t _X dS )VTest that a page will be copied with parental and child relations removed if excluded.r  r  signup_linkr   rQ   r  r  r  %https://christmas-is-awesome.com/rsvpr  r  ry  r  rg   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)r1   exclude_fields_in_copyrH   r^   r/   r   rD  r  r'  r|  r`   r  r  r  rK   rK   rL   9test_copy_page_with_excluded_parental_and_child_relations  sT    
 zFTestCopyPage.test_copy_page_with_excluded_parental_and_child_relationsc              	   C   s.   t ddd}| t |  W 5 Q R X dS )z*Test that unsaved page will not be copied.ZtestpurpZtestpurpose)rX   rW   N)r=   ri   r^  r|  )rb   r1  rK   rK   rL   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   rQ   ZSantaZClausZ
first_name	last_namezOrderable Pageztranslated-orderable-pagery  r  N)r1   rH   r^   r  r  r2   r'  r_  ri  r|  r~  r   translation_key)rb   rv   r1  rK   rK   rL   .test_copy_page_with_unique_uuids_in_orderables  s&    

z;TestCopyPage.test_copy_page_with_unique_uuids_in_orderablesc              	      sl   t jjdd}d d fdd}t| z,|jddd	d
}|   | | W 5 t| X dS )zDTest that copying of a published page emits a page_published signal.r   rQ   FNc                    s   d |d S NTrK   Zsenderr[   r   signal_firedZsignal_pagerK   rL   page_published_handler@  s    zMTestCopyPage.test_copy_published_emits_signal.<locals>.page_published_handlerzNew christmasznew-christmasry  r  )	r1   rH   r^   r"   connect
disconnectr|  rs   r`   )rb   rv   rT  Z	copy_pagerK   rR  rL    test_copy_published_emits_signal9  s    

z-TestCopyPage.test_copy_published_emits_signalc              	      sf   t jjdd}d|_|  d  fdd}t| z|jddid | 	  W 5 t| X d	S )
zKTest that copying of an unpublished page not emits a page_published signal.rP   rQ   Fc                    s   d d S rP  rK   rQ  rS  rK   rL   rT  Y  s    zSTestCopyPage.test_copy_unpublished_not_emits_signal.<locals>.page_published_handlerrX   new_slugr  N)
r   rH   r^   r  r'  r"   rU  rV  r|  r   rb   rc   rT  rK   rX  rL   &test_copy_unpublished_not_emits_signalQ  s    
z3TestCopyPage.test_copy_unpublished_not_emits_signalc              	      sZ   t jjdd}d  fdd}z*t| |jdddid |   W 5 t| X d	S )
zXTest that copying of a live page with keep_live=False not emits a page_published signal.rP   rQ   Fc                    s   d d S rP  rK   rQ  rX  rK   rL   rT  j  s    zWTestCopyPage.test_copy_keep_live_false_not_emits_signal.<locals>.page_published_handlerrX   rY  rz  N)r   rH   r^   r"   rV  rU  r|  r   rZ  rK   rX  rL   *test_copy_keep_live_false_not_emits_signale  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   rQ   zabout-us-aliasupdate_slugrX   zabout-us-alias-copyr  z/home/about-us-alias-copy/)r=   rH   r^   create_aliasr|  r  r`   rX   r~  r]   rR   r   alias_of)rb   r  Zabout_us_aliasZabout_us_alias_copyrK   rK   rL   test_copy_alias_pagev  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 pagerP   rQ   Child Page 1child-page-1hello child page 1rV   rZ   rU   r|   passwordChild Page 2child-page-2ry  r  r|   N)r   rH   r^   r=   r_   r   r   r|  rs   rt   ru   )rb   rc   child_page_1child_page_2rK   rK   rL   !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 pagerP   rQ   Parent 1parent-1hello parent 1rV   rZ   rU   rf  Parent 2parent-2hello parent 2rc  rd  re  rh  ri  ry  r>  rj  Nr   rH   r^   r=   r_   r   r   r|  r   rt   ru   rb   rc   Zorigin_parentZdestination_parentrk  rl  rK   rK   rL   5test_copy_page_does_not_copy_restrictions_from_parent  s2          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 )rn  rP   rQ   ro  rp  rq  rV   rZ   rr  rs  rt  rU   rf  rc  rd  re  rh  ri  ry  r>  rj  Nru  rv  rK   rK   rL   Itest_copy_page_does_not_copy_restrictions_when_new_parent_has_one_already  s4          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,  r2  r6  r?  rB  rJ  rK  rO  rW  r[  r\  ra  rm  rw  rx  rK   rK   rK   rL   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 ))TestCreateAliasrO   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   rQ   zDraft titler   r%  rx  r]  zAbout usr  )r=   rH   r^   r   r'  r_  r  r`   rX   r~  r]   rR   r`  r  rK   rK   rL   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   rQ   r  r]  r   r  r  r  r  )r1   rH   r^   r_  r`   r  r  r  r  rK   rK   rL   &test_create_alias_copies_child_objects  s0      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   rQ   r  r  r  r  r]  r   r  r  N)r1   rH   r^   r/   r   r  r'  r_  r`   r  r  r  r  rK   rK   rL   +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   rQ   r  r]  r   )r1   rH   r^   r_  r_  r`   r  r  r  rK   rK   rL   'test_create_alias_doesnt_copy_revisions5	  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   rQ   r  r]  r   r  )	r   rH   r^   r_  r  r1   r`   r  r  r  rK   rK   rL   =test_create_alias_copies_child_objects_with_nonspecific_classA	  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   rQ   Tr  r  r^  rr   rM  r  r  r  )r0   rH   r^   r_  rQ  rt   r   r}  r`   rR   r`  r  rK   rK   rL   $test_create_alias_copies_recursivelyR	  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   rQ   Tr  r  rr   rM  r   r  r  )r0   rH   r^   r_  rQ  rt   r   r`   r   r  r  r  rK   rK   rL   7test_create_alias_copies_recursively_with_child_objectsp	  s&     

zGTestCreateAlias.test_create_alias_copies_recursively_with_child_objectsc              	   C   sf   t jjdd}| jdd j}|  | t	}|j
d|d W 5 Q R X | t|jd d S )Nr   rQ   rr   rM  T)r  r  r  )r0   rH   r^   rQ  rt   r   r   r_  ri   r  r_  r`   r  r`  r  rK   rK   rL   :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   rQ   r  )r^  r   )r   rH   r^   r1   r_  r_  r`   r  r  rK   rK   rL   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  rQ   r  r]  r  r\   )r?   rH   r^   r_  r  r`   r  r~  r]   r	  r
  rR   r1   r   r  rK   rK   rL   )test_create_alias_multi_table_inheritance	  s4      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   rQ   r  r  ry  r  r  rZ   c                 S   s   g | ]
}|j qS rK   r\   r  rK   rK   rL   r  	  s     zATestCreateAlias.test_create_alias_copies_tags.<locals>.<listcomp>r   rP   r  c                 S   s   g | ]
}|j qS rK   r\   r  rK   rK   rL   r  	  s     c                 3   s   | ]}| kV  qd S rG   rK   r  r  rK   rL   r  	  s     z@TestCreateAlias.test_create_alias_copies_tags.<locals>.<genexpr>)r   rH   r^   rD   r  r  r_   r_  ri  r  r  r`   r  rs   r_  r~  r]   r  rK   r  rL   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   rQ   r!  r  r"  r#  r$  r%  r&  ry  rZ   r'  rP   r  )r   rH   r^   r&   r   r$   r4   r_   r)  r  r'   r_  ri  r_  r~  r]   r*  rK   rK   rL   $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   rQ   r"  r#  r$  r-  r.  ry  rZ   rP   r  )r   rH   r^   r$   r   r3   r/  r_   r_  ri  r_  r~  r]   r`   r0  rK   rK   rL   *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   rQ   r3  r4  ry  rZ   rP   r  )r   rH   r^   r8   r_   r_  r~  r]   r5  rK   rK   rL   #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 )NrP   rQ   r7  r8  r9  r:  r;  rZ   r=  r  r^  )r   rH   r^   r_   r9   r_  r`   rW   r~  r]   r   r<  )rb   rc   r|   r1  rK   rK   rL   1test_create_alias_with_additional_excluded_fields$
  s    zATestCreateAlias.test_create_alias_with_additional_excluded_fieldsc                 C   s   zdddg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 5 g t _X dS )rC  r  r  rD  r   rQ   r  r  r  rE  r  r]  rg   r   r  r   rF  r   rG  rH  N)r1   rI  rH   r^   r/   r   rD  r  r'  r_  r`   r  r  r  rK   rK   rL   <test_create_alias_with_excluded_parental_and_child_relations7
  sP    
 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 )rb  rP   rQ   rc  rd  re  rV   rZ   z
Test Groupr  )r|   Zrestriction_typeri  r]  rj  r]   Tr  N)r   rH   r^   r=   r_   r   r   r   ZGROUPSgroupsr  r_  r`   listr  r  )rb   rc   rk  groupZrestrictionrl  Zcopied_restrictionrK   rK   rL   "test_alias_page_copies_restrictionz
  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 )rn  rP   rQ   ro  rp  rq  rV   rZ   rU   rf  rr  rs  rt  rc  rd  re  ri  r  rj  Nr   rH   r^   r=   r_   r   r   r_  r   rt   ru   rv  rK   rK   rL   6test_alias_page_does_not_copy_restrictions_from_parent
  s2          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 )rn  rP   rQ   ro  rp  rq  rV   rZ   rr  rs  rt  rU   rf  rc  rd  re  ri  r  rj  Nr  rv  rK   rK   rL   Jtest_alias_page_does_not_copy_restrictions_when_new_parent_has_one_already
  s4          zZTestCreateAlias.test_alias_page_does_not_copy_restrictions_when_new_parent_has_one_alreadyN)r   r   r   r   rz  r{  r|  r}  r~  r  r  r  r  r  r  r  r  r  unittestZexpectedFailurer  r  r  r  r  rK   rK   rK   rL   ry    s,   !#$

Bry  c                   @   s"   e Zd ZdgZdd Zdd ZdS )TestUpdateAliasesrO   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   rQ   new-event-pager]  new-event-page-2zUpdated titlezA different draft titleZTedZCrillyrL  rq   r   r   wagtail.publishr|   action)r1   rH   r^   r_  rW   r   r  r  r2   r'  rj  r`   r  r   r  deleteupdate_aliasesr   rt   ru   rb   r?  aliasZalias_aliasrK   rK   rL   test_update_aliases
  sJ     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   rQ   FTcleanr  r]  r  r  r  )r1   rH   r^   r  r@  r'  r_  r   rj  r   r  r  r  rs   rt   ru   r  rK   rK   rL   $test_update_aliases_publishes_drafts  s<     z6TestUpdateAliases.test_update_aliases_publishes_draftsN)r   r   r   r   r  r  rK   rK   rK   rL   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 )TestCopyForTranslationrO   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 )NrP   rQ   r   r   r  r"  )r   rH   r^   r   en_homepager0   en_eventindexr1   en_eventpager  r   r   r   r(  r  rK   rK   rL   r   5  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]   r`   r  rN  rX   r   r  rs   r@  r   rH   r^   datamessage)rb   r)  	log_entryrK   rK   rL   test_copy_homepage<  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 contentrV   rZ   z	home-fr-1)r   r_   r=   r  r&  r(  r`   rX   )rb   r)  rK   rK   rL   test_copy_homepage_slug_existsR  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  rW   rX   r  rN  rZ   r  r  r  r#  r  r|   r  r  zGCopied for translation from Welcome to the Wagtail test site! (English))r   r_   r   r(  r  rN  r  r&  r~  r]   r`   r  r  rX   r   rH   r^   r  r  )rb   r)  fr_eventindexr  rK   rK   rL   test_copy_childpage^  s0    	 z*TestCopyForTranslation.test_copy_childpagec              	   C   s(   |  t | j| j W 5 Q R X d S rG   )ri   r   r  r&  r(  r  rK   rK   rL   "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]   r`   r  rN  rX   r  r  )rb   r  r)  rK   rK   rL   %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  rZ   rl   ro   )r   r_   r   r(  r  rN  r0   r  r  r  r^   r&  r`   r  r  Zget_translations)rb   r)  Z
en_speakerfr_eventpageZ
fr_speakerrK   rK   rL   .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  r`   r  rN  r  r`  )rb   r  r  rK   rK   rL   &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  rK   rK   rK   rL   r  2  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 rG   )assertInr=   Zallowed_subpage_modelsr)   assertNotInr+   r(   r  rK   rK   rL   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 rG   )	r  r=   Zallowed_parent_page_modelsr  r(   r*   rA   r+   r)   r  rK   rK   rL   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 rG   )	rs   r=   Zcan_exist_underrA   r   r   r+   r)   r(   r  rK   rK   rL   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 rG   )	r   r   can_create_atrs   r=   rA   r+   r)   r(   r  rK   rK   rL   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 )
NrP   rQ   zsimple parentzsimple-parentry  rZ   zsimple-parent-2zsimple childzsimple-child)	r   rH   r^   r_   r>   rs   r<   r  r   )rb   r   Zparent1Zparent2rK   rK   rL   ;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 rG   )	rs   r=   Zcan_move_torA   r   r   r+   r)   r(   r  rK   rK   rL   test_can_move_to3  s    z-TestSubpageTypeBusinessRules.test_can_move_toc                 C   sF   t jjdd}| t| |jtdddd | t| d S )NrP   rQ   Z	singletonry  rZ   )r   rH   r^   rs   r@   r  r_   r   rb   r   rK   rK   rL   test_singleton_page_creationB  s    z9TestSubpageTypeBusinessRules.test_singleton_page_creationN)
r   r   r   r  r  r  r  r  r  r  rK   rK   rK   rL   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
    rO   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   rQ   r   z
old-eventsr\   z/home/old-events/christmas/)r   rH   r^   r   r1   rX   r_  ri  r]   r`   rR   )rb   r  rX  r  rK   rK   rL   )test_child_urls_updated_on_parent_publishW  s    z6TestIssue735.test_child_urls_updated_on_parent_publishN)r   r   r   __doc__r   r  rK   rK   rK   rL   r  O  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   rH   r^   r_  r}  latest_revision_created_atri  )rb   rs  rK   rK   rL   >test_publish_revision_doesnt_remove_latest_revision_created_atj  s    zKTestIssue756.test_publish_revision_doesnt_remove_latest_revision_created_atN)r   r   r   r  r  rK   rK   rK   rL   r  d  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
    rO   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   rQ   r   zchristmas-%s-christmasZ01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789zevents-%s-eventsr\   z/home/{}/{}/)r   rH   r^   r   r1   rX   r_  ri  r]   r   r`   rR   )rb   r  rX  Znew_christmas_slugZnew_event_index_slugr  Zexpected_url_pathrK   rK   rL   'test_url_path_can_exceed_255_characters  s      z5TestIssue1216.test_url_path_can_exceed_255_charactersN)r   r   r   r  r   r  rK   rK   rK   rL   r  x  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)rs   r=   is_creatabler  r    r  rK   rK   rL   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   r5   r  r  r    r  rK   rK   rL   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)rs   r6   r  r  r    r  rK   rK   rL   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  rK   rK   rL   test_abstract_pages  s    z#TestIsCreatable.test_abstract_pagesN)r   r   r   r  r  r  r  rK   rK   rK   rL   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
        rY   c                 S   s   g | ]}t |tr|qS rK   )
issubclassr=   )r  clsrK   rK   rL   r    s    
 zYTestDeferredPageClasses.test_deferred_page_classes_are_not_registered.<locals>.<listcomp>N)r  r=   rH   Zdeferr    r`   )rb   Zsimplepage_subclassesrK   rK   rL   -test_deferred_page_classes_are_not_registered  s
    zETestDeferredPageClasses.test_deferred_page_classes_are_not_registeredN)r   r   r   r  rK   rK   rK   rL   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   rH   r   r  rK   rK   rL   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=   rH   r   r  rK   rK   rL   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-   rH   r,   r  rK   rK   rL   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-   rH   r  r.   Z
about_spamr  rK   rK   rL   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  r7   rH   r,   r  rK   rK   rL   test_abstract_base_page_manager  s    z/TestPageManager.test_abstract_base_page_managerN)r   r   r   r  r  r  r  r  rK   rK   rK   rL   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.
    rO   c                 C   sD   t jjdd}|j}|  t jjdd}| |jtjt  d S )Nr   rQ   )r   rH   r^   content_typer  r`   r   rI   )rb   r  Zevent_index_content_typerK   rK   rL   test_delete_content_type  s     
z&TestIssue2024.test_delete_content_typeN)r   r   r   r  r   r  rK   rK   rK   rL   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 )TestMakePreviewRequestrO   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   rQ   r   r   rA  hostr   REQUEST_METHODGETSCRIPT_NAMErg   	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   rH   r^   make_preview_requestr`   r   r   r   headersr   r  rb   r  r   r   rK   rK   rL   -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   rQ   r   r   rA  r  r   r  r  r  rg   r  r  r   r  r  r  r  r  httpsr  r  r  r  r  r   rH   r   r   r^   r  r`   r   r   r   r  r   r  r  rK   rK   rL   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   rQ   r   r   rA  r  zlocalhost:8888r  r  r  rg   r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  rK   rK   rL   ?test_make_preview_request_for_accessible_page_non_standard_port?  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 |}|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   rQ   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_COOKIErF  HTTP_AUTHORIZATIONr   r   r  zx-forwarded-forr  cookier   z
user-agentrF  authorizationr  r  r  r  rg   r  rA  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  )r   rH   r^   r   r  r`   r   r   r   r  r  )rb   r  Zoriginal_headersfactoryZoriginal_requestr   r   rK   rK   rL   Ctest_make_preview_request_for_accessible_page_with_original_requestZ  sZ    



   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   rQ   r   r   r  r  )r   rH   r^   r  r`   r   r   r  rb   r   r   r   rK   rK   rL   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   rQ   r   r   r  r	  )	r   rH   r^   r  r`   r   r   r~  r  r  rK   rK   rL   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 5 Q R X | d	 | |  W 5 Q R X | d | 	|  W 5 Q R X d S )
Nr   rQ   zstream page)r  rU   )rW   bodyrZ   r\   r   r   )
r   rH   r^   rB   r_   r]   r   r   Zis_previewablers   )rb   r  Zstream_pageZplain_stream_pagerK   rK   rL   test_is_previewable  s    z*TestMakePreviewRequest.test_is_previewableN)r   r   r   r   r  r  r  r  r   r  r
  r  rK   rK   rK   rL   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'
    rO   c                 C   s   t ddd}| |j d S NzMy Awesome Pagezmy-awesome-pagery  )r   r   show_in_menusr{   rK   rK   rL   test_show_in_menus_default  s    z7TestShowInMenusDefaultOption.test_show_in_menus_defaultc                 C   s   t ddd}| |j d S r  )r%   rs   r  r{   rK   rK   rL   #test_show_in_menus_default_override  s    z@TestShowInMenusDefaultOption.test_show_in_menus_default_overrideN)r   r   r   r  r   r  r  rK   rK   rK   rL   r    s   r  c                   @   s   e Zd ZdgZdd ZdS )TestPageWithContentJSONrO   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   rQ   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   )rW   r   rX   rR   r  numchildrP  r   rY   rp  rm  r  locked	locked_by	locked_atr@  r  r  r  )rW   rX   rY   rR   r  )r  r   rP  r  r  r   r  r@  r  r  r  r  r  rp  z/home/about-them/)r=   rH   r^   r   rI   r1   Zserializable_datar   r  r  rP  r   r  r@  r]   r  Zwith_content_jsonr~  r  r`   rR   )rb   rA  Zeventpage_content_typerY   Zupdated_page	attr_namerK   rK   rL   'test_with_content_json_preserves_values  sH    
  z?TestPageWithContentJSON.test_with_content_json_preserves_valuesN)r   r   r   r   r  rK   rK   rK   rL   r    s   r  c                   @   s"   e Zd ZdgZdd Zdd ZdS )TestUnpublishrO   c                 C   s<   t jjdd}|jtddddd}|jdd	 |  d S )
Nr   r\   ZHomepageZhome2rU   rV   rZ   Fr  )r   rH   r^   r_   r=   r'  ru  )rb   r   Z	home_pagerK   rK   rL   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   rQ   r  r]  r  zwagtail.unpublishr  )r1   rH   r^   r_  rs   r  r   r  r  ru  rj  r   rt   ru   r  rK   rK   rL   'test_unpublish_also_unpublishes_aliases  s,     z5TestUnpublish.test_unpublish_also_unpublishes_aliasesN)r   r   r   r   r  r  rK   rK   rK   rL   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  rV   rZ   )	r   rH   r   r_   r=   r|   r   rI   Zspecific_page_ctyper  rK   rK   rL   r   A  s
    
zTestCachedContentType.setUpc              	   C   s<   |  d | jj}W 5 Q R X | |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   r\   N)r   r|   Zcached_content_typer`   r   rH   r^   Zcontent_type_idr  rK   rK   rL   test_golden_pathH  s    z&TestCachedContentType.test_golden_pathN)r   r   r   r  r   r   rK   rK   rK   rL   r  >  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 rG   )r!   r  r1   r  r   r2   r   r$   rb   Ztranslatable_modelsrK   rK   rL   test_get_translatable_modelsU  s    z6TestGetTranslatableModels.test_get_translatable_modelsc                 C   sJ   t dd}| t| | t| | t| | t| | t| d S )NT)Zinclude_subclasses)r!   r  r1   r   r2   r  r   r$   r"  rK   rK   rL   /test_get_translatable_models_include_subclasses`  s    
zITestGetTranslatableModels.test_get_translatable_models_include_subclassesN)r   r   r   r#  r$  rK   rK   rK   rL   r!  T  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 rG   )r   rH   r   r   r  rK   rK   rL   r   l  s    zTestDefaultLocale.setUpc                 C   s.   | j jtddddd}| |j| j j d S r  )r   r_   r=   r`   r  r{   rK   rK   rL   test_default_localeo  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  rW   rX   rY   r  rZ   r   rH   r   r   r_   r=   r`   r  )rb   r(  r|   rK   rK   rL   test_override_default_localev  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'  rZ   rV   r(  )rb   r(  Zfr_pager|   rK   rK   rL   %test_always_defaults_to_parent_locale  s       z7TestDefaultLocale.test_always_defaults_to_parent_localeN)r   r   r   r   r&  r)  r*  rK   rK   rK   rL   r%  k  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 )TestLocalizedrO   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   rQ   Tr$  u   NoëlrW   r%  )r   rH   r   r(  r   r^   r?  r&  fr_event_pagerW   r'  r_  ri  r  rK   rK   rL   r     s     zTestLocalized.setUpc                 C   s(   |  | jj| j |  | jj| j d S rG   )r`   r?  	localizedlocalized_draftr  rK   rK   rL   test_localized_same_language  s    z*TestLocalized.test_localized_same_languagec              	   C   sB   t d. | | jj| jj | | jj| jj W 5 Q R X d S r  )r   r  r`   r?  r.  r-  r
  r/  r  rK   rK   rL   !test_localized_different_language  s     z/TestLocalized.test_localized_different_languageFr+  c              	   C   s>   t d* | | jj| j | | jj| j W 5 Q R X dS )z<Should return the same page if WAGTAIL_I18N_ENABLED is Falser  N)r   r  r`   r?  r.  r/  r  rK   rK   rL   Atest_localized_different_language_with_wagtail_i18n_enabled_false  s    zOTestLocalized.test_localized_different_language_with_wagtail_i18n_enabled_falsec              	   C   sT   | j   | j   td, | | jj| j | | jj| j j	 W 5 Q R X d S r  )
r-  ru  r'  r   r  r`   r?  r.  r/  r
  r  rK   rK   rL   -test_localized_different_language_unpublished  s    

 z;TestLocalized.test_localized_different_language_unpublishedc              	   C   sf   t dR | | jj| j | | jj| jj | | jj| j | | jj| jj W 5 Q R X d S )Nde)r   r  r`   r?  r.  r-  r   r/  r  rK   rK   rL   -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N | | jj	| j | | j
j	| j
 | | jj| j | | j
j| j
 W 5 Q R X d S )Nr  r"  plr4  )r   rH   r^   r#  r'  r   r  r`   r?  r.  r-  r/  )rb   Z	en_localerK   rK   rL   *test_localized_with_missing_default_locale  s    z8TestLocalized.test_localized_with_missing_default_localeN)r   r   r   r   r   r0  r1  r   r2  r3  r5  r7  rK   rK   rK   rL   r,    s   


r,  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 )TestGetLockrO   c                 C   s    t jjdd}| |  d S )Nr   rQ   )r1   rH   r^   r   get_lockrW  rK   rK   rL   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   rQ   Ti        re     r   rf  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   rH   r^   r1   r  r  r   rl  rn  r   ro  r  r9  r  r   rs   for_userr  r   r`   get_messager  rb   	moderatorrX  lockexpected_date_stringrK   rK   rL   test_when_locked  s<          


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   rQ   Tz<b>'Christmas' is locked</b>.z+<b>'Christmas' is locked</b> by <b>you</b>.)
r   rH   r^   r1   r  r  r9  r`   r@  r  )rb   rB  rX  rC  rK   rK   rL   "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   rH   r^   r1   r  r  r   rl  rn  r   ro  r  r9  r  r   rs   r?  r  r`   r@  r  rA  rK   rK   rL   test_when_locked_globally  s<          


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   rQ   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   rH   r^   r1   r_  r   r   r   r  r  r   r   startr9  r  r   rs   r?  r  r   r`   r@  r   )rb   rB  rX  rH  rI  rC  Z
other_taskrK   rK   rL   test_when_locked_by_workflow4  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   rQ   i  r<  r=  r      r   rf  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  )r1   rH   r^   r   rl  rn  r   ro  r  r_  ri  r9  r  r   rs   r?  r  r`   r@  r   )rb   rX  ZrvnrC  rD  Z	superuserrK   rK   rL   test_when_scheduled_for_publishV  s4          

z+TestGetLock.test_when_scheduled_for_publishN)r   r   r   r   r:  rE  rF  r   rG  rK  rM  rK   rK   rK   rL   r8    s   !
!"r8  c                   @   s2   e Zd ZdgZdd Zdd Zdd Zdd	 Zd
S )TestPageCacheKeyrO   c                 C   s   t j | _t j | _d S rG   )r   rH   lastr|   r   
other_pager  rK   rK   rL   r   y  s    zTestPageCacheKey.setUpc                 C   s,   |  | jj| jj |  | jj| jj d S rG   )r`   r|   	cache_keyrP  r  rK   rK   rL   test_cache_key_consistent}  s    z*TestPageCacheKey.test_cache_key_consistentc              	   C   s*   |  d | jj | jj W 5 Q R X d S )Nr   )r   r|   rQ  rP  r  rK   rK   rL   test_no_queries  s    z TestPageCacheKey.test_no_queriesc                 C   s.   | j j}d| j _| j   | | j j| d S )Nzsomething-else)r|   rQ  rX   r'  r~  )rb   Zoriginal_cache_keyrK   rK   rL   test_changes_when_slug_changes  s    
z/TestPageCacheKey.test_changes_when_slug_changesN)r   r   r   r   r   rR  rS  rT  rK   rK   rK   rL   rN  v  s
   rN  c                   @   s   e Zd ZdgZdd ZdS )TestPageCachedParentObjExistsrO   c                 C   s2   t jjdd}d|_|jdd}| |dd d S )NrP   rQ   Z_cached_parent_obj_existsFr  zZPage.get_parent() (treebeard) no longer uses _cached_parent_obj to cache the parent object)r   rH   r^   Z_cached_parent_objr  r`   )rb   rc   r  rK   rK   rL   test_cached_parent_obj_exists  s    z;TestPageCachedParentObjExists.test_cached_parent_obj_existsN)r   r   r   r   rV  rK   rK   rK   rL   rU    s   rU  )|rn  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   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.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   Zwagtail.test.utilsrE   Zwagtail.url_routingrF   rM   rN   r   r   r  r-  rH  rT  r]  rc  r  r  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r%  r,  r8  rN  rU  rK   rK   rK   rL   <module>   s   8$i  l Zh! Lz       O     c $z / 1D,&F 