a
    Dg;                     @   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   a/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/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   Z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   sN   d| j _| j   | | j | | j  W d    n1 s@0    Y  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 d    n1 s00    Y  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   r0   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 )
Nr7   r8   r9   	subscribeT)r<   	post_datar'   z
p=1&q=test)r)   ZQUERYSTRINGr=   )r   Zmocked_postr<   r@   r   r   r   +test_is_renderable_with_query_and_post_dataD   s    
zDTestCustomPageAssertions.test_is_renderable_with_query_and_post_datac                 C   s^   d| j _| j   | | j | | j  W d    n1 s@0    Y  | 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   sP   |  | j | | jd W d    n1 s00    Y  | j| jddd d S )Nr%   TrB   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   sl   ddg}|D ]>}|  | j | | j| W d    q1 s@0    Y  q|D ]}| j| j|dd qPd S )Nzpermanant-homepage-redirect/ztemporary-homepage-redirect/T)Zaccept_redirectrD   )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y$   Y n0 || jtjd  z| j | j| jd W n | jyd   Y n0 || jtjd  d S )Nr   r3   )rH   r   r#   Zassert_called_withZ_pageiseditable_superuserr   r5   r	   )r   r/   r   r   r   %test_is_editable_always_authenticatest   s    z>TestCustomPageAssertions.test_is_editable_always_authenticatesc                 C   sZ   |  d}| | j  | j| j|d W d    n1 s<0    Y  |  |  d S )NZbobr3   )Zcreate_userr"   r#   rH   r   r,   )r   r/   r0   r4   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r@   rG   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 )Nr8   r   rM   rO   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 )Nr3   )rP   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moderO   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 d    n1 s20    Y  d S )NbrokenrU   )r"   r#   rP   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   patchr1   r2   r6   r>   rA   rC   rE   rF   rI   rJ   rK   rN   rQ   rR   rS   rW   rY   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
   