o
    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)create_superuser	superuser)cls r   b/var/www/html/ndineBlogger/venv/lib/python3.10/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   page	add_childselfr   r   r   setUp   s   zTestCustomPageAssertions.setUpc                 C      |  | j d S NassertPageIsRoutabler   r   r   r   r   test_is_routable      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   sP   d| j _| j   | | j | | j  W d    d S 1 s!w   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    d S 1 sw   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/   r3   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-   )r0   r   r
   r2   r   AUTHENTICATION_BACKENDSr3   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-   r0   r   r2   )r   r5   rA   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 )
Nr<   r=   r>   	subscribeT)rA   	post_datar,   z
p=1&q=test)r.   QUERYSTRINGrB   )r   mocked_postrA   rE   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 w   Y  | j| j dd d S )NFT
accept_404)r   r%   r&   r'   r(   r0   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 sw   Y  | j| jddd d S )Nr*   TrI   r'   r(   r0   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    n1 s w   Y  q|D ]}| j| j|dd q(d S )Nzpermanant-homepage-redirect/ztemporary-homepage-redirect/T)accept_redirectrL   )r   redirect_route_paths
route_pathr   r   r   #test_is_rendereable_accept_redirectb   s   z<TestCustomPageAssertions.test_is_rendereable_accept_redirectc                 C   r   r   assertPageIsEditabler   r   r   r   r   test_is_editableq   r"   z)TestCustomPageAssertions.test_is_editablec                 C   s~   z|  | j W n
 | jy   Y nw || jtjd  z| j | j| jd W n
 | jy2   Y nw || jtjd  d S )Nr   r8   )rS   r   r(   assert_called_with_pageiseditable_superuserr   r:   r
   )r   r4   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w   Y  |  |  d S )Nbobr8   )create_userr'   r(   rS   r   r1   )r   r4   r5   r9   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-worldgoodbye)r   r   contentrE   rR   r   r   r   r   test_is_editable_with_post_data   s   
z8TestCustomPageAssertions.test_is_editable_with_post_datac                 C   r   r   assertPageIsPreviewabler   r   r   r   r   test_is_previewable   r"   z,TestCustomPageAssertions.test_is_previewablec                 C   s   | j | jdddd d S )Nr=   r   r]   r_   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 )Nr8   )r`   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moder_   r   r   r   r   (test_is_previewable_for_alternative_mode   s   zATestCustomPageAssertions.test_is_previewable_for_alternative_modec                 C   sB   |  | j | j| jdd W d    d S 1 sw   Y  d S )Nbrokenre   )r'   r(   r`   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   patchr6   r7   r;   rC   rH   rK   rM   rQ   rT   rW   rZ   r^   ra   rb   rc   rg   ri   r   r   r   r   r   
   sH    




	
r   N)unittestr   django.confr   wagtail.modelsr    wagtail.test.routablepage.modelsr   wagtail.test.utilsr   r   r   r   r   r   <module>   s    