U
    |h;                     @   sP   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	 G dd de	Z
dS )	    )mock)settings)Page)RoutablePageTest)WagtailPageTestCasec                   @   s6  e Zd Zedd Zdd Zdd Zdd Zd	d
 Zdd Z	e
de
ddd Ze
de
ddd Ze
de
ddd Ze
ddd Ze
ddd Zdd Zdd Zdd Zd d! Ze
dd"d# Ze
de
dd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2S )3TestCustomPageAssertionsc                 C   s   |  d| _d S )Nsuper)Zcreate_superuser	superuser)cls r   j/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/tests/test_page_assertions.pysetUpTestData   s    z&TestCustomPageAssertions.setUpTestDatac                 C   s2   t jjdd| _tddd| _| jj| jd d S )N   )idzHello world!zhello-worldtitleslug)instance)r   objectsgetparentr   pageZ	add_childselfr   r   r   setUp   s    zTestCustomPageAssertions.setUpc                 C   s   |  | j d S NassertPageIsRoutabler   r   r   r   r   test_is_routable   s    z)TestCustomPageAssertions.test_is_routablec                 C   s   |  | jd d S )Narchive/year/1984/r   r   r   r   r   'test_is_routable_with_alternative_route   s    z@TestCustomPageAssertions.test_is_routable_with_alternative_routec              	   C   s:   d| j _| j   | | j | | j  W 5 Q R X d S )NF)r   livesaveassertRaisesfailureExceptionr   r   r   r   r   %test_is_routable_fails_for_draft_page   s    
z>TestCustomPageAssertions.test_is_routable_fails_for_draft_pagec              	   C   s*   |  | j | | jd W 5 Q R X d S )Ninvalid-route-path/)r#   r$   r   r   r   r   r   r   -test_is_routable_fails_for_invalid_route_path#   s    zFTestCustomPageAssertions.test_is_routable_fails_for_invalid_route_pathz django.test.testcases.Client.getz(django.test.testcases.Client.force_loginc                 C   s&   |  | j |  |jdd d d S )N/hello-world/dataassertPageIsRenderabler   assert_not_calledassert_called_once_withr   mocked_force_login
mocked_getr   r   r   test_is_renderable'   s    z+TestCustomPageAssertions.test_is_renderablec                 C   s(   |  | jd |  |jdd d d S )Nr   z/hello-world/archive/year/1984/r)   r+   r/   r   r   r   (test_is_renderable_for_alternative_route.   s    zATestCustomPageAssertions.test_is_renderable_for_alternative_routec                 C   s8   | j | j| jd || jtjd  |jdd d d S )Nuserr   r(   r)   )r,   r   r	   r.   r   AUTHENTICATION_BACKENDSr/   r   r   r   test_is_renderable_for_user5   s     z4TestCustomPageAssertions.test_is_renderable_for_userc                 C   s,   ddd}| j | j|d |jd|d d S )N   testpq)
query_datar(   r)   r,   r   r.   )r   r1   r=   r   r   r   "test_is_renderable_with_query_data>   s    
z;TestCustomPageAssertions.test_is_renderable_with_query_dataz!django.test.testcases.Client.postc                 C   s8   ddd}ddi}| j | j||d |jd|dd	 d S )
Nr8   r9   r:   	subscribeT)r=   	post_datar(   z
p=1&q=test)r*   ZQUERYSTRINGr>   )r   Zmocked_postr=   rA   r   r   r   +test_is_renderable_with_query_and_post_dataD   s    
    zDTestCustomPageAssertions.test_is_renderable_with_query_and_post_datac              	   C   sJ   d| j _| j   | | j | | j  W 5 Q R X | j| j dd d S )NFTZ
accept_404)r   r!   r"   r#   r$   r,   r   r   r   r   !test_is_renderable_for_draft_pageO   s
    
z:TestCustomPageAssertions.test_is_renderable_for_draft_pagec              	   C   s<   |  | j | | jd W 5 Q R X | j| jddd d S )Nr&   TrC   r#   r$   r,   r   r   r   r   r   )test_is_renderable_for_invalid_route_pathZ   s    zBTestCustomPageAssertions.test_is_renderable_for_invalid_route_pathc              
   C   sX   ddg}|D ]*}|  | j | | j| W 5 Q R X q|D ]}| j| j|dd q<d S )Nzpermanant-homepage-redirect/ztemporary-homepage-redirect/T)Zaccept_redirectrE   )r   Zredirect_route_pathsZ
route_pathr   r   r   #test_is_rendereable_accept_redirectb   s    z<TestCustomPageAssertions.test_is_rendereable_accept_redirectc                 C   s   |  | j d S r   assertPageIsEditabler   r   r   r   r   test_is_editableq   s    z)TestCustomPageAssertions.test_is_editablec                 C   s   z|  | j W n | jk
r&   Y nX || jtjd  z| j | j| jd W n | jk
rh   Y nX || jtjd  d S )Nr   r4   )rI   r   r$   Zassert_called_withZ_pageiseditable_superuserr   r6   r	   )r   r0   r   r   r   %test_is_editable_always_authenticatest   s       z>TestCustomPageAssertions.test_is_editable_always_authenticatesc              	   C   sF   |  d}| | j | j| j|d W 5 Q R X |  |  d S )NZbobr4   )Zcreate_userr#   r$   rI   r   r-   )r   r0   r1   r5   r   r   r   -test_is_editable_with_permission_lacking_user   s
    
zFTestCustomPageAssertions.test_is_editable_with_permission_lacking_userc                 C   s   | j | jddddd d S )NzGoodbye world?zgoodbye-worldZgoodbye)r   r   contentrA   rH   r   r   r   r   test_is_editable_with_post_data   s    z8TestCustomPageAssertions.test_is_editable_with_post_datac                 C   s   |  | j d S r   assertPageIsPreviewabler   r   r   r   r   test_is_previewable   s    z,TestCustomPageAssertions.test_is_previewablec                 C   s   | j | jdddd d S )Nr9   r   rN   rP   r   r   r   r   "test_is_previewable_with_post_data   s     z;TestCustomPageAssertions.test_is_previewable_with_post_datac                 C   s   | j | j| jd d S )Nr4   )rQ   r   r	   r   r   r   r   $test_is_previewable_with_custom_user   s    z=TestCustomPageAssertions.test_is_previewable_with_custom_userc                 C   s   | j | jdd d S )NextramoderP   r   r   r   r   (test_is_previewable_for_alternative_mode   s    zATestCustomPageAssertions.test_is_previewable_for_alternative_modec              	   C   s,   |  | j | j| jdd W 5 Q R X d S )NbrokenrV   )r#   r$   rQ   r   r   r   r   r   #test_is_previewable_for_broken_mode   s    z<TestCustomPageAssertions.test_is_previewable_for_broken_modeN)__name__
__module____qualname__classmethodr   r   r   r    r%   r'   r   patchr2   r3   r7   r?   rB   rD   rF   rG   rJ   rK   rL   rO   rR   rS   rT   rX   rZ   r   r   r   r   r   
   sF   




	
r   N)Zunittestr   Zdjango.confr   Zwagtail.modelsr   Z wagtail.test.routablepage.modelsr   Zwagtail.test.utilsr   r   r   r   r   r   <module>   s
   