a
    Dg-                     @   sF   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eZdS )    )get_user_model)TestCase)PagePermissionPolicy)WagtailTestUtilsc                   @   sF   e Zd ZdZdgZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dS )TestExplorablePagesaU  
    Test the way that the explorer nav menu behaves for users with different permissions.

    This is isolated in its own test case because it requires a custom page tree and custom set of
    users and groups.
    The fixture sets up this page tree:
    ========================================================
    ID Site          Path
    ========================================================
    1              /
    2  testserver  /home/
    3  testserver  /home/about-us/
    4  example.com /home/
    5  example.com /home/content/
    6  example.com /home/content/page-1/
    7  example.com /home/content/page-2/
    9  example.com /home/content/page-2/child-1
    8  example.com /home/other-content/
    10 example.com /home-2/
    ========================================================
    Group 1 has explore and choose permissions rooted at testserver's homepage.
    Group 2 has explore and choose permissions rooted at example.com's page-1.
    Group 3 has explore and choose permissions rooted at example.com's other-content.
    User "jane" is in Group 1.
    User "bob" is in Group 2.
    User "sam" is in Groups 1 and 2.
    User "josh" is in Groups 2 and 3.
    User "mary" is is no Groups, but she has the "access wagtail admin" permission.
    User "superman" is an admin.

    Note that the Explorer Nav does not display leaf nodes.
    ztest_explorable_pages.jsonc                 C   s.   t  }|jjdd}| t |jd d S )Nzsuperman@example.comemail   r   objectsgetassertEqualr   explorable_root_instanceidselfUseruser r   b/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/admin/tests/test_navigation.pytest_admins_see_all_pages,   s    z-TestExplorablePages.test_admins_see_all_pagesc                 C   s.   t  }|jjdd}| t |jd d S )Nzjane@example.comr      r
   r   r   r   r   5test_nav_root_for_nonadmin_is_closest_common_ancestor2   s    zITestExplorablePages.test_nav_root_for_nonadmin_is_closest_common_ancestorc                 C   s.   t  }|jjdd}| t |jd d S )Nzbob@example.comr      r
   r   r   r   r   *test_nonadmin_sees_leaf_page_at_root_level8   s    z>TestExplorablePages.test_nonadmin_sees_leaf_page_at_root_levelc                 C   sR   t  }|jjdd}| t |jd t |D ]}| |jddg q6d S )Nzjosh@example.comr      r      	r   r   r   r   r   r   r   Z(instances_with_direct_explore_permissionZassertInr   r   r   pager   r   r   6test_nonadmin_sees_pages_below_closest_common_ancestor>   s    zJTestExplorablePages.test_nonadmin_sees_pages_below_closest_common_ancestorc                 C   sR   t  }|jjdd}| t |jd t |D ]}| |jddg q6d S )Nzsam@example.comr   r	   r   r   r   r   r   r   r   (test_nonadmin_sees_only_explorable_pagesK   s    z<TestExplorablePages.test_nonadmin_sees_only_explorable_pagesc                 C   s*   t  }|jjdd}| t | d S )Nzmary@example.comr   )r   r   r   ZassertIsNoner   r   r   r   r   r   /test_nonadmin_with_no_page_perms_cannot_exploreZ   s    zCTestExplorablePages.test_nonadmin_with_no_page_perms_cannot_exploreN)__name__
__module____qualname____doc__Zfixturesr   r   r   r    r!   r"   r   r   r   r   r      s   !r   N)	Zdjango.contrib.authr   Zdjango.testr   Z!wagtail.permission_policies.pagesr   Zwagtail.test.utilsr   r   r   r   r   r   <module>   s   