U
    |hF                     @   s   d dl mZmZmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ G dd deeeZG d	d
 d
eZdS )    )AnonymousUserGroup
Permission)TestCase)GroupPagePermissionPageget_default_page_content_type)PagePermissionPolicy)WagtailTestUtils)PermissionPolicyTestUtilsc                   @   s   e Zd Zdd ZdS )PermissionPolicyTestCasec                 C   s  t  }tjjdd| _| jjtdddd| _tjjdd}t	jj|| jt
jj|d	d
d| _tjjdd}t	jj|| jt
jj|d	d
d| _tjjdd}t	jj|| jt
jj|dd
d| _| ddd| _| ddd| _d| j_| j  | ddd| _| jj| | ddd| _| jj| d| j_| j  | ddd| _| jj| | ddd| _| jj| | ddd| _t | _| jjtdd | jd!d| _| jjtd"d#| jd!d| _| jjtd$d%| jd!d| _| jjtd&d'| jd!d| _ | jjtd(d)dd| _!d S )*N   )idZReportsZreports)titleslug)instancezRoot editors)nameZchange_page)content_typecodename)grouppageZ
permissionzReport editorszReport addersZadd_page	superuserzsuperuser@example.compasswordZinactivesuperuserzinactivesuperuser@example.comFZ
rooteditorzrooteditor@example.comZinactiverooteditorzinactiverooteditor@example.comZreporteditorzreporteditor@example.comZreportadderzreportadder@example.comZuselessuserzuselessuser@example.comzreporteditor's pagezreporteditor-page)r   r   ownerzreporteditor's reportzreporteditor-reportzreportadder's reportzreportadder-reportzuselessuser's reportzuselessuser-reportzanonymous reportzanonymous-report)"r   r   objectsget	root_pageZ	add_childreports_pager   creater   r   root_edit_permreport_edit_permreport_add_permZcreate_superuserr   inactive_superuserZ	is_activesaveZcreate_userroot_editorgroupsaddinactive_root_editorreport_editorreport_adderuseless_userr   anonymous_usereditor_pageeditor_reportadder_reportuseless_reportanonymous_report)selfZ	page_typeZroot_editors_groupZreport_editors_groupZreport_adders_group r2   s/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/tests/test_page_permission_policies.pysetUp   s       	    
    
      				zPermissionPolicyTestCase.setUpN)__name__
__module____qualname__r4   r2   r2   r2   r3   r   
   s   r   c                       s|   e Zd Z f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d Zdd Z  ZS )TestPagePermissionPolicyc                    s   t    t | _d S N)superr4   r	   policyr1   	__class__r2   r3   r4      s    
zTestPagePermissionPolicy.setUpc                 C   s   |  | j| ji  |  | j| ji  |  | j| ji  |  | j| ji  |  | j| ji  |  | j| j| j	h |  | j| j
| jh |  | j| j| jh d S r9   )assertResultSetEqualr;   Zget_cached_permissions_for_userr   r"   r'   r*   r+   r$   r   r(   r    r)   r!   r<   r2   r2   r3   "_test_get_all_permissions_for_user   s@    z;TestPagePermissionPolicy._test_get_all_permissions_for_userc              	   C   s*   |    | d |    W 5 Q R X d S )Nr   )r@   ZassertNumQueriesr<   r2   r2   r3   $test_get_cached_permissions_for_user   s    z=TestPagePermissionPolicy.test_get_cached_permissions_for_userc                 C   s   |  | jddddf| jddddf| jddddf| jddddf| jddddf| jddddf| jddddf| jddddfgddddg d S )NTFr&   changedelete
frobnicate)	ZassertUserPermissionMatrixr   r"   r$   r'   r(   r)   r*   r+   r<   r2   r2   r3   test_user_has_permission   s    

z1TestPagePermissionPolicy.test_user_has_permissionc                 C   s   |  | j| jddg | | j| jddg |  | j| jddg |  | j| jddg | | j| jddg |  | j| jdg d S )Nr&   rB   )	
assertTruer;   Zuser_has_any_permissionr   assertFalser"   r(   r)   r+   r<   r2   r2   r3   test_user_has_any_permission   s*     z5TestPagePermissionPolicy.test_user_has_any_permissionc                 C   s   | j ddg}| || j| j| j| jg | j ddg}| || j| jg | j ddg}| || j| j| j| jg d S )Nr&   rB   rD   )r;   Zusers_with_any_permissionr?   r   r$   r(   r)   )r1   Z#users_with_add_or_change_permissionZ'users_with_add_or_frobnicate_permissionZ(users_with_edit_or_frobnicate_permissionr2   r2   r3   test_users_with_any_permission   s<    
	z7TestPagePermissionPolicy.test_users_with_any_permissionc                 C   sH   | j d}| || j| j| j| jg | j d}| || jg d S )NrB   rD   )r;   Zusers_with_permissionr?   r   r$   r(   r)   )r1   Zusers_with_change_permissionZusers_with_custom_permissionr2   r2   r3   test_users_with_permission  s    
z3TestPagePermissionPolicy.test_users_with_permissionc                 C   s   |  | j| jdddf| jdddf| jdddf| jdddf| jdddf| jdddf| jdddf| j	dddfgdddg |  | j
| jdddf| jdddf| jdddf| jdddf| jdddf| jdddf| jdddf| j	dddfgdddg d S )NTFrB   rC   rD   )Z"assertUserInstancePermissionMatrixr,   r   r"   r$   r'   r(   r)   r*   r+   r/   r<   r2   r2   r3   %test_user_has_permission_for_instance  s4    

z>TestPagePermissionPolicy.test_user_has_permission_for_instancec                 C   s|   |  | j| jddg| j | | j| jddg| j |  | j| jddg| j | | j| j	ddg| j d S NrB   rC   )
rF   r;   Z$user_has_any_permission_for_instancer(   r/   rG   r,   r)   r.   r+   r<   r2   r2   r3   )test_user_has_any_permission_for_instance=  s8            zBTestPagePermissionPolicy.test_user_has_any_permission_for_instancec              
   C   s   |  | j| jdtj  |  | j| jdg  |  | j| jd| j	| j
| j| j| j| j| jg |  | j| jd| j
| j| j| j| jg |  | j| jdg  |  | j| jdg  d S NrB   )r?   r;   Z!instances_user_has_permission_forr   r   r   allr"   r$   r   r   r,   r-   r.   r/   r0   r(   r*   r+   r<   r2   r2   r3   &test_instances_user_has_permission_forV  sl    z?TestPagePermissionPolicy.test_instances_user_has_permission_forc              
   C   s  |  | j| jddgtj  |  | j| jddgg  |  | j| jddg| j	| j
| j| j| j| j| jg |  | j| jddg| j
| j| j| j| jg |  | j| jddg| jg |  | j| jddgg  |  | j| jddgg  d S rL   )r?   r;   Z%instances_user_has_any_permission_forr   r   r   rO   r"   r$   r   r   r,   r-   r.   r/   r0   r(   r)   r*   r+   r<   r2   r2   r3   *test_instances_user_has_any_permission_for  sz           zCTestPagePermissionPolicy.test_instances_user_has_any_permission_forc                 C   s   |  | jd| j| j| jg |  | jd| j| j| j| j| jg |  | jd| j	| j| j| jg |  | jd| j
| j| j| jg |  | jd| j| j| j| jg d S rN   )r?   r;   Z"users_with_permission_for_instancer,   r   r$   r.   r(   r)   r-   r/   r0   r<   r2   r2   r3   'test_users_with_permission_for_instance  s:    
   z@TestPagePermissionPolicy.test_users_with_permission_for_instancec                 C   s   |  | jddg| j| j| jg |  | jddg| j| j| j| j| jg |  | jddg| j	| j| j| jg |  | jddg| j	| jg d S )NrB   rC   rD   )
r?   r;   Z&users_with_any_permission_for_instancer,   r   r$   r.   r(   r)   r/   r<   r2   r2   r3   +test_users_with_any_permission_for_instance  s8     
   zDTestPagePermissionPolicy.test_users_with_any_permission_for_instance)r5   r6   r7   r4   r@   rA   rE   rH   rI   rJ   rK   rM   rP   rQ   rR   rS   __classcell__r2   r2   r=   r3   r8      s   ")#?@r8   N)Zdjango.contrib.auth.modelsr   r   r   Zdjango.testr   Zwagtail.modelsr   r   r   Z!wagtail.permission_policies.pagesr	   Zwagtail.test.utilsr
   Z&wagtail.tests.test_permission_policiesr   r   r8   r2   r2   r2   r3   <module>   s    