a
    Dg%                     @   sN   d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	 G dd de	eZ
dS )    )Group)TestCaseoverride_settings)PagePageViewRestriction)WagtailTestUtilsc                   @   s   e Zd Zdg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S )TestPagePrivacyz	test.jsonc                 C   sV   t jjdd| _tjj| jd| _t jjdd| _tjjdd| _t jjdd| _	d S )N/home/secret-plans/Zurl_path)pagez /home/secret-event-editor-plans/zEvent editors)namez/home/secret-login-plans/)
r   objectsgetsecret_plans_pager   view_restrictionZsecret_event_editor_plans_pager   Zevent_editors_groupZsecret_login_plans_page)self r   ^/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/tests/test_page_privacy.pysetUp   s    zTestPagePrivacy.setUpc                 C   s(  | j d}| |jd jd d| jj| jjf }| |d|  | j|ddd | j 	|d	dd
}| |jd jd | |d|  | j 	|ddd
}| 
|d | j d}| |jd jd | j   | jdd0 | j 	|ddd
}| 
|d W d    n1 s0    Y  d S )N/secret-plans/r   "wagtailcore/password_required.html(/_util/authenticate_with_password/%d/%d/<form action="%s"zS<input id="id_return_url" name="return_url" type="hidden" value="/secret-plans/" />ThtmlwrongpasswordpasswordZ
return_url	swordfishztests/simple_page.html/)ZLOGIN_REDIRECT_URLzhttps://invaliddomain.com)clientr   assertEqual	templatesr   r   idr   assertContainspostassertRedirectsZlogoutsettings)r   response
submit_urlr   r   r   %test_anonymous_user_must_authenticate   sT    
z5TestPagePrivacy.test_anonymous_user_must_authenticate(tests/custom_page_password_required.html)Z"WAGTAIL_PASSWORD_REQUIRED_TEMPLATEc                 C   s8   | j d}| d|jd j | d|jd j d S )Nr   r   r   r+   )r    r   ZassertNotEqualr"   r   r!   r   r(   r   r   r   Ltest_anonymous_user_must_authenticate_with_custom_password_required_templateR   s    

z\TestPagePrivacy.test_anonymous_user_must_authenticate_with_custom_password_required_templatec                 C   s   t jjdd}| jd}| |jd jd d| jj|jf }| 	|d | 	|d|  | j	|d	d
d | j
|ddd}| |jd jd | 	|d|  | j
|ddd}| |d | jd}| |jd jd d S )N$/home/secret-plans/steal-underpants/r
   z/secret-plans/steal-underpants/r   'tests/event_page_password_required.htmlr   <title>Steal underpants</title>r   zd<input id="id_return_url" name="return_url" type="hidden" value="/secret-plans/steal-underpants/" />Tr   r   r   r   ztests/event_page.html)r   r   r   r    r!   r"   r   r   r#   r$   r%   r&   )r   underpants_pager(   r)   r   r   r   (test_view_restrictions_apply_to_subpagesc   sJ    z8TestPagePrivacy.test_view_restrictions_apply_to_subpagesc                 C   sp   t jjdd}|jdd}| jd}| |jd jd d| jj	|j	f }| 
|d	|  | j
|d
dd d S )Nr	   r
   alias-secret-plansZupdate_slugz/alias-secret-plans/r   r   r   r   zY<input id="id_return_url" name="return_url" type="hidden" value="/alias-secret-plans/" />Tr   r   r   r   Zcreate_aliasr    r!   r"   r   r   r#   r$   )r   r   secret_plans_alias_pager(   r)   r   r   r   'test_view_restrictions_apply_to_aliases   s$    z7TestPagePrivacy.test_view_restrictions_apply_to_aliasesc                 C   s   t jjdd}|jdd}t jjdd}|j|d}| jd}| |jd jd	 d
| jj	|j	f }| 
|d | 
|d|  | j
|ddd d S )Nr	   r
   r3   r4   r.   )parentz%/alias-secret-plans/steal-underpants/r   r/   r   r0   r   zj<input id="id_return_url" name="return_url" type="hidden" value="/alias-secret-plans/steal-underpants/" />Tr   r5   )r   r   r6   r1   Zunderpants_alias_pager(   r)   r   r   r   3test_view_restrictions_apply_to_subpages_of_aliases   s2    zCTestPagePrivacy.test_view_restrictions_apply_to_subpages_of_aliasesc                 C   s   | j d}| |d d S )N/secret-event-editor-plans/./_util/login/?next=/secret-event-editor-plans/r    r   r&   r,   r   r   r   *test_group_restriction_with_anonymous_user   s    z:TestPagePrivacy.test_group_restriction_with_anonymous_userc                 C   s*   | j ddd | jd}| |d d S )Neventmoderatorr   usernamer   r:   r;   )loginr    r   r&   r,   r   r   r   ,test_group_restriction_with_unpermitted_user   s    z<TestPagePrivacy.test_group_restriction_with_unpermitted_userc                 C   s8   | j ddd | jd}| |jd | |d d S )NZeventeditorr   r?   r:      (<title>Secret event editor plans</title>rA   r    r   r!   status_coder$   r,   r   r   r   *test_group_restriction_with_permitted_user   s    z:TestPagePrivacy.test_group_restriction_with_permitted_userc                 C   s8   | j ddd | jd}| |jd | |d d S )NZ	superuserr   r?   r:   rC   rD   rE   r,   r   r   r   %test_group_restriction_with_superuser   s    z5TestPagePrivacy.test_group_restriction_with_superuserc                 C   s   | j d}| |d d S )N/secret-login-plans/z'/_util/login/?next=/secret-login-plans/r<   r,   r   r   r   *test_login_restriction_with_anonymous_user   s    z:TestPagePrivacy.test_login_restriction_with_anonymous_userc                 C   s8   | j ddd | jd}| |jd | |d d S )Nr>   r   r?   rI   rC   z!<title>Secret login plans</title>rE   r,   r   r   r   *test_login_restriction_with_logged_in_user   s    z:TestPagePrivacy.test_login_restriction_with_logged_in_userc                 C   sd   | j d}| |jd jd | d|d  | d|d  | d|d  | d|d  d S )	Nr   r   r   zno-cachezCache-Controlzno-storezmust-revalidatez	max-age=0)r    r   r!   r"   r   ZassertInr,   r   r   r   $test_password_protected_page_headers   s    z4TestPagePrivacy.test_password_protected_page_headersN)__name__
__module____qualname__Zfixturesr   r*   r   r-   r2   r7   r9   r=   rB   rG   rH   rJ   rK   rL   r   r   r   r   r      s"   9
2 r   N)Zdjango.contrib.auth.modelsr   Zdjango.testr   r   Zwagtail.modelsr   r   Zwagtail.test.utilsr   r   r   r   r   r   <module>   s   