o
    h%                     @   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/url_path)pagez /home/secret-event-editor-plans/zEvent editors)namez/home/secret-login-plans/)
r   objectsgetsecret_plans_pager   view_restrictionsecret_event_editor_plans_pager   event_editors_groupsecret_login_plans_page)self r   _/var/www/html/ndineBlogger/venv/lib/python3.10/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 | j 	|ddd
}| 
|d W d    d S 1 sw   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password
return_url	swordfishztests/simple_page.html/)LOGIN_REDIRECT_URLzhttps://invaliddomain.com)clientr   assertEqual	templatesr   r   idr   assertContainspostassertRedirectslogoutsettings)r   response
submit_urlr   r   r   %test_anonymous_user_must_authenticate   sV   
"z5TestPagePrivacy.test_anonymous_user_must_authenticate(tests/custom_page_password_required.html)"WAGTAIL_PASSWORD_REQUIRED_TEMPLATEc                 C   s8   | j d}| d|jd j | d|jd j d S )Nr   r   r   r2   )r&   r   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/   r0   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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   create_aliasr&   r'   r(   r   r   r)   r*   )r   r   secret_plans_alias_pager/   r0   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
   r<   r=   r7   )parentz%/alias-secret-plans/steal-underpants/r   r8   r   r9   r   zj<input id="id_return_url" name="return_url" type="hidden" value="/alias-secret-plans/steal-underpants/" />Tr   r?   )r   r   rA   r:   underpants_alias_pager/   r0   r   r   r   3test_view_restrictions_apply_to_subpages_of_aliases   s2   
zCTestPagePrivacy.test_view_restrictions_apply_to_subpages_of_aliasesc                 C      | j d}| |d d S )N/secret-event-editor-plans/./_util/login/?next=/secret-event-editor-plans/r&   r   r,   r5   r   r   r   *test_group_restriction_with_anonymous_user      z:TestPagePrivacy.test_group_restriction_with_anonymous_userc                 C   s*   | j ddd | jd}| |d d S )Neventmoderatorr!   usernamer!   rG   rH   )loginr&   r   r,   r5   r   r   r   ,test_group_restriction_with_unpermitted_user   s   z<TestPagePrivacy.test_group_restriction_with_unpermitted_userc                 C   8   | j ddd | jd}| |jd | |d d S )Neventeditorr!   rM   rG      (<title>Secret event editor plans</title>rO   r&   r   r'   status_coder*   r5   r   r   r   *test_group_restriction_with_permitted_user      z:TestPagePrivacy.test_group_restriction_with_permitted_userc                 C   rQ   )N	superuserr!   rM   rG   rS   rT   rU   r5   r   r   r   %test_group_restriction_with_superuser   rX   z5TestPagePrivacy.test_group_restriction_with_superuserc                 C   rF   )N/secret-login-plans/z'/_util/login/?next=/secret-login-plans/rI   r5   r   r   r   *test_login_restriction_with_anonymous_user   rK   z:TestPagePrivacy.test_login_restriction_with_anonymous_userc                 C   rQ   )NrL   r!   rM   r[   rS   z!<title>Secret login plans</title>rU   r5   r   r   r   *test_login_restriction_with_logged_in_user   rX   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   assertInr5   r   r   r   $test_password_protected_page_headers   s   z4TestPagePrivacy.test_password_protected_page_headersN)__name__
__module____qualname__fixturesr   r1   r   r6   r;   rB   rE   rJ   rP   rW   rZ   r\   r]   r_   r   r   r   r   r      s$    9
2 r   N)django.contrib.auth.modelsr   django.testr   r   wagtail.modelsr   r   wagtail.test.utilsr   r   r   r   r   r   <module>   s
    