o
    h)                    @   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	 d dl
mZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZ d dlm Z  d dl!m"Z" d dl#m$Z$ dd Z%G dd deZ&G dd de$eZ'G dd de$eZ(G dd deZ)G dd deZ*G dd deZ+ed d!d"d#id$d%e,d&G d'd( d(eZ-G d)d* d*eZ.dS )+    N)StringIO)mock)Group)ContentType)
management)TestCaseTransactionTestCase)override_settings)reverse)	APIClient)signal_handlers)PagesAPIViewSet)LocalePageSite)BaseViewRestriction)models)
StreamPage)WagtailTestUtilsc                   C   s(   t jjtjjddjdd   S )NT)is_default_site)	inclusive)	r   objectsdescendant_ofr   get	root_pagelivepubliccount r   r   _/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/api/v2/tests/test_pages.pyget_total_page_count   s   r    c                   @   s   e Zd Zg ZdS )Test10411APIViewSetN)__name__
__module____qualname__meta_fieldsr   r   r   r   r!   "   s    r!   c                   @   s~  e Zd ZdgZdd Zdd Zdd Zdd	 Zd
d Zd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ddd d! Zeddd"d# Zd$d% Zedd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&dHdI Z'dJdK Z(dLdM Z)dNdO Z*dPdQ Z+dRdS Z,dTdU Z-dVdW Z.dXdY Z/dZd[ Z0d\d] Z1d^d_ Z2d`da Z3dbdc Z4ddde Z5dfdg Z6dhdi Z7djdk Z8dldm Z9dndo Z:dpdq Z;drds Z<dtdu Z=dvdw Z>dxdy Z?dzd{ Z@d|d} ZAd~d ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zaedddd ZbeddddĄ ZceddddǄ ZdddɄ Zedd˄ Zfdd̈́ Zgddτ Zhddф Ziddӄ ZjdS )TestPageListingdemosite.jsonc                 K      | j td|S Nwagtailapi_v2:pages:listingclientr   r
   selfparamsr   r   r   get_response)      zTestPageListing.get_responsec                 C      dd |d D S )Nc                 S      g | ]}|d  qS idr   .0pager   r   r   
<listcomp>-       z4TestPageListing.get_page_id_list.<locals>.<listcomp>itemsr   r.   contentr   r   r   get_page_id_list,   r1   z TestPageListing.get_page_id_listc                 C      t jjddS N	home-pageslugr   r   r   r.   r   r   r   get_homepage/      zTestPageListing.get_homepagec                 C   s   |   }| |jd | |d d t|jd}| d| | |d t	 | d|d  | |d d t
 | |d d t  | d| | |d t |d D ]}| d| | |d t	 | t|d  h d qYd S )	N   Content-typeapplication/jsonUTF-8metatotal_countr;   >   rC   typehtml_url
detail_urlfirst_published_at)r0   assertEqualstatus_codejsonloadsr=   decodeassertInassertIsInstancedictintr    listsetkeysr.   responser=   r8   r   r   r   
test_basic4   s&   zTestPageListing.test_basicc                 C   sT   t  }tjjjdd}|  |  }t|j	
d}| |d d |d  d S )N   r4   rK   rL   rM      )r    r   BlogEntryPager   r   	unpublishr0   rT   rU   r=   rV   rR   )r.   rM   r8   r_   r=   r   r   r   *test_unpublished_pages_dont_appear_in_listS   s   z:TestPageListing.test_unpublished_pages_dont_appear_in_listc                 C   sl   t  }tjjjdd}|jjtjdd t  }| 	|| | 
 }t|jd}| |d d | d S )N   r4   test)restriction_typepasswordrK   rL   rM   )r    r   BlogIndexPager   r   view_restrictionscreater   PASSWORDassertNotEqualr0   rT   rU   r=   rV   rR   )r.   rM   r8   new_total_countr_   r=   r   r   r   &test_private_pages_dont_appear_in_list]   s   z6TestPageListing.test_private_pages_dont_appear_in_listc                 C   sz   t  }| jddd}t }tjjjdd}|jjdd |	| |t
d}t|jd	d
 d }| || d S )Naliceri   usernameri   rf   r4   loginrh   r*   rK   rL   rM   )r   create_userr    r   rj   r   r   rk   rl   force_authenticater
   rT   rU   r=   rV   rR   )r.   r,   userold_total_countr8   r_   ro   r   r   r   "test_private_pages_with_user_loginl   s   
z2TestPageListing.test_private_pages_with_user_loginc           	      C   s   t  }| jddd}t }tjjjdd}tjjdd}|jj	dd	}|j
| |j
| || |td
}t|jdd d }| || d S )Nrq   ri   rr   rf   r4   Editors)namegroupsru   r*   rK   rL   rM   )r   rv   r    r   rj   r   r   r   rk   rl   r}   addrw   r
   rT   rU   r=   rV   rR   )	r.   r,   rx   ry   r8   editors_grouppage_restriction_instancer_   ro   r   r   r   #test_private_pages_with_user_groups{   s    
z3TestPageListing.test_private_pages_with_user_groupsc                 C   sF   t jjddd}tjjjdd j|d |  }| 	|j
d d S Ntestsmissingpage)	app_labelmodelra   r4   )content_typerH   r   r   rl   r   rc   filterorder_byupdater0   rR   rS   r.   missing_page_content_typer_   r   r   r   )test_page_listing_with_missing_page_model   s   z9TestPageListing.test_page_listing_with_missing_page_modelc                 C   s\   | j dd}t|jd}|d D ]}| |d d d | t| h d qd S )Ndemosite.BlogEntryPagerN   rK   r;   rL   rN   >   r5   rL   titler0   rT   rU   r=   rV   rR   r\   r]   r^   r   r   r   +test_type_filter_items_are_all_blog_entries   s   z;TestPageListing.test_type_filter_items_are_all_blog_entriesc                 C   s6   | j dd}t|jd}| |d d d d S )Nr   r   rK   rL   rM      r0   rT   rU   r=   rV   rR   r.   r_   r=   r   r   r   test_type_filter_total_count   s   z,TestPageListing.test_type_filter_total_countc                 C   s   | j dd}t|jd}d}d}|d D ]/}| |d d dd	g |d d dkr0d
}n
|d d d	kr:d
}| t| h d q| j	|dd | j	|dd d S )Nz)demosite.BlogEntryPage,demosite.EventPager   rK   Fr;   rL   rN   r   demosite.EventPageT>   r5   rL   r   z%No blog pages were found in the items)msgz&No event pages were found in the items)
r0   rT   rU   r=   rV   rW   rR   r\   r]   
assertTrue)r.   r_   r=   blog_page_seenevent_page_seenr8   r   r   r   test_type_filter_multiple   s   z)TestPageListing.test_type_filter_multiplec                 C   @   | j dd}t|jd}| |jd | |ddi d S )Nzdemosite.IDontExistr   rK     messagetype doesn't existr0   rT   rU   r=   rV   rR   rS   r   r   r   r   "test_non_existent_type_gives_error      z2TestPageListing.test_non_existent_type_gives_errorc                 C   r   )Nz	auth.Userr   rK   r   r   r   r   r   r   r   r   test_non_page_type_gives_error   r   z.TestPageListing.test_non_page_type_gives_errorTWAGTAIL_I18N_ENABLEDc                 C   s|   t jjdd}|  }||}|   | jdd}t	|j
d}| t|d d | |d d d |j d S )	Nfrlanguage_code)localerK   r;   rb   r   r5   )r   r   rl   rF   copy_for_translationget_latest_revisionpublishr0   rT   rU   r=   rV   rR   lenr5   r.   frenchhomepagefrench_homepager_   r=   r   r   r   test_locale_filter   s   
z"TestPageListing.test_locale_filterc                 C   s~   t jjdd}|  }||}|   | j|jd}t	
|jd}| t|d d | |d d d |j d S )	Nr   r   )translation_ofrK   r;   rb   r   r5   r   r   rl   rF   r   r   r   r0   r5   rT   rU   r=   rV   rR   r   r   r   r   r   test_translation_of_filter   s   
z*TestPageListing.test_translation_of_filterc                 C   d   | j dd}t|jd}|d D ]}| t| h d | t|d  h d qd S )Nr   r   rK   r;   >   r5   rL   r   rL   >   rC   rN   rO   rP   rQ   r   r^   r   r   r   test_fields_default      z#TestPageListing.test_fields_defaultc                 C   sH   | j dd}t|jd}|d D ]}| dt|d   qd S )Nr   r   rK   r;   r   rL   r0   rT   rU   r=   rV   rW   r\   r]   r^   r   r   r   %test_fields_default_with_i18n_enabled  s
   z5TestPageListing.test_fields_default_with_i18n_enabledc                 C   sJ   | j ddd}t|jd}|d D ]}| t| h d qd S )Nr   title,date,feed_imagerN   fieldsrK   r;   >   r5   daterL   r   
feed_imager   r^   r   r   r   test_fields
  s   zTestPageListing.test_fieldsc                 C   H   | j dd}t|jd}|d D ]}| t| ddh qd S )N-titler   rK   r;   r5   rL   r   r^   r   r   r   test_remove_fields  
   z"TestPageListing.test_remove_fieldsc                 C   r   )N	-html_urlr   rK   r;   >   r5   rL   r   rL   >   rC   rN   rP   rQ   r   r^   r   r   r   test_remove_meta_fields  r   z'TestPageListing.test_remove_meta_fieldsc                 C   r   )Nz5-type,-detail_url,-slug,-first_published_at,-html_urlr   rK   r;   r5   r   r   r^   r   r   r   test_remove_all_meta_fields'  s   z+TestPageListing.test_remove_all_meta_fieldsc                 C   r   )N-idr   rK   r;   rL   r   r   r^   r   r   r   test_remove_id_field0  r   z$TestPageListing.test_remove_id_fieldc                 C   f   | j ddd}t|jd}|d D ]}| t| h d | t|d  h d qd S )	Nr   *r   rK   r;   >
   r5   bodyr   rL   tagsr   r   related_linkscarousel_itemsfeed_image_thumbnailrL   >
   rC   rN   r   alias_ofrO   	seo_titlerP   show_in_menusrQ   search_descriptionr   r^   r   r   r   test_all_fields7  s   
zTestPageListing.test_all_fieldsc                 C   r   )	Nr   z*,-title,-date,-seo_titler   rK   r;   >   r5   r   rL   r   r   r   r   r   rL   >	   rC   rN   r   r   rO   rP   r   rQ   r   r   r^   r   r   r   %test_all_fields_then_remove_something[  s   
z5TestPageListing.test_all_fields_then_remove_somethingc                 C   sd   | j ddd}t|jd}|d D ]}| t| ddh | t|d  dh qd S )	Nr   	_,id,typer   rK   r;   r5   rL   rN   r   r^   r   r   r   test_remove_all_fields~  s   z&TestPageListing.test_remove_all_fieldsc                 C   N   | j ddd}t|jd}|d D ]}| t|d  h d qd S )Nr   feed_image(width,height)r   rK   r;   r   >   r5   rL   r   widthheightr   r^   r   r   r   test_nested_fields     z"TestPageListing.test_nested_fieldsc                 C   sN   | j ddd}t|jd}|d D ]}| t|d  ddh qd S )	Nr   feed_image(-title)r   rK   r;   r   r5   rL   r   r^   r   r   r   test_remove_nested_fields  s   z)TestPageListing.test_remove_nested_fieldsc                 C   r   )Nr   feed_image(*)r   rK   r;   r   >   r5   rL   r   r   r   r   r^   r   r   r   test_all_nested_fields  r   z&TestPageListing.test_all_nested_fieldsc                 C   sL   | j ddd}t|jd}|d D ]}| t|d  dh qd S )Nr   feed_image(_,id)r   rK   r;   r   r5   r   r^   r   r   r   test_remove_all_nested_fields  s   z-TestPageListing.test_remove_all_nested_fieldsc                 C   st   | j ddd}t|jd}|d D ]#}|d D ]}| t| h d | t|d  h d	 qqd S )
Nr   #carousel_items(image(width,height))r   rK   r;   r   >   r5   linkrL   imagecaption	embed_urlr   >   r5   rL   r   r   r   r   )r.   r_   r=   r8   carousel_itemr   r   r   test_nested_nested_fields  s    
z)TestPageListing.test_nested_nested_fieldsc                 C   sZ   | j ddd}t|jd}|d D ]}| t| h d | |d t	 qd S )Nr   title,related_linksr   rK   r;   >   r5   rL   r   r   r   
r0   rT   rU   r=   rV   rR   r\   r]   rX   r[   r^   r   r   r   test_fields_child_relation  s   z*TestPageListing.test_fields_child_relationc                 C   s   | j ddd}t|jd}|d D ]R}|d }|d urf| |t | t|	 h d | |d t
 | |d	 t | t|d	 	 h d
 | |d	 d d | |d	 d d|d   qd S )Nr   r   r   rK   r;   r   >   r5   rL   r   r5   rL   >   rN   rP   download_urlrN   wagtailimages.ImagerP   $http://localhost/api/main/images/%d/r0   rT   rU   r=   rV   rX   rY   rR   r\   r]   rZ   )r.   r_   r=   r8   r   r   r   r   test_fields_foreign_key  s,   

z'TestPageListing.test_fields_foreign_keyc                 C   sZ   | j ddd}t|jd}|d D ]}| t| h d | |d t	 qd S )Nr   r   r   rK   r;   >   r5   rL   r   r   r   r^   r   r   r   test_fields_tags  s   z TestPageListing.test_fields_tagsc                 C   sd   | j ddd}t|jd}tjtjd|jd}g d}| t	|d d 
 | d S )	Nr   z#date,title,feed_image,related_linksr   rK   object_pairs_hook)r5   rL   r   r   r   r   r;   r   r0   rT   rU   r=   rV   JSONDecodercollectionsOrderedDictrR   r[   r]   )r.   r_   r=   field_orderr   r   r   test_fields_ordering  s   
 z$TestPageListing.test_fields_orderingc                 C   r   )Ntitle,*r   rK   r   r   /fields error: '*' must be in the first positionr   r   r   r   r   'test_star_in_wrong_position_gives_error     z7TestPageListing.test_star_in_wrong_position_gives_errorc                 C   B   | j ddd}t|jd}| |jd | |ddi d S )Nr   feed_image(123,title,abc)r   rK   r   r   unknown fields: 123, abcr   r   r   r   r   %test_unknown_nested_fields_give_error     z5TestPageListing.test_unknown_nested_fields_give_errorc                 C   r   )Nparentr   rK   r   r   zunknown fields: parentr   r   r   r   r   test_parent_field_gives_error     z-TestPageListing.test_parent_field_gives_errorc                 C   r   )Nr   r   rK   r   r   zunknown fields: related_linksr   r   r   r   r   $test_fields_without_type_gives_error  r   z4TestPageListing.test_fields_without_type_gives_errorc                 C   r   )Npathr   rK   r   r   unknown fields: pathr   r   r   r   r   3test_fields_which_are_not_in_api_fields_gives_error#  r   zCTestPageListing.test_fields_which_are_not_in_api_fields_gives_errorc                 C   r   )N123,title,abcr   rK   r   r   r  r   r   r   r   r   %test_fields_unknown_field_gives_error*  r   z5TestPageListing.test_fields_unknown_field_gives_errorc                 C   r   )N-123,-title,-abcr   rK   r   r   r  r   r   r   r   r   ,test_fields_remove_unknown_field_gives_error1  r   z<TestPageListing.test_fields_remove_unknown_field_gives_errorc                 C   r  )Nr   title(foo,bar)r   rK   r   r   &'title' does not support nested fieldsr   r   r   r   r   6test_nested_fields_on_non_relational_field_gives_error8  r  zFTestPageListing.test_nested_fields_on_non_relational_field_gives_errorc                 C   s:   | j dd}t|jd}| |}| |dg d S )Nz	Home pager   rK      r0   rT   rU   r=   rV   r>   rR   r.   r_   r=   page_id_listr   r   r   test_filtering_exact_filterC     
z+TestPageListing.test_filtering_exact_filterc                 C   <   | j ddd}t|jd}| |}| |dg d S )Nr   
2013-12-02)rN   r   rK   ra   r  r  r   r   r   -test_filtering_exact_filter_on_specific_fieldJ     
z=TestPageListing.test_filtering_exact_filter_on_specific_fieldc                 C   s:   | j dd}t|jd}| |}| |dg d S )Nra   r4   rK   r  r  r   r   r   test_filtering_on_idQ  r  z$TestPageListing.test_filtering_on_idc                 C   r  )Ndemosite.contactpage   rN   r   rK      r  r  r   r   r   test_filtering_on_foreign_keyX  r!  z-TestPageListing.test_filtering_on_foreign_keyc                 C   <   | j dd}t|jd}| |}| |g d d S )Nfalser   rK   )   	   ra            r  r  r   r   r   test_filtering_on_boolean_     
z)TestPageListing.test_filtering_on_booleanc                 C   r   )Nr  )r   rK   r   r   z?query parameter is not an operation or a recognised field: dater   r   r   r   r   :test_filtering_doesnt_work_on_specific_fields_without_typef     zJTestPageListing.test_filtering_doesnt_work_on_specific_fields_without_typec                 C   s>   | j ddd}t|jd}| |}| |ddg d S )Nr   wagtailrN   r   rK   ra   r-  r  r  r   r   r   test_filtering_tagsr     
z#TestPageListing.test_filtering_tagsc                 C   r  )Nr   zwagtail,birdr5  rK   ra   r  r  r   r   r   test_filtering_multiple_tagsy  r!  z,TestPageListing.test_filtering_multiple_tagsc                 C   r   )Nabc)not_a_fieldrK   r   r   zFquery parameter is not an operation or a recognised field: not_a_fieldr   r   r   r   r   (test_filtering_unknown_field_gives_error  r3  z8TestPageListing.test_filtering_unknown_field_gives_errorc                 C   r   )Nr9  r4   rK   r   r   zefield filter error. 'abc' is not a valid value for id (invalid literal for int() with base 10: 'abc')r   r   r   r   r    test_filtering_id_int_validation  r3  z0TestPageListing.test_filtering_id_int_validationc                 C   sJ   | j ddd}t|jd}| |jd | |d d d d d S )	Nr#  r9  r%  rK   r   r   =   z=field filter error. 'abc' is not a valid value for feed_imager   r   r   r   r   )test_filtering_foreign_key_int_validation  s   z9TestPageListing.test_filtering_foreign_key_int_validationc                 C   r   )Nr9  r*  rK   r   r   zhfield filter error. 'abc' is not a valid value for show_in_menus (expected 'true' or 'false', got 'abc')r   r   r   r   r   !test_filtering_boolean_validation  r3  z1TestPageListing.test_filtering_boolean_validationc                 C   r   )N rB   rK   r   r   z<field filter error. null characters are not allowed for slugr   r   r   r   r   1test_slug_field_containing_null_bytes_gives_error  s   zATestPageListing.test_slug_field_containing_null_bytes_gives_errorc                 C   r(  )Nrf   child_ofrK   ra   r-  r.  r  r  r   r   r   test_child_of_filter  r1  z$TestPageListing.test_child_of_filterc                 C   r(  )NrootrB  rK   )   rf         r&  r  r  r   r   r   test_child_of_root  s   
z"TestPageListing.test_child_of_rootc                 C   s:   | j ddd}t|jd}| |}| |g  d S )Nr   rf   )rN   rC  rK   r  r  r   r   r   test_child_of_with_type  s   
z'TestPageListing.test_child_of_with_typec                 C   r   )N  rB  rK   r   r   parent page doesn't existr   r   r   r   r   &test_child_of_unknown_page_gives_error  r   z6TestPageListing.test_child_of_unknown_page_gives_errorc                 C   r   )Nr9  rB  rK   r   r   z#child_of must be a positive integerr   r   r   r   r   %test_child_of_not_integer_gives_error  r   z5TestPageListing.test_child_of_not_integer_gives_errorc                 C   r   )Nrb   rB  rK   r   r   rM  r   r   r   r   r   5test_child_of_page_thats_not_in_same_site_gives_error  r  zETestPageListing.test_child_of_page_thats_not_in_same_site_gives_errorc                 C   s2   | j dd}| }| |}| |ddg d S )N
   ancestor_ofr  rH  r0   rT   r>   rR   r  r   r   r   test_ancestor_of_filter  s   
z'TestPageListing.test_ancestor_of_filterc                 C   s2   | j ddd}| }| |}| |dg d S )Ndemosite.eventindexpager+  )rN   rS  rG  rT  r  r   r   r   test_ancestor_of_with_type  s   
z*TestPageListing.test_ancestor_of_with_typec                 C   6   | j dd}| }| |jd | |ddi d S )NrL  rR  r   r   zdescendant page doesn't existr0   rT   rR   rS   r   r   r   r   )test_ancestor_of_unknown_page_gives_error     z9TestPageListing.test_ancestor_of_unknown_page_gives_errorc                 C   rX  )Nr9  rR  r   r   z&ancestor_of must be a positive integerrY  r   r   r   r   (test_ancestor_of_not_integer_gives_error  r[  z8TestPageListing.test_ancestor_of_not_integer_gives_errorc                 C   s.   | j dd}| }| |}| |g  d S )Nr  rR  rT  r  r   r   r   'test_ancestor_of_home_page_ignores_root  s   
z7TestPageListing.test_ancestor_of_home_page_ignores_rootc                 C   r(  )NrH  r   rK   )rQ     r/           r  r  r   r   r   test_descendant_of_filter  r1  z)TestPageListing.test_descendant_of_filterc                 C   r(  )NrF  r^  rK   )rG  r+  r,  rf   ra   r-  r.  rH  rQ  r_  r/  r`  ra  rb  rI        r&  r  r  r   r   r   test_descendant_of_root  s   
z'TestPageListing.test_descendant_of_rootc                 C   r  )NrV  r  )rN   r   rK   rG  r  r  r   r   r   test_descendant_of_with_type!  r!  z,TestPageListing.test_descendant_of_with_typec                 C   r   )NrL  r^  rK   r   r   ancestor page doesn't existr   r   r   r   r   +test_descendant_of_unknown_page_gives_error(  r   z;TestPageListing.test_descendant_of_unknown_page_gives_errorc                 C   r   )Nr9  r^  rK   r   r   z(descendant_of must be a positive integerr   r   r   r   r   *test_descendant_of_not_integer_gives_error/  r  z:TestPageListing.test_descendant_of_not_integer_gives_errorc                 C   r   )Nrb   r^  rK   r   r   rh  r   r   r   r   r   :test_descendant_of_page_thats_not_in_same_site_gives_error8  r  zJTestPageListing.test_descendant_of_page_thats_not_in_same_site_gives_errorc                 C   r  )NrH  rf   )r   rC  rK   r   r   z9filtering by descendant_of with child_of is not supportedr   r   r   r   r   9test_descendant_of_when_filtering_by_child_of_gives_error@  s   zITestPageListing.test_descendant_of_when_filtering_by_child_of_gives_errorc                 C   s2   | j dd}t|jd}| |ddi d S )N	localhostsiterK   r   zQYour query returned multiple sites. Try adding a port number to your site filter.r   r   r   r   r   ,test_site_filter_same_hostname_returns_errorL  s   z<TestPageListing.test_site_filter_same_hostname_returns_errorc                 C   s<   | j dd}t|jd}| |}| |ddg d S )Nzlocalhost:8001rn  rK         r  r  r   r   r   test_site_filterW  s   
z TestPageListing.test_site_filterc                 C   s8   |   }t|jd}| |}| |g d d S )NrK   )r  rG  r+  r,  rf   ra   r-  r.  rH  rQ  r_  r/  r`  ra  rb  rI  rd  re  r&  r  r  r   r   r   test_ordering_defaulta  s   
z%TestPageListing.test_ordering_defaultc                 C   r(  )Nr   orderrK   )r`  ra  r.  rb  rf   ra   r-  r&  re  r+  r,  rG  r  rd  rI  r/  rH  rQ  r_  r  r  r   r   r   test_ordering_by_titlek     
z&TestPageListing.test_ordering_by_titlec                 C   r(  )Nr   ru  rK   r_  rQ  rH  r/  rI  rd  r  rG  r,  r+  re  r&  r-  ra   rf   rb  r.  ra  r`  r  r  r   r   r    test_ordering_by_title_backwardsu  rx  z0TestPageListing.test_ordering_by_title_backwardsc                 C   s`   | j dd}t|jd}| |}| j dd}t|jd}| |}| || d S )Nrandomru  rK   )r0   rT   rU   r=   rV   r>   rn   )r.   
response_1	content_1page_id_list_1
response_2	content_2page_id_list_2r   r   r   test_ordering_by_random  s   

z'TestPageListing.test_ordering_by_randomc                 C   r   )Nz-randomru  rK   r   r   z(cannot order by 'random' (unknown field)r   r   r   r   r   -test_ordering_by_random_backwards_gives_error  r  z=TestPageListing.test_ordering_by_random_backwards_gives_errorc                 C   r  )Nr{  rQ  )rv  offsetrK   r   r   z,random ordering with offset is not supportedr   r   r   r   r   /test_ordering_by_random_with_offset_gives_error     z?TestPageListing.test_ordering_by_random_with_offset_gives_errorc                 C   r(  )Nr   r   rK   rD  r  r  r   r   r   test_ordering_default_with_type  r1  z/TestPageListing.test_ordering_default_with_typec                 C   >   | j ddd}t|jd}| |}| |g d d S )Nr   r   rN   rv  rK   )r.  ra   r-  r  r  r   r   r    test_ordering_by_title_with_type  r7  z0TestPageListing.test_ordering_by_title_with_typec                 C   r  )Nr   r   r  rK   rD  r  r  r   r   r   )test_ordering_by_specific_field_with_type  r7  z9TestPageListing.test_ordering_by_specific_field_with_typec                 C   r   )Nr:  ru  rK   r   r   z-cannot order by 'not_a_field' (unknown field)r   r   r   r   r   *test_ordering_by_unknown_field_gives_error  r  z:TestPageListing.test_ordering_by_unknown_field_gives_errorc                 C   sB   | j dgd}t|jd}| |jd | |ddi d S )Nz	random,idru  rK   r   r   z4random ordering cannot be combined with other fieldsr   r   r   r   r   3test_random_ordering_with_unknown_field_gives_error  r  zCTestPageListing.test_random_ordering_with_unknown_field_gives_errorc                 C   R   | j dgd}t|jd}| |}g d}| |d d |d d  d S )Nzid,slugru  rK   )r  rG  rf   rH  r+  r,  rQ  r&  rd  re  r_  ra   r/  r-  r.  rI  r`  ra  rb  r_  r  r.   r_   r=   r  expected_orderr   r   r   test_ordering_by_id_and_slug  
   
 z,TestPageListing.test_ordering_by_id_and_slugc                 C   r  )Nz	title,-idru  rK   ry  rf   r  r  r   r   r   'test_ordering_by_title_and_id_backwards  r  z7TestPageListing.test_ordering_by_title_and_id_backwardsc                 C   s6   | j dd}t|jd}| t|d d d S )Nr  limitrK   r;   r0   rT   rU   r=   rV   rR   r   r   r   r   r   "test_limit_only_two_items_returned  s   z2TestPageListing.test_limit_only_two_items_returnedc                 C   8   | j dd}t|jd}| |d d t  d S )Nr  r  rK   rL   rM   r0   rT   rU   r=   rV   rR   r    r   r   r   r   test_limit_total_count     z&TestPageListing.test_limit_total_countc                 C   r   )Nr9  r  rK   r   r   z limit must be a positive integerr   r   r   r   r   "test_limit_not_integer_gives_error
  r   z2TestPageListing.test_limit_not_integer_gives_errorc                 C   r   )NrL  r  rK   r   r   zlimit cannot be higher than 20r   r   r   r   r   test_limit_too_high_gives_error  r   z/TestPageListing.test_limit_too_high_gives_errorN)WAGTAILAPI_LIMIT_MAXc                 C   sF   | j dd}t|jd}| |jd | t|d t  d S )Ni@B r  rK   rH   r;   )	r0   rT   rU   r=   rV   rR   rS   r   r    r   r   r   r   #test_limit_max_none_gives_no_errors  s   z3TestPageListing.test_limit_max_none_gives_no_errorsrQ  c                 C   r   )NrI  r  rK   r   r   zlimit cannot be higher than 10r   r   r   r   r   !test_limit_maximum_can_be_changed   r  z1TestPageListing.test_limit_maximum_can_be_changedr  c                 C   s2   |   }t|jd}| t|d d d S )NrK   r;   r  r  r   r   r   r   #test_limit_default_changes_with_max(  s   z3TestPageListing.test_limit_default_changes_with_maxc                 C   s:   |   }t|jd}| |}| |dd d S )NrK   rf   rG  r0   rT   rU   r=   rV   r>   rR   indexr  r   r   r   )test_offset_5_usually_appears_5th_in_list3  s   
z9TestPageListing.test_offset_5_usually_appears_5th_in_listc                 C   s>   | j dd}t|jd}| |}| |dd d S )NrG  r  rK   rf   r   r  r  r   r   r    test_offset_5_moves_after_offset9  s   
z0TestPageListing.test_offset_5_moves_after_offsetc                 C   r  )NrQ  r  rK   rL   rM   r  r   r   r   r   test_offset_total_count?  r  z'TestPageListing.test_offset_total_countc                 C   r   )Nr9  r  rK   r   r   z!offset must be a positive integerr   r   r   r   r   #test_offset_not_integer_gives_errorF  r   z3TestPageListing.test_offset_not_integer_gives_errorc                 C   s(   t j   |  }| |jd d S )NrH   )r   r   alldeleter0   rR   rS   r.   r_   r   r   r   test_issue_3967O  s   zTestPageListing.test_issue_3967c                 C   s"   | j td}| |jd d S )Nz!wagtailapi_v2:issue_10411:listingrH   )r,   r   r
   rR   rS   r  r   r   r   test_issue_10411U  s   z TestPageListing.test_issue_10411)kr"   r#   r$   fixturesr0   r>   rF   r`   re   rp   rz   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  r  r   r"  r'  r0  r2  r6  r8  r;  r<  r>  r?  rA  rE  rJ  rK  rN  rO  rP  rU  rW  rZ  r\  r]  rc  rf  rg  ri  rj  rk  rl  rp  rs  rt  rw  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r&   &   s    

	


	$#		
		


	



				



	r&   c                       s   e Zd ZdgZ f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d Zdd Zdd Zdd Zeddd d! Zd"d# Zd$d% Zd&d' Zd(d) Z  ZS )*TestPageListingSearchr'   c                    s"   t    tjddt dd d S )Nupdate_indexdefault2   )backend_namestdout
chunk_size)supersetUpr   call_commandr   rE   	__class__r   r   r  ^  s   

zTestPageListingSearch.setUpc                 K   r(   r)   r+   r-   r   r   r   r0   g  r1   z"TestPageListingSearch.get_responsec                 C   r2   )Nc                 S   r3   r4   r   r6   r   r   r   r9   k  r:   z:TestPageListingSearch.get_page_id_list.<locals>.<listcomp>r;   r   r<   r   r   r   r>   j  r1   z&TestPageListingSearch.get_page_id_listc                 C   r?   r@   rD   rE   r   r   r   rF   m  rG   z"TestPageListingSearch.get_homepageTr   c                 C   s   t jjdd}|  }||}|   tjjdd}||}|   | j	ddd}t
|jd}| t|d d	 | |d d
 d |j d S )Nr   r   z/home-page/events-index/url_pathevents)r   searchrK   r;   rb   r   r5   )r   r   rl   rF   r   r   r   r   r   r0   rT   rU   r=   rV   rR   r   r5   )r.   r   r   r   events_indexfrench_events_indexr_   r=   r   r   r   test_locale_filter_with_searchp  s   

z4TestPageListingSearch.test_locale_filter_with_searchc                 C   s   t jjdd}|  }||}|   | j|jdd}t	
|jd}| t|d d | |d d d	 |j | j|jd
d}t	
|jd}| t|d d d S )Nr   r   home)r   r  rK   r;   rb   r   r5   gnomer   r   r   r   r   &test_translation_of_filter_with_search  s   
z<TestPageListingSearch.test_translation_of_filter_with_searchc                 C   s@   | j dd}t|jd}| |}| t|h d d S )Nblogr  rK   >   rf   ra   r-  r.  r0   rT   rU   r=   rV   r>   rR   r\   r  r   r   r   test_search_for_blog  s   
z*TestPageListingSearch.test_search_for_blogc                 C   sB   | j ddd}t|jd}| |}| t|h d d S )Nr   r  rN   r  rK      ra   r-  r.  r  r  r   r   r   test_search_with_type  s   
z+TestPageListingSearch.test_search_with_typec                 C   r  )Nzdemosite.InvalidPageTyper  r  rK   r   r   r   r   r   r   r   r   test_search_with_invalid_type  s   z3TestPageListingSearch.test_search_with_invalid_typec                 C   s>   | j dddd}t|jd}| |}| |dg d S )NzAnother blog postr  r   )r   r  rv  rK   r.  r  r  r   r   r   test_search_with_filter  s   
z-TestPageListingSearch.test_search_with_filterc                 C   sF   | j ddddd}t|jd}| |jd | |dd	i d S )
Nr   foor  r   )rN   r   r  rv  rK   r   r   z>cannot filter by 'body' while searching (field is not indexed)r   r   r   r   r   /test_search_with_filter_on_non_filterable_field  s   zETestPageListingSearch.test_search_with_filter_on_non_filterable_fieldc                 C   r  )Nr  r   )r  rv  rK   )r.  rf   ra   r-  r  r  r   r   r   test_search_with_order  s   
z,TestPageListingSearch.test_search_with_orderc                 C   D   | j dddd}t|jd}| |jd | |ddi d S )	Nr   r  r   )rN   r  rv  rK   r   r   z=cannot order by 'body' while searching (field is not indexed)r   r   r   r   r   .test_search_with_order_on_non_filterable_field  s   zDTestPageListingSearch.test_search_with_order_on_non_filterable_fieldF)WAGTAILAPI_SEARCH_ENABLEDc                 C   r   )Nr  r  rK   r   r   zsearch is disabledr   r   r   r   r   %test_search_when_disabled_gives_error  r  z;TestPageListingSearch.test_search_when_disabled_gives_errorc                 C   r  )	Nr   r  r4  )rN   r  r   rK   r   r   z5filtering by tag with a search query is not supportedr   r   r   r   r   -test_search_when_filtering_by_tag_gives_error  s   zCTestPageListingSearch.test_search_when_filtering_by_tag_gives_errorc                 C   sB   | j dddd}t|jd}| |}| t|dh d S )Nr   blog elephantsandrN   r  search_operatorrK   r-  r  r  r   r   r   test_search_operator_and  s   
z.TestPageListingSearch.test_search_operator_andc                 C   sD   | j dddd}t|jd}| |}| t|h d d S )Nr   r  orr  rK   r  r  r  r   r   r   test_search_operator_or  s   
z-TestPageListingSearch.test_search_operator_orc                 C   sT   | j dd}t|jd}| |jd | |d d | |d d d	 d S )
N r  rK   rH   rI   rJ   rL   rM   r   r   r   r   r   r   test_empty_searches_work  s
   z.TestPageListingSearch.test_empty_searches_work)r"   r#   r$   r  r  r0   r>   rF   r	   r  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__r   r   r  r   r  [  s.    	

	


r  c                   @   s   e Zd ZdgZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
edddd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:S );TestPageDetailr'   c                 K   s   | j td|fd|S )Nwagtailapi_v2:pages:detailargsr+   )r.   page_idr/   r   r   r   r0   
  s   zTestPageDetail.get_responsec                 C   sf  |  d}| |jd | |d d t|jd}| d| | |d d | d| | |d t	 | d|d  | |d d d	 | d
|d  | |d d
 d | d|d  | |d d d | d|d  | |d d t	 | t
|d d  h d | |d d d d | |d d d t	 | t
|d d d  h d | |d d d d d | |d d d d
 d | |d d d d d | d|d  | |d d  | d| | d| | d| | d| | d| | d| | |d d | |d ddg | |d t	 | t
|d  h d | |d d d | |d d t	 | t
|d d  h d  | |d d d d! | |d d d
 d" | |d# d$d%i | |d g  |d D ]}| t
| h d& | t
|d  dh qd S )'Nra   rH   rI   rJ   rK   r5   rL   rN   r   rP   #http://localhost/api/main/pages/16/rO   &http://localhost/blog-index/blog-post/r	  >   r5   rL   r   rf   >   rN   rO   rP   zdemosite.BlogIndexPagez"http://localhost/api/main/pages/5/zhttp://localhost/blog-index/r   r   r   r   r   r   r   r  birdr4  r$  >   rN   rP   r   r   z#http://localhost/api/main/images/7/r   errorSourceImageIOError>   r5   r   rL   r   r   r   )r0   rR   rS   rT   rU   r=   rV   rW   rX   rY   r\   r]   assertIsNoner.   r_   r=   r   r   r   r   r`     s   
 	
zTestPageDetail.test_basicc                 C   s2   |  d}t|jd}| |d d  d S )Nr  rK   rL   r	  )r0   rT   rU   r=   rV   r  r   r   r   r   )test_meta_parent_id_doesnt_show_root_pagez  s   
z8TestPageDetail.test_meta_parent_id_doesnt_show_root_pagec                 C   sx   |  d}t|jd}tjtjd|jd}g d}| t	|
 | g d}| t	|d 
 | d S )Nra   rK   r   )
r5   rL   r   r   r   r   r   r   r   r   )
rN   rP   rO   rC   r   r   r   rQ   r   r	  rL   r   )r.   r_   r=   r   meta_field_orderr   r   r   test_field_ordering  s   

z"TestPageDetail.test_field_orderingc                 C   sV   t jjjdd jd d | d}t|j	
d}| d| | |d  d S )Nra   r4   )feed_image_idrK   r   r   )r   rc   r   r   r   r   r0   rT   rU   r=   rV   rW   r  r   r   r   r   test_null_foreign_key  s
   
z$TestPageDetail.test_null_foreign_keyc                 C   sH   t jjddd}tjjjdd j|d | d}| 	|j
d d S r   r   r   r   r   r   !test_page_with_missing_page_model  s   
z0TestPageDetail.test_page_with_missing_page_modelc                 C   sp  t jjddj}|jdd}| |j}| |jd | |d d t	
|jd}| |d	 d
 d | |d	 d d | d|d	  | |d	 d t | t|d	 d  h d | |d	 d d d | |d	 d d	 t | t|d	 d d	  h d | |d	 d d	 d
 d | |d	 d d	 d d | |d	 d d	 d d d S )Nra   r4   znew-slug)update_slugrH   rI   rJ   rK   rL   rN   r   rO   z%http://localhost/blog-index/new-slug/r   >   r5   rL   r   r5   >   rN   rO   rP   rP   r  r  )r   r   r   specificcreate_aliasr0   r5   rR   rS   rT   rU   r=   rV   rW   rX   rY   r\   r]   )r.   originalaliasr_   r=   r   r   r   test_alias_page  s@   zTestPageDetail.test_alias_pageTr   c                 C   s8   |  d}t|jd}| dt|d   d S )Nra   rK   r   rL   r   )r.   r_   r8   r   r   r   %test_default_fields_with_i18n_enabled  s   
z4TestPageDetail.test_default_fields_with_i18n_enabledc                 C   L   | j ddd}t|jd}| dt|  | dt|  d S )Nra   r   r   rK   r5   r   	r0   rT   rU   r=   rV   rW   r\   r]   assertNotInr   r   r   r   r        z!TestPageDetail.test_remove_fieldsc                 C   sT   | j ddd}t|jd}| dt|d   | dt|d   d S )Nra   r   r   rK   rP   rL   rO   r  r   r   r   r   r     s   z&TestPageDetail.test_remove_meta_fieldsc                 C   r  )Nra   zu-type,-detail_url,-slug,-first_published_at,-alias_of,-html_url,-search_description,-show_in_menus,-parent,-seo_titler   rK   r5   rL   r  r   r   r   r   r      s   z*TestPageDetail.test_remove_all_meta_fieldsc                 C   r  )Nra   r   r   rK   r   r5   r  r   r   r   r   r   
  r  z#TestPageDetail.test_remove_id_fieldc                 C   sV   | j ddd}t|jd}| t| ddh | t|d  dh d S )Nra   r   r   rK   r5   rL   rN   r   r   r   r   r   r     s   z%TestPageDetail.test_remove_all_fieldsc                 C   @   | j ddd}t|jd}| t|d  h d d S )Nra   r   r   rK   r   >   r5   rL   r   r   r   r   r   r   r   r   r        z!TestPageDetail.test_nested_fieldsc                 C   s@   | j ddd}t|jd}| t|d  ddh d S )Nra   r   r   rK   r   r5   rL   r   r   r   r   r   r   !  s    z(TestPageDetail.test_remove_nested_fieldsc                 C   r  )Nra   r   r   rK   r   >   r5   rL   r   r   r   r   r   r   r   r   r   '  r  z%TestPageDetail.test_all_nested_fieldsc                 C   s>   | j ddd}t|jd}| t|d  dh d S )Nra   r   r   rK   r   r5   r   r   r   r   r   r   0  s   z,TestPageDetail.test_remove_all_nested_fieldsc                 C   r   )	Nra   r   r   rK   r   >   r5   r   rL   r   r   r   r   >   r5   rL   r   r   r   r   r  r   r   r   r   6  s   
z(TestPageDetail.test_nested_nested_fieldsc                 C   s0   |  d}t|jd}| |d t d S )Nra   rK   r   )r0   rT   rU   r=   rV   rX   r[   r   r   r   r   "test_fields_child_relation_is_listE  s   
z1TestPageDetail.test_fields_child_relation_is_listc                 C   s   |  d}t|jd}|d }| |t | t|	 h d | |d t
 | |d t | t|d 	 h d | |d d d	 | |d d
 d|d   d S )Nra   rK   r   >   r5   rL   r   r5   rL   >   rN   rP   r   rN   r   rP   r   r   )r.   r_   r=   r   r   r   r   r   K  s   


z&TestPageDetail.test_fields_foreign_keyc                 C   r  )Nra   r   r   rK   r   r   r  r   r   r   r   r   r  ^  r  z6TestPageDetail.test_star_in_wrong_position_gives_errorc                 C   r  )Nra   r  r   rK   r   r   r  r   r   r   r   r   r  g     z4TestPageDetail.test_unknown_nested_fields_give_errorc                 C   r  )Nra   r  r   rK   r   r   r  r   r   r   r   r   r  n  r   zBTestPageDetail.test_fields_which_are_not_in_api_fields_gives_errorc                 C   r  )Nra   r  r   rK   r   r   r  r   r   r   r   r   r  u  r   z4TestPageDetail.test_fields_unknown_field_gives_errorc                 C   r  )Nra   r  r   rK   r   r   r  r   r   r   r   r   r  |  r   z;TestPageDetail.test_fields_remove_unknown_field_gives_errorc                 C   r  )Nra   r  r   rK   r   r   r  r   r   r   r   r   r    r   zETestPageDetail.test_nested_fields_on_non_relational_field_gives_errorc                 C   s   t jjdd}|jtjddd}tjjj|dddd}tjjj|d	d
dddd}| j|j	dd}t
|jd}| |d |j	dddiddddddd	|j	d
ddid
dddddd	g dS )zl
        Check that adding form_fields will correctly return then in the API response when declared
        rA   rB   z
Contact usr  instancerb   email)r8   
sort_orderlabel
field_typer  r   	multilineTz<em>please</em> be polite)r8   r  r  r  required	help_textform_fieldsr   rK   rN   zdemosite.FormFieldr  )	r5   
clean_namerL   r  r	  r  r  choicesdefault_valueN)r   r   r   	add_childr   FormPage	FormFieldrl   r0   pkrT   rU   r=   rV   rR   )r.   	home_page	form_pagefield_1field_2r_   r=   r   r   r   test_form_fields_on_form_page  sT   	z,TestPageDetail.test_form_fields_on_form_pageN) r"   r#   r$   r  r0   r`   r  r  r  r  r  r	   r  r   r   r   r   r   r   r   r   r   r   r  r   r  r  r  r  r  r  r  r   r   r   r   r    s<    k&	+

			r  c                   @   sJ   e Zd ZdgZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )TestPageFindr'   c                 K   r(   )Nzwagtailapi_v2:pages:findr+   r-   r   r   r   r0     r1   zTestPageFind.get_responsec                 C   sL   |   }| |jd | |d d t|jd}| |ddi d S )N  rI   rJ   rK   r   	not foundr0   rR   rS   rT   rU   r=   rV   r   r   r   r   test_without_parameters  s
   z$TestPageFind.test_without_parametersc                 C   s.   | j dd}| j|dtddgd dd d S )Nrf   r4   http://localhostr  r  Ffetch_redirect_responser0   assertRedirectsr
   r  r   r   r   test_find_by_id     
zTestPageFind.test_find_by_idc                 C   P   | j dd}| |jd | |d d t|jd}| |ddi d S )	Ni  r4   r  rI   rJ   rK   r   r  r  r   r   r   r   test_find_by_id_nonexistent  
   z(TestPageFind.test_find_by_id_nonexistentc                 C   .   | j dd}| j|dtddgd dd d S )	Nz/events-index/event-1/	html_pathr  r  r+  r  Fr  r  r  r   r   r   test_find_by_html_path  r"  z#TestPageFind.test_find_by_html_pathc                 C   r&  )	Nzevents-index/event-1r'  r  r  r+  r  Fr  r  r  r   r   r   9test_find_by_html_path_with_start_and_end_slashes_removed  r"  zFTestPageFind.test_find_by_html_path_with_start_and_end_slashes_removedc                 C   r#  )	Nz/foor'  r  rI   rJ   rK   r   r  r  r   r   r   r   "test_find_by_html_path_nonexistent  r%  z/TestPageFind.test_find_by_html_path_nonexistentN)r"   r#   r$   r  r0   r  r!  r$  r)  r*  r+  r   r   r   r   r    s    			r  c                   @   sB   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S )TestPageDetailWithStreamFieldz	test.jsonc                 C   s   t jjdd| _d S )Nz/home/r  )r   r   r   r   rE   r   r   r   r    s   z#TestPageDetailWithStreamField.setUpc                 C   s   t dd|d}| jj|dS )Nzstream pagezstream-page)r   rC   r   r  )r   r   r  )r.   r   stream_pager   r   r   make_stream_page
  s   z.TestPageDetailWithStreamField.make_stream_pagec                 C   s   |  d}td|jfd}| j|}| |jd | |d d t|j	
d}| d| | |d |j | d	| | t|d	 d
 | |d	 d d d | |d	 d d d | |d	 d d  d S )Nz"[{"type": "text", "value": "foo"}]r  r  rH   zcontent-typerJ   utf-8r5   r   rb   r   rN   textvaluer  )r.  r
   r5   r,   r   rR   rS   rT   rU   r=   rV   rW   r   r   r.   r-  response_urlr_   r=   r   r   r   "test_can_fetch_streamfield_content  s   
z@TestPageDetailWithStreamField.test_can_fetch_streamfield_contentc                 C   sl   |  d}td|jfd}| j|}t|jd}| 	|d d d d | 	|d d d	 d
 d S )N[{"type": "image", "value": 1}]r  r  r/  r   r   rN   r   r1  rb   
r.  r
   r5   r,   r   rT   rU   r=   rV   rR   r2  r   r   r   test_image_chooser_block!  s   
z6TestPageDetailWithStreamField.test_image_chooser_blockc                 C   sx   |  d}dtd|jfd}| j|}t|j	d}| 
|d d d d	 | 
|d d d
 ddd d S )Nr5  z{}?extended=1r  r  r/  r   r   rN   r   r1  rb   zA missing image)r5   r   )r.  formatr
   r5   r,   r   rT   rU   r=   rV   rR   r2  r   r   r   ;test_image_chooser_block_with_custom_get_api_representation,  s   
zYTestPageDetailWithStreamField.test_image_chooser_block_with_custom_get_api_representationc                 C   s   |  d}td|jfd}| j|}t|jd}| 	|d d d d | 	|d d d	 d
 d | 	|d d d	 d d d S )Nze[{"type": "image_with_alt", "value": {"image": 1, "alt_text": "Some alt text", "decorative": false}}]r  r  r/  r   r   rN   image_with_altr1  r   rb   alt_textzSome alt textr6  r2  r   r   r   test_image_block;  s    z.TestPageDetailWithStreamField.test_image_blockN)
r"   r#   r$   r  r  r.  r4  r7  r9  r<  r   r   r   r   r,    s    r,  varnishz3wagtail.contrib.frontend_cache.backends.HTTPBackendzhttp://localhost:8000)BACKENDLOCATIONzhttp://api.example.com)WAGTAILFRONTENDCACHEWAGTAILAPI_BASE_URLz>wagtail.contrib.frontend_cache.backends.http.HTTPBackend.purgec                       sV   e Zd ZdgZe fddZe fddZdd Zdd	 Zd
d Z	dd Z
  ZS )TestPageCacheInvalidationr'   c                       t    t  d S N)r  
setUpClassr   register_signal_handlersclsr  r   r   rE  V     
z$TestPageCacheInvalidation.setUpClassc                    rC  rD  )r  tearDownClassr   unregister_signal_handlersrG  r  r   r   rJ  [  rI  z'TestPageCacheInvalidation.tearDownClassc                 C   sR   | j dd tjjddj   W d    n1 sw   Y  |d d S NTexecuter  r4   z(http://api.example.com/api/main/pages/2/)captureOnCommitCallbacksr   r   r   r  save_revisionr   assert_any_callr.   purger   r   r   test_republish_page_purges`  s   z4TestPageCacheInvalidation.test_republish_page_purgesc                 C   L   | j dd tjjdd  W d    n1 sw   Y  |d d S rL  )rO  r   r   r   rd   rQ  rR  r   r   r   test_unpublish_page_purgesf     z4TestPageCacheInvalidation.test_unpublish_page_purgesc                 C   rU  )NTrM  ra   r4   z)http://api.example.com/api/main/pages/16/)rO  r   r   r   r  rQ  rR  r   r   r   test_delete_page_purgesl  rW  z1TestPageCacheInvalidation.test_delete_page_purgesc                 C   sL   | j dd tjjddj  W d    n1 sw   Y  |  d S )NTrM  r  r4   )rO  r   r   r   r  rP  assert_not_calledrR  r   r   r   test_save_draft_doesnt_purger  s   z6TestPageCacheInvalidation.test_save_draft_doesnt_purge)r"   r#   r$   r  classmethodrE  rJ  rT  rV  rX  rZ  r  r   r   r  r   rB  I  s    rB  c                   @   s   e Zd ZejZdd ZdS )TestPageViewSetSubclassingc                 C   s   |  |  jtj d S rD  )rR   get_querysetr   r   rc   rE   r   r   r   test_get_queryset|  s   z,TestPageViewSetSubclassing.test_get_querysetN)r"   r#   r$   r   rc   r   r^  r   r   r   r   r\  y  s    r\  )/r   rT   ior   unittestr   django.contrib.auth.modelsr   "django.contrib.contenttypes.modelsr   django.corer   django.testr   r   django.test.utilsr	   django.urlsr
   rest_framework.testr   wagtail.api.v2r   wagtail.api.v2.viewsr   wagtail.modelsr   r   r    wagtail.models.view_restrictionsr   wagtail.test.demositer   wagtail.test.testapp.modelsr   wagtail.test.utilsr   r    r!   r&   r  r  r  r,  patchrB  r\  r   r   r   r   <module>   s`            = -   =CE	&