o
    h                    @   s  d dl Z d dl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 d dlmZ d d	lmZmZ d d
lmZmZmZmZ d dlmZ G dd deeZG dd deeZG dd deeZG dd deeZG dd deeZ G dd deeZ!e	ddG dd de!Z"e	ddG dd de!Z#e	dd d!G d"d# d#e#Z$e	dd$d!G d%d& d&e#Z%G d'd( d(eeZ&G d)d* d*eeZ'G d+d, d,eeZ(G d-d. d.eeZ)e	dd/G d0d1 d1eeZ*dS )2    N)parse_qsurlsplit)get_user_model)TestCaseTransactionTestCaseoverride_settingsreverse)escape)	urlencode)can_choose_page)LocalePage)
EventIndex	EventPage
SimplePageSingleEventPage)WagtailTestUtilsc                   @   sT   e Zd Zdd Zi fddZdd Zdd Zed	d
dd Zedd
dd Z	dS )TestChooserBrowsec                 C   :   t jjdd| _tddd| _| jj| jd |   d S N   id	foobarbazhellotitlecontentinstancer   objectsget	root_pager   
child_page	add_childloginself r*   e/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/admin/tests/test_page_chooser.pysetUp      zTestChooserBrowse.setUpc                 C      | j td|S Nwagtailadmin_choose_pageclientr#   r	   r)   paramsr*   r*   r+   r#         zTestChooserBrowse.getc                 C   &   |   }| |jd | |d d S N    wagtailadmin/chooser/browse.htmlr#   assertEqualstatus_codeassertTemplateUsedr)   responser*   r*   r+   test_simple"      zTestChooserBrowse.test_simplec                    s   t ddd t j d t ddd}t j|d  fdd}| d| |  }W d    n1 s7w   Y  | t|jd	 j	d
 | |jd	 j	d j
  d S )N
Test shownr   r   r   Test not shownc                       | j  jdS Nr   filterr   pagesrequestpager*   r+   filter_pages.      zDTestChooserBrowse.test_construct_queryset_hook.<locals>.filter_pagesconstruct_page_chooser_querysettabler      )r   r   get_first_root_noder&   register_hookr#   r;   lencontextdataspecificr)   page_not_shownrM   r?   r*   rK   r+   test_construct_queryset_hook'   s   
z.TestChooserBrowse.test_construct_queryset_hookT)USE_THOUSAND_SEPARATORc           	      C   s   t jjdd| _tdddd| _| jj| jd | dd	i}t| jj}|j	
 }t|}| |d
 d |d }| d| d| | |jd | |d | |}|jdddd }tt|j}| |d d	g d S )NrQ   r   test_child_pagetest contenti&'  r   r   pkr   multiple1stepbrowsehtmlzvalue=""r8   r9   formsearch)roleaction)r   r"   r#   rL   r   r%   r&   strr   r   decodejsonloadsr;   assertInr<   r=   get_soupfindr   r   query)	r)   r?   checkbox_valuedecoded_contentresponse_jsonresponse_htmlsoup
search_urlsearch_query_paramsr*   r*   r+   test_multiple_chooser_view7   s$   


z,TestChooserBrowse.test_multiple_chooser_viewFc                 C   s   t jjdd| _tdddd| _| jj| jd | dd	i}t| jj}|j	
 }| d
| d| | |jd | |d d S )NrQ   r   r\   r]   iB'  r^   r   r`   ra   zvalue=\"z\"r8   r9   )r   r"   r#   rL   r   r%   r&   rj   r   r   rk   rn   r;   r<   r=   )r)   r?   rr   rs   r*   r*   r+   5test_multiple_chooser_view_without_thousand_separatorR   s   
zGTestChooserBrowse.test_multiple_chooser_view_without_thousand_separatorN)
__name__
__module____qualname__r,   r#   r@   rZ   r   ry   rz   r*   r*   r*   r+   r      s    	
r   c                   @   s0   e Zd Zdd Zi fddZdd Zdd Zd	S )
TestCanChooseRootFlagc                 C      |    d S Nr'   r(   r*   r*   r+   r,   g      zTestCanChooseRootFlag.setUpc                 C   r.   r/   r1   r3   r*   r*   r+   r#   j   r5   zTestCanChooseRootFlag.getc                 C   s   |   }| |d d S )N/admin/pages/1/edit/)r#   assertNotContainsr>   r*   r*   r+   "test_cannot_choose_root_by_defaultm   s   z8TestCanChooseRootFlag.test_cannot_choose_root_by_defaultc                 C   s   |  ddi}| |d d S )Ncan_choose_roottruer   )r#   assertContainsr>   r*   r*   r+   test_can_choose_rootq   s   z*TestCanChooseRootFlag.test_can_choose_rootN)r{   r|   r}   r,   r#   r   r   r*   r*   r*   r+   r~   f   s
    r~   c                   @   s   e Zd Zdd Zi fddZi 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dd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+S ),TestChooserBrowseChildc                 C   r   r   r!   r(   r*   r*   r+   r,   w   r-   zTestChooserBrowseChild.setUpc                 C   s   | j td| jjfd|S Nwagtailadmin_choose_page_childargs)r2   r#   r	   r$   r   r3   r*   r*   r+   r#      s   zTestChooserBrowseChild.getc                 C   s   | j tddd|S )Nr   )i r   r1   r3   r*   r*   r+   get_invalid      z"TestChooserBrowseChild.get_invalidc                 C   r6   r7   r:   r>   r*   r*   r+   r@      rA   z"TestChooserBrowseChild.test_simplec                 C   s   |  |  jd d S )N  )r;   r   r<   r(   r*   r*   r+   test_get_invalid      z'TestChooserBrowseChild.test_get_invalidc                 C   s  t dddddd}| jj|d tdd	}| jj|d |jt d
dddddd | ddi}| |jd | |d | |jd d dd |jd j	D }| 
| jj| | || jj j | || jj j | |j| | 
|j| | ||j j | ||j j d S )Neventthe moonpublicfree
2001-01-01r   locationaudiencecost	date_fromr   eventsr   zother event	page_typetests.simplepager8   r9   page_type_stringc                 S      i | ]}|j |qS r*   r   .0rL   r*   r*   r+   
<dictcomp>       z>TestChooserBrowseChild.test_with_page_type.<locals>.<dictcomp>rP   )r   r$   r&   r   r#   r;   r<   r=   rU   rV   rn   r%   r   
assertTrue
can_chooseassertFalsecan_descendassertNotIn)r)   
event_pageevent_index_pager?   rI   r*   r*   r+   test_with_page_type   sB   z*TestChooserBrowseChild.test_with_page_typec                 C   sh   t dddddd}| jj|d |  }| |jd | |d	 d
d |jd jD }| 	d| d S )Nfoor   r   r   r   r   r   r8   r9   c                 S   s   g | ]}|j qS r*   )urlr   r*   r*   r+   
<listcomp>   s    zKTestChooserBrowseChild.test_with_url_extended_page_type.<locals>.<listcomp>rP   z/foo/pointless-suffix/)
r   r$   r&   r#   r;   r<   r=   rU   rV   rn   )r)   single_event_pager?   	page_urlsr*   r*   r+    test_with_url_extended_page_type   s   z7TestChooserBrowseChild.test_with_url_extended_page_typec                 C   ,   |  ddi}| |jd | |d d S )Nr    r8   r9   r:   r>   r*   r*   r+   test_with_blank_page_type   s   z0TestChooserBrowseChild.test_with_blank_page_typec                 C   s   t dddddd}| jj|d | dd	i}| |jd
 | |d | |jd d	 dd |jd jD }| 	| j
j| | || j
j j | 	|j| | || j
j j d S )Nr   r   r   r   r   r   r   r    tests.simplepage,tests.eventpager8   r9   r   c                 S   r   r*   r   r   r*   r*   r+   r      r   zHTestChooserBrowseChild.test_with_multiple_page_types.<locals>.<dictcomp>rP   )r   r$   r&   r#   r;   r<   r=   rU   rV   rn   r%   r   r   r   r)   r   r?   rI   r*   r*   r+   test_with_multiple_page_types   s&   
z4TestChooserBrowseChild.test_with_multiple_page_typesc                 C   st   t dddddd}| jj|d | dd	i}| |jd
 | |jd ddg | d}d}| || d S )Nr   r   r   r   r   r   r   r   r   r8   page_type_nameszSimple pagez
Event pagerd   aO  
            <p class="help-block help-warning">
                <svg class="icon icon-warning icon" aria-hidden="true"><use href="#icon-warning"></use></svg>
                Only the following page types may be chosen for this field: Simple page, Event page. Search results will exclude pages of other types.
            </p>
        )	r   r$   r&   r#   r;   r<   rU   rl   assertTagInHTML)r)   r   r?   rd   expectedr*   r*   r+   6test_with_multiple_specific_page_types_display_warning   s    zMTestChooserBrowseChild.test_with_multiple_specific_page_types_display_warningc                 C       |  ddi}| |jd d S Nr   zfoo.barr   r#   r;   r<   r>   r*   r*   r+   test_with_unknown_page_type     z2TestChooserBrowseChild.test_with_unknown_page_typec                 C   r   Nr   zwagtailcore.siter   r   r>   r*   r*   r+   test_with_bad_page_type  r   z.TestChooserBrowseChild.test_with_bad_page_typec                 C   r   Nr   r   r   r   r>   r*   r*   r+   test_with_invalid_page_type!  r   z2TestChooserBrowseChild.test_with_invalid_page_typec                 C   sR   |  ddi}| |jd | |d |  d}| d| | d| d S )Nr   wagtailcore.Pager8   r9   rd   foobarbaz (simple page)zdata-title="foobarbaz")r#   r;   r<   r=   rl   assertInHTMLrn   r)   r?   rd   r*   r*   r+   test_with_admin_display_title%  s   z4TestChooserBrowseChild.test_with_admin_display_titlec                 C   s   t ddd}| jj|d | jjtd| jjfdddid	}| |jd
 | 	|d | 
d| d | 
d| d d S )Nquuxgoodbyer   r   r   r   r   r   r4   r8   r9   r   rd   zquux (simple page))r   r%   r&   r2   r#   r	   r   r;   r<   r=   r   rl   )r)   	leaf_pager?   r*   r*   r+   $test_parent_with_admin_display_title3  s   z;TestChooserBrowseChild.test_parent_with_admin_display_titlec                 C   sx   t ddd}| jj|d | jtd|jfd}| |jd | 	|d d	j
| jjd
d}| || d d S )Nr   r   r   r   r   r   r8   r9   a  
            <li class="w-h-full w-flex w-items-center w-overflow-hidden w-transition w-duration-300 w-whitespace-nowrap w-flex-shrink-0 w-font-bold " data-w-breadcrumbs-target="content">
                <a class="w-flex w-items-center w-text-text-label w-pr-0.5 w-text-14 w-no-underline w-outline-offset-inside w-border-b w-border-b-2 w-border-transparent w-box-content hover:w-border-current hover:w-text-text-label" href="/admin/choose-page/{page_id}/?">
                    {page_title}
                </a>
                <svg class="icon icon-arrow-right w-w-4 w-h-4 w-ml-3" aria-hidden="true">
                   <use href="#icon-arrow-right"></use>
                </svg>
            </li>
        r   )page_id
page_titlerd   )r   r%   r&   r2   r#   r	   r   r;   r<   r=   formatr   rl   )r)   r   r?   r   r*   r*   r+   #test_admin_display_title_breadcrumbC  s   	z:TestChooserBrowseChild.test_admin_display_title_breadcrumbc                 C   s2   t dD ]}tdd| dd}| jj|d qd S )Nd   r   zfoobarbaz-%dr   )r   slugr   r   )ranger   r$   r&   )r)   inew_pager*   r*   r+   setup_pagination_test_data_  s   z1TestChooserBrowseChild.setup_pagination_test_datac                 C   s>   |    |  }| |jd jjd | |jd jd d S )Npagination_page   rQ   )r   r#   r;   rU   	paginator	num_pagesnumberr>   r*   r*   r+   test_pagination_basici  s   z,TestChooserBrowseChild.test_pagination_basicc                 C   s.   |    | ddi}| |jd jd d S )Npr   r   )r   r#   r;   rU   r   r>   r*   r*   r+   test_pagination_another_pagep  s   z3TestChooserBrowseChild.test_pagination_another_pagec                 C   (   |    | ddi}| |jd d S )Nr   r   r   r   r#   r;   r<   r>   r*   r*   r+   test_pagination_invalid_pagev     z3TestChooserBrowseChild.test_pagination_invalid_pagec                 C   r   )Nr   r   r   r   r>   r*   r*   r+   !test_pagination_out_of_range_page|  r   z8TestChooserBrowseChild.test_pagination_out_of_range_pageN)r{   r|   r}   r,   r#   r   r@   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r*   r*   r*   r+   r   v   s,    	2
r   c                   @   s|   e Zd ZdgZdd Z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d ZdS )TestChooserSearchztest_empty.jsonc                 C   r   r   r!   r(   r*   r*   r+   r,     r-   zTestChooserSearch.setUpNc                 C   s   | j td|p	i S )Nwagtailadmin_choose_page_searchr1   r3   r*   r*   r+   r#     r   zTestChooserSearch.getc                 C   sz   |  ddd}| |jd | |d | |d | |d td| jjgdd	 }| |d
| d| jj d d S )Nr   r   )qallow_external_linkr8   )wagtailadmin/chooser/_search_results.htmlThere is 1 matchr   r   z?allow_external_link=true	<a href="z" class="navigate-parent">z</a>)	r#   r;   r<   r=   r   r	   r$   r   r   )r)   r?   expected_urlr*   r*   r+   r@     s   zTestChooserSearch.test_simplec                 C   sD   |  ddi}| |jd | |d | |d | |d d S )Nr   foobar8   r   r   r   r#   r;   r<   r=   r   r>   r*   r*   r+   test_partial_match  s
   z$TestChooserSearch.test_partial_matchc                 C   sX   t dddddd}| jj|d | dd	i}| |jd
 | |d | |d d S )NzLunar eventr   r   r   r   r   r   r   lunarr8   r   zLunar event (single event))r   r$   r&   r#   r;   r<   r=   r   )r)   r   r?   r*   r*   r+   +test_result_uses_custom_admin_display_title  s   z=TestChooserSearch.test_result_uses_custom_admin_display_titlec                 C   r   )Nr   r   r8   zThere are 0 matchesr#   r;   r<   r   r>   r*   r*   r+   test_search_no_results  s   z(TestChooserSearch.test_search_no_resultsc                 C   s   t dddddd}| jj|d | dd	d
}| |jd | |d | |jd d	 dd |jd D }| | j	j
| | |j
| d S )Nfoobarbaz againr   r   r   r   r   r   r   r   r   r   r8   r   r   c                 S   r   r*   r   r   r*   r*   r+   r     r   z9TestChooserSearch.test_with_page_type.<locals>.<dictcomp>rI   )r   r$   r&   r#   r;   r<   r=   rU   rn   r%   r   r   r   r*   r*   r+   r     s   z%TestChooserSearch.test_with_page_typec                 C   sF   |  ddd}| |jd | |d | |d | |d d S )Nr   r   r   r8   r   r   r   r>   r*   r*   r+   r     s
   z+TestChooserSearch.test_with_blank_page_typec                 C   s   t dddddd}| jj|d | dd	d
}| |jd | |d | |jd d	 dd |jd D }| | j	j
| | |j
| d S )Nr   r   r   r   r   r   r   r   r   r   r8   r   r   c                 S   r   r*   r   r   r*   r*   r+   r     r   zCTestChooserSearch.test_with_multiple_page_types.<locals>.<dictcomp>rI   )r   r$   r&   r#   r;   r<   r=   rU   rn   r%   r   r   r*   r*   r+   r     s&   
z/TestChooserSearch.test_with_multiple_page_typesc                 C   r   r   r   r>   r*   r*   r+   r     r   z-TestChooserSearch.test_with_unknown_page_typec                 C   r   r   r   r>   r*   r*   r+   r      r   z)TestChooserSearch.test_with_bad_page_typec                 C   r   r   r   r>   r*   r*   r+   r     r   z-TestChooserSearch.test_with_invalid_page_typec                    s   t ddd | jj d t ddd}| jj|d  fdd}| d| | d	d
i}W d    n1 s8w   Y  | t|jd d | |jd d j  d S )NrB   r   r   r   rC   c                    rD   rE   rF   rH   rK   r*   r+   rM     rN   zDTestChooserSearch.test_construct_queryset_hook.<locals>.filter_pagesrO   r   TestrI   rQ   r   )	r   r$   r&   rS   r#   r;   rT   rU   rW   rX   r*   rK   r+   rZ     s   z.TestChooserSearch.test_construct_queryset_hookr   )r{   r|   r}   fixturesr,   r#   r@   r   r   r   r   r   r   r   r   r   rZ   r*   r*   r*   r+   r     s    
		r   c                   @   sX   e Zd Zdd Zdd Zi fddZdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )TestAutomaticRootPageDetectionc                 C   s   t jjdd| _t jjdd| _| jjtdddd| _| jjtdd	dd| _| jjtd
ddd| _	| 
d| _|   d S )NrQ   r   r   About	About Foor   r   ContactzContent FooPeoplezThe people of FooEvents)r   r"   r#   	tree_root	home_pager&   r   
about_pagecontact_pagepeople_pagemake_event_sectionevent_indexr'   r(   r*   r*   r+   r,     s   


z$TestAutomaticRootPageDetection.setUpc                 C   sL   | j jt|dd}|jtddddddd |jtd	d
ddddd |S )Nr   r   zFirst EventBarr   r   r   r   zSecond EventBaz)r  r&   r   r   )r)   namer	  r*   r*   r+   r  +  s(   		z1TestAutomaticRootPageDetection.make_event_sectionc                 C   s   | j td|}|jd jS )Nr0   parent_page)r2   r#   r	   rU   rW   )r)   r4   r?   r*   r*   r+   get_best_rootA  s   z,TestAutomaticRootPageDetection.get_best_rootc                 C   s   |  |  | j d S r   r;   r  r  r(   r*   r*   r+   test_no_type_filterE  r   z2TestAutomaticRootPageDetection.test_no_type_filterc                 C   s   |  | ddi| j d S )Nr   r   r  r(   r*   r*   r+   test_type_pageH  s   z-TestAutomaticRootPageDetection.test_type_pagec                 C      |  | ddi| j dS )zc
        The chooser should start at the EventIndex that holds all the
        EventPages.
        r   tests.EventPageN)r;   r  r	  r(   r*   r*   r+   test_type_eventpageM     z2TestAutomaticRootPageDetection.test_type_eventpagec                 C   s&   |  d | | ddi| j dS )zs
        The chooser should start at the home page, as there are two
        EventIndexes with EventPages.
        zOther eventsr   r  N)r  r;   r  r  r(   r*   r*   r+   test_type_eventpage_two_indexesV  s   
z>TestAutomaticRootPageDetection.test_type_eventpage_two_indexesc                 C   r  )zm
        The chooser should start at the home page, as all SimplePages are
        directly under it
        r   tests.BusinessIndexNr  r(   r*   r*   r+   test_type_simple_page`  r  z4TestAutomaticRootPageDetection.test_type_simple_pagec                 C   r  )zW
        The chooser should start at the root, as there are no BusinessIndexes
        r   r  Nr  r(   r*   r*   r+   test_type_missingi  s   z0TestAutomaticRootPageDetection.test_type_missingN)r{   r|   r}   r,   r  r  r  r  r  r  r  r  r*   r*   r*   r+   r     s    	
	r   c                   @   s   e Zd Zdd Zi fddZi i 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edddd Zeddd d! Zed"dd#d$ Zd%S )&TestChooserExternalLinkc                 C   s2   |    tddd| _tjjddj| jd d S )Nr   r   r   r   )r_   r   )r'   r   internal_pager   r"   r#   r&   r(   r*   r*   r+   r,   s  s   zTestChooserExternalLink.setUpc                 C   r.   )N&wagtailadmin_choose_page_external_linkr1   r3   r*   r*   r+   r#   x  s   zTestChooserExternalLink.getc                 C   *   t d}|r|dt| 7 }| j||S )Nr  ?r	   r   r2   postr)   	post_data
url_paramsr   r*   r*   r+   r   }     zTestChooserExternalLink.postc                 C   r6   )Nr8   z'wagtailadmin/chooser/external_link.htmlr:   r>   r*   r*   r+   r@     rA   z#TestChooserExternalLink.test_simplec                 C   :   |  ddd}| |jd | |d | |d d S )NTorchboxzhttps://torchbox.com/	link_textlink_urlr8   r   r>   r*   r*   r+   test_prepopulated_form     z.TestChooserExternalLink.test_prepopulated_formc                 C   s~   |  ddd}| |jd t|j }| |d d | |d d d | |d d	 d | |d d
 d d S )Nhttp://www.example.com/exampleexternal-link-chooser-urlzexternal-link-chooser-link_textr8   rb   external_link_chosenresultr   r   prefer_this_title_as_link_textTr   r;   r<   rl   rm   r   rk   assertIsr)   r?   rt   r*   r*   r+   test_create_link  s   z(TestChooserExternalLink.test_create_linkc                 C   s|   |  ddi}| |jd t|j }| |d d | |d d d | |d d d | |d d	 d
 d S )Nr/  r,  r8   rb   r0  r1  r   r   r2  Fr3  r5  r*   r*   r+   test_create_link_without_text  s   z5TestChooserExternalLink.test_create_link_without_textc                 C   s   |  dddddd}t|j d }| |d d | |d d | |d	 d
 |  dddddd}t|j d }| |d d | |d d | |d	 d d S )Nr,  r-  r.  zhttp://old.example.com/r)  r(  r1  r   r   r2  Fnew exampleTr   rl   rm   r   rk   r;   r4  r)   r?   r1  r*   r*   r+    test_notice_changes_to_link_text  0   

z8TestChooserExternalLink.test_notice_changes_to_link_textc                 C   sN   |  ddd}| |jd t|j }| |d d | |d d S )Nzntp://www.example.comr-  r.  r8   rb   external_linkzEnter a valid URL.)r   r;   r<   rl   rm   r   rk   r   r5  r*   r*   r+   test_invalid_url  s   z(TestChooserExternalLink.test_invalid_urlc                 C   sj   |  ddd}| |jd t|j }| |d d | |d d d | |d d	 d d S )
Nz/admin/adminr.  r8   rb   r0  r1  r   r   )r   r;   r<   rl   rm   r   rk   r5  r*   r*   r+   test_allow_local_url  s   z,TestChooserExternalLink.test_allow_local_urlc                 C   sn   |  ddd}| |jd t|j }| |d d | |d d d	 | |d d
 | jj d S )Nhttp://localhost/about/aboutr.  r8   rb   r0  r1  r   /about/r   	r   r;   r<   rl   rm   r   rk   r  r_   r5  r*   r*   r+   &test_convert_external_to_internal_link     z>TestChooserExternalLink.test_convert_external_to_internal_linkc                 C   s   |  ddd}| |jd t|j }| |d d | |d d d | |d	 d d
 | |d	 d | jj d S )Nhttp://localhost/about?test=1rC  r.  r8   rb   confirm_external_to_internalexternalr   internalrD  r   rE  r5  r*   r*   r+   Atest_convert_external_link_with_query_parameters_to_internal_link  s   zYTestChooserExternalLink.test_convert_external_link_with_query_parameters_to_internal_linkc                 C   sn   |  ddd}| |jd t|j }| |d d | |d d d | |d d	 | jj d S )
NrD  rC  r.  r8   rb   r0  r1  r   r   rE  r5  r*   r*   r+   4test_convert_relative_external_link_to_internal_link	  rG  zLTestChooserExternalLink.test_convert_relative_external_link_to_internal_linkr   %WAGTAILADMIN_EXTERNAL_LINK_CONVERSIONc                 C      d}d}|  ||d}| |jd t|j }| |d d | |d d | | |d d	 | | d
|d  d S )NrB  rC  r.  r8   rb   r0  r1  r   r   r   r   r;   r<   rl   rm   r   rk   r   r)   r   r   r?   rt   r*   r*   r+   :test_no_conversion_external_to_internal_link_when_disabled  s   zRTestChooserExternalLink.test_no_conversion_external_to_internal_link_when_disabledexactc                 C   rP  )NrH  rC  r.  r8   rb   r0  r1  r   r   r   rQ  rR  r*   r*   r+   4test_no_confirm_external_to_internal_link_when_exact%  s   zLTestChooserExternalLink.test_no_confirm_external_to_internal_link_when_exactconfirmc                 C   s   d}|  |dd}| |jd t|j }| |d d | |d d | | |d	 d d
 | |d	 d | jj d S )NrB  rC  r.  r8   rb   rI  rJ  r   rK  rD  r   rE  r)   r   r?   rt   r*   r*   r+   @test_convert_external_link_to_internal_link_with_confirm_setting5  s   zXTestChooserExternalLink.test_convert_external_link_to_internal_link_with_confirm_settingN)r{   r|   r}   r,   r#   r   r@   r*  r6  r7  r<  r?  rA  rF  rL  rM  r   rS  rU  rX  r*   r*   r*   r+   r  r  s(    !

r  zwagtail.test.headless_urls)ROOT_URLCONFc                   @   s6   e Zd Zdd Zdd Zdd Zeddd	d
 ZdS )&TestChooserExternalLinkWithNoServePathc                 C      |  ddd}| |jd t|j }| |d d | |d d d | |d	 d  | |d	 d
 | jj	 d S NrB  rC  r.  r8   rb   rI  rJ  r   rK  r   
r   r;   r<   rl   rm   r   rk   assertIsNoner  r_   r5  r*   r*   r+   rF  L  s   zMTestChooserExternalLinkWithNoServePath.test_convert_external_to_internal_linkc                 C   r[  )NrH  rC  r.  r8   rb   rI  rJ  r   rK  r   r]  r5  r*   r*   r+   rL  _  s   zhTestChooserExternalLinkWithNoServePath.test_convert_external_link_with_query_parameters_to_internal_linkc                 C   r[  )NrD  rC  r.  r8   rb   rI  rJ  r   rK  r   r]  r5  r*   r*   r+   rM  s  s   z[TestChooserExternalLinkWithNoServePath.test_convert_relative_external_link_to_internal_linkrV  rN  c                 C   s   d}|  |dd}| |jd t|j }| |d d | |d d | | |d	 d  | |d	 d
 | jj	 d S r\  r]  rW  r*   r*   r+   rX    s   zgTestChooserExternalLinkWithNoServePath.test_convert_external_link_to_internal_link_with_confirm_settingN)r{   r|   r}   rF  rL  rM  r   rX  r*   r*   r*   r+   rZ  J  s    rZ  zwagtail.test.non_root_urlsc                   @   sv   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
dddd Ze
dddd Ze
dddd ZdS )+TestChooserExternalLinkWithNonRootServePathzsite/c                 C      |  ddd}| |jd t|j }| |d d | |d d d | |d	 d d
| j d | |d	 d | jj	 d S )NrB  rC  r.  r8   rb   rI  rJ  r   rK  /about/r   
r   r;   r<   rl   rm   r   rk   prefixr  r_   r5  r*   r*   r+   rF       zRTestChooserExternalLinkWithNonRootServePath.test_convert_external_to_internal_linkc                 C   s   |  d| j ddd}| d |  d| j ddd}W d    n1 s*w   Y  | |jd t|j }| |d d | |d	 d
 d| j d | |d	 d | j	j
 d S )Nhttp://localhost/rb  rC  r.  
   r8   rb   r0  r1  r   ra  r   )r   rd  assertNumQueriesr;   r<   rl   rm   r   rk   r  r_   r5  r*   r*   r+   6test_convert_external_to_internal_link_with_serve_path  s"   
zbTestChooserExternalLinkWithNonRootServePath.test_convert_external_to_internal_link_with_serve_pathc                 C   r`  )NrH  rC  r.  r8   rb   rI  rJ  r   rK  ra  rb  r   rc  r5  r*   r*   r+   rL    s   zmTestChooserExternalLinkWithNonRootServePath.test_convert_external_link_with_query_parameters_to_internal_linkc                 C   s   |  d| j ddd}| |jd t|j }| |d d | |d d	 d| j d | |d
 d	 d| j d | |d
 d | jj	 d S )Nrf  about?test=1rC  r.  r8   rb   rI  rJ  r   rK  ra  rb  r   
r   rd  r;   r<   rl   rm   r   rk   r  r_   r5  r*   r*   r+   Qtest_convert_external_link_with_query_parameters_to_internal_link_with_serve_path  s   
z}TestChooserExternalLinkWithNonRootServePath.test_convert_external_link_with_query_parameters_to_internal_link_with_serve_pathc                 C   r`  )NrD  rC  r.  r8   rb   rI  rJ  r   rK  ra  rb  r   rc  r5  r*   r*   r+   rM    re  z`TestChooserExternalLinkWithNonRootServePath.test_convert_relative_external_link_to_internal_linkc                 C   s   |  d| j ddd}| |jd t|j }| |d d | |d d	 d| j d | |d d
 | jj	 d S )Nra  rb  rC  r.  r8   rb   r0  r1  r   r   rk  r5  r*   r*   r+   Dtest_convert_relative_external_link_to_internal_link_with_serve_path  s   zpTestChooserExternalLinkWithNonRootServePath.test_convert_relative_external_link_to_internal_link_with_serve_pathr   rN  c                 C      d| j  d}d}| ||d}| |jd t|j }| |d d | |d d	 | | |d d
 | | d|d  d S )Nrf  rb  rC  r.  r8   rb   r0  r1  r   r   r   	rd  r   r;   r<   rl   rm   r   rk   r   rR  r*   r*   r+   Jtest_no_conversion_external_to_internal_link_when_disabled_with_serve_path,  s   zvTestChooserExternalLinkWithNonRootServePath.test_no_conversion_external_to_internal_link_when_disabled_with_serve_pathrT  c                 C   rn  )Nrf  rj  rC  r.  r8   rb   r0  r1  r   r   r   ro  rR  r*   r*   r+   Dtest_no_confirm_external_to_internal_link_when_exact_with_serve_path=  s   zpTestChooserExternalLinkWithNonRootServePath.test_no_confirm_external_to_internal_link_when_exact_with_serve_pathrV  c                 C   s   d| j  d}| |dd}| |jd t|j }| |d d | |d d	 | | |d
 d	 d| j  d | |d
 d | jj	 d S )Nrf  rb  rC  r.  r8   rb   rI  rJ  r   rK  ra  r   )
rd  r   r;   r<   rl   rm   r   rk   r  r_   rW  r*   r*   r+   rX  M  s   zlTestChooserExternalLinkWithNonRootServePath.test_convert_external_link_to_internal_link_with_confirm_settingN)r{   r|   r}   rd  rF  ri  rL  rl  rM  rm  r   rp  rq  rX  r*   r*   r*   r+   r_    s    

r_  Tzwagtail.test.urls_multilang)WAGTAIL_I18N_ENABLEDrY  c                   @      e Zd ZdZdS )TestChooserExternalLinkWithI18nzen/Nr{   r|   r}   rd  r*   r*   r*   r+   rt  b  s    rt  z$wagtail.test.urls_multilang_non_rootc                   @   rs  )&TestChooserExternalLinkWithI18nNonRootzen/site/Nru  r*   r*   r*   r+   rv  j  s    rv  c                   @   sV   e Zd Zdd Zi fddZi i fddZdd Zd	d
 Zdd Zdd Z	dd Z
dS )TestChooserAnchorLinkc                 C   r   r   r   r(   r*   r*   r+   r,   u  r   zTestChooserAnchorLink.setUpc                 C   r.   )N$wagtailadmin_choose_page_anchor_linkr1   r3   r*   r*   r+   r#   x  r5   zTestChooserAnchorLink.getc                 C   r  )Nrx  r  r  r!  r*   r*   r+   r   {  r$  zTestChooserAnchorLink.postc                 C   r6   )Nr8   z%wagtailadmin/chooser/anchor_link.htmlr:   r>   r*   r*   r+   r@     rA   z!TestChooserAnchorLink.test_simplec                 C   r%  )NExample Anchor Textexampleanchorr'  r8   r   r>   r*   r*   r+   r*    r+  z,TestChooserAnchorLink.test_prepopulated_formc                 C   X   |  ddd}t|j d }| |d d | |d d | |d d	 d S )
Nrz  ry  anchor-link-chooser-urlzanchor-link-chooser-link_textr1  r   #exampleanchorr   r2  Tr:  r;  r*   r*   r+   r6       z&TestChooserAnchorLink.test_create_linkc                 C   V   |  ddi}t|j d }| |d d | |d d | |d d d S )	Nr}  rz  r1  r   r~  r   r2  Fr:  r;  r*   r*   r+   r7       z3TestChooserAnchorLink.test_create_link_without_textc                 C   s   |  dddddd}t|j d }| |d d | |d d | |d	 d
 |  dddddd}t|j d }| |d d | |d d | |d	 d
 d S )Nexampleanchor2zExample Text)r}  email-link-chooser-link_textr8  r1  r   z#exampleanchor2r   r2  TzExample Anchor Test 2.1r|  rz  ry  r:  r;  r*   r*   r+   r<    r=  z6TestChooserAnchorLink.test_notice_changes_to_link_textN)r{   r|   r}   r,   r#   r   r@   r*  r6  r7  r<  r*   r*   r*   r+   rw  t  s    	rw  c                   @   sn   e Zd Zdd Zi fddZi i 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S )TestChooserEmailLinkc                 C   r   r   r   r(   r*   r*   r+   r,     r   zTestChooserEmailLink.setUpc                 C   r.   )N#wagtailadmin_choose_page_email_linkr1   r3   r*   r*   r+   r#     r5   zTestChooserEmailLink.getc                 C   r  )Nr  r  r  r!  r*   r*   r+   r     r$  zTestChooserEmailLink.postc                 C   r6   )Nr8   z$wagtailadmin/chooser/email_link.htmlr:   r>   r*   r*   r+   r@     rA   z TestChooserEmailLink.test_simplec                 C   r%  )NExampleexample@example.comr'  r8   r   r>   r*   r*   r+   r*       z+TestChooserEmailLink.test_prepopulated_formc                 C   r{  )
Nr  contact email-link-chooser-email_addressr  r1  r   mailto:example@example.comr   r2  Tr:  r;  r*   r*   r+   r6    r  z%TestChooserEmailLink.test_create_linkc                 C   s   |  ddddd}| |jd t|j d }|d }| |d	 | |d
 d | |d d t|}t	|j
}| |jd | |d d d | |d d d d S )Nr  r  Awesome SubjectAn example body)r  r  email-link-chooser-subjectemail-link-chooser-bodyr8   r1  r   zMmailto:example@example.com?subject=Awesome%20Subject&body=An%20example%20bodyr   r2  Tsubjectr   body)r   r;   r<   rl   rm   r   rk   r4  r   r   rq   pathr)   r?   r1  r   
mail_partsrq   r*   r*   r+   &test_create_link_with_subject_and_body  s.   
z;TestChooserEmailLink.test_create_link_with_subject_and_bodyc                 C      |  dddd}| |jd t|j d }|d }| |d | |d	 d | |d
 d t|}t	|j
}| |jd | |d d d | d|v d S )Nr  r  r  )r  r  r  r8   r1  r   z4mailto:example@example.com?subject=Awesome%20Subjectr   r2  Tr  r   r  r   r;   r<   rl   rm   r   rk   r4  r   r   rq   r  r   r  r*   r*   r+   "test_create_link_with_subject_only  &   
z7TestChooserEmailLink.test_create_link_with_subject_onlyc                 C   r  )Nr  r  r  )r  r  r  r8   r1  r   z3mailto:example@example.com?body=An%20example%20bodyr   r2  Tr  r   r  r  r  r*   r*   r+   test_create_link_with_body_only  r  z4TestChooserEmailLink.test_create_link_with_body_onlyc                 C   r  )	Nr  r  r1  r   r  r   r2  Fr:  r;  r*   r*   r+   r7  6  s   z2TestChooserEmailLink.test_create_link_without_textc                 C      |  dddddd}t|j d }| |d d | |d	 d | |d
 d |  dddddd}t|j d }| |d d | |d	 d | |d
 d d S )Nzexample2@example.comr-  r  r  r8  r1  r   zmailto:example2@example.comr   r2  Fr9  Tr:  r;  r*   r*   r+   r<  A  r=  z5TestChooserEmailLink.test_notice_changes_to_link_textN)r{   r|   r}   r,   r#   r   r@   r*  r6  r  r  r  r7  r<  r*   r*   r*   r+   r    s    r  c                   @   s^   e Zd Zdd Zi fddZi i fddZdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )TestChooserPhoneLinkc                 C   r   r   r   r(   r*   r*   r+   r,   d  r   zTestChooserPhoneLink.setUpc                 C   r.   )N#wagtailadmin_choose_page_phone_linkr1   r3   r*   r*   r+   r#   g  r5   zTestChooserPhoneLink.getc                 C   r  )Nr  r  r  r!  r*   r*   r+   r   j  r$  zTestChooserPhoneLink.postc                 C   r6   )Nr8   z$wagtailadmin/chooser/phone_link.htmlr:   r>   r*   r*   r+   r@   p  rA   z TestChooserPhoneLink.test_simplec                 C   r%  )Nr  
+123456789r'  r8   r   r>   r*   r*   r+   r*  u  r  z+TestChooserPhoneLink.test_prepopulated_formc                 C   r{  )
Nr  callphone-link-chooser-phone_numberzphone-link-chooser-link_textr1  r   tel:+123456789r   r2  Tr:  r;  r*   r*   r+   r6  {     z%TestChooserPhoneLink.test_create_linkc                 C   r  )	Nr  r  r1  r   r  r   r2  Fr:  r;  r*   r*   r+   r7    r  z2TestChooserPhoneLink.test_create_link_without_textc                 C   r  )Nz
+222222222r-  r  z
+111111111r8  r1  r   ztel:+222222222r   r2  Fr9  Tr:  r;  r*   r*   r+   r<    r=  z5TestChooserPhoneLink.test_notice_changes_to_link_textc                 C   r{  )
Nz+1 234 567 890r  r  r1  r   ztel:+1234567890r   r2  Tr:  r;  r*   r*   r+   test_phone_number_has_spaces  r  z1TestChooserPhoneLink.test_phone_number_has_spacesN)r{   r|   r}   r,   r#   r   r@   r*  r6  r7  r<  r  r*   r*   r*   r+   r  c  s    	!r  c                   @   sj   e 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d Z
dd Zdd Zdd Zdd ZdS )TestCanChoosePage	test.jsonc                 C   s   |   | _tf| _d S r   )r'   userr   desired_classesr(   r*   r*   r+   r,     s   
zTestCanChoosePage.setUpc                 C   s,   t jjdd}t|| j| j}| | d S )N/home/url_pathr   r"   r#   r   r  r  r   r)   homepager1  r*   r*   r+   test_can_choose_page  s   z&TestCanChoosePage.test_can_choose_pagec                 C   s>   t jjdd}t jjdd}t||| jdd}| | d S )Nr  r  zeventeditor@example.com)emailcopy_to)	user_perm)r   r"   r#   r   r   r  r   )r)   r  event_editorr1  r*   r*   r+   test_with_user_no_permission  s   
z.TestCanChoosePage.test_with_user_no_permissionc                 C   0   t jjdd}t|| j| jdd}| | d S )Nra  r  Tr   r  r)   rootr1  r*   r*   r+   test_with_can_choose_root  
   z+TestCanChoosePage.test_with_can_choose_rootc                 C   r  )Nra  r  Fr  r   r"   r#   r   r  r  r   r  r*   r*   r+   test_with_can_not_choose_root  r  z/TestCanChoosePage.test_with_can_not_choose_rootc                 C   s4   t jjdd}t|| j| jd|gd}| | d S )Nr  r  move_tor  target_pagesr  r  r*   r*   r+   test_move_to_same_page  s   z(TestCanChoosePage.test_move_to_same_pagec                 C   B   t jjdd}t jjdd}t|| j| jd|gd}| | d S )Nr  r  ra  r  r  r  )r)   r  r  r1  r*   r*   r+   test_move_to_root  s   z#TestCanChoosePage.test_move_to_rootc                 C   r  )N-/home/events/businessy-events/board-meetings/r  r  r  r  r  )r)   board_meetingsr  r1  r*   r*   r+   )test_move_to_page_with_wrong_parent_types  s   z;TestCanChoosePage.test_move_to_page_with_wrong_parent_typesc                 C   sD   t jjdd}t jjdd}t|| j| jd||gd}| | d S )Nr  r  /home/secret-plans/bulk_move_tor  r  )r)   r  secret_plansr1  r*   r*   r+   test_move_to_same_page_bulk  s   z-TestCanChoosePage.test_move_to_same_page_bulkc                 C   R   t jjdd}t jjdd}t jjdd}t|| j| jd||gd}| | d S )Nr  r  r  ra  r  r  r  )r)   r  r  r  r1  r*   r*   r+   test_move_to_root_bulk  s   z(TestCanChoosePage.test_move_to_root_bulkc                 C   r  )Nr  r  z$/home/secret-plans/steal-underpants/r  r  r  r  )r)   r  steal_underpantsr  r1  r*   r*   r+   .test_move_to_page_with_wrong_parent_types_bulk  s   z@TestCanChoosePage.test_move_to_page_with_wrong_parent_types_bulkN)r{   r|   r}   r   r,   r  r  r  r  r  r  r  r  r  r  r*   r*   r*   r+   r    s    	r  rr  c                   @   sr   e Zd ZdgZdZdd Zdd Zdd	d
Zdd Zdd Z	dd Z
dd Zedddd Zdd Zdd ZdS )TestPageChooserLocaleSelectorr  zTdata-locale-selector[^<]+<button[^<]+<svg[^<]+<use[^<]+<\/use[^<]+<\/svg[^<]+Englishc                 C   s   t jjdd| _tddd| _| jj| jd tjjdd| _	| j
| j	| _d	| j_| j  | j
| j	| _| j  | j| jjd
}d| d| _|   d S )Nr   r   r   r   r   r   fr)language_code	Bienvenue)parent_page_idr   " data-locale-selector-link>)r   r"   r#   r$   r   r%   r&   r   create	fr_localecopy_for_translationroot_page_frr   savechild_page_frget_choose_page_urlr_   LOCALE_SELECTOR_HTML_FRr'   )r)   switch_to_french_urlr*   r*   r+   r,   7  s   


z#TestPageChooserLocaleSelector.setUpc                 C   s   | j td|gdS r   r1   )r)   r  r*   r*   r+   r#   N  r   z!TestPageChooserLocaleSelector.getNr   c                 C   s.   |d urt d|gd}nt d}| d| S )Nr   r   r0   r  r   )r)   r  r4   r   r*   r*   r+   r  S  s   z1TestPageChooserLocaleSelector.get_choose_page_urlc                 C   sT   | j td}| d}| || j | jdd}d| d}| || d S )Nr0   rd   	locale=frr   r   r  )r2   r#   r	   rl   assertRegexLOCALE_SELECTOR_HTMLr  rn   )r)   r?   rd   r  fr_selectorr*   r*   r+   )test_locale_selector_present_in_root_viewZ  s   zGTestPageChooserLocaleSelector.test_locale_selector_present_in_root_viewc                 C   s<   |  | jj}|  d}| || j | | j| d S )Nrd   )r#   r%   r_   rl   r  r  rn   r  r   r*   r*   r+   test_locale_selectord  s   z2TestPageChooserLocaleSelector.test_locale_selectorc                 C   s6   | j   | | jj}| d}| d| d S Nrd   data-locale-selector)r  deleter#   r%   r_   rl   r   r   r*   r*   r+   (test_locale_selector_without_translationk  s   
zFTestPageChooserLocaleSelector.test_locale_selector_without_translationc                 C   s   | j dd}| j|}| d}| | j| | d| jj d| | | j	j| | 
|d | j dd}| d| d	| d S )
Nr  r   rd   zdata-title="re   zSdata-locale-selector[^<]+<button[^<]+<svg[^<]+<use[^<]+<\/use[^<]+<\/svg[^<]+Frenchz	locale=enr   r  )r  r2   r#   rl   r   r  r$   r   rn   r  r  )r)   r  r?   rd   switch_to_english_urlr*   r*   r+   'test_locale_selector_with_active_localer  s   
zETestPageChooserLocaleSelector.test_locale_selector_with_active_localeFr  c                 C   s,   |  | jj}|  d}| d| d S r  )r#   r%   r_   rl   r   r   r*   r*   r+   3test_locale_selector_not_present_when_i18n_disabled  s   zQTestPageChooserLocaleSelector.test_locale_selector_not_present_when_i18n_disabledc                 C   sn   t d| jjgd}d}| j| d| d}| d}| d| | j| jj|d}| t	|| d S )	Nr   r   <can_choose_root=false&user_perms=copy_to&match_subclass=truer  &p=1rd   r  )r  r4   )
r	   r%   r_   r2   r#   rl   rn   r  r  r
   r)   
choose_urlr4   r?   rd   r  r*   r*   r+   test_query_params_preserved  s   
z9TestPageChooserLocaleSelector.test_query_params_preservedc                 C   sb   t d}d}| j| d| d}| d}| d| | j|d d}| t|| d S )	Nr0   r  r  r  rd   r  z
&locale=frr   )r	   r2   r#   rl   rn   r  r
   r  r*   r*   r+   (test_query_params_preserved_in_root_view  s   zFTestPageChooserLocaleSelector.test_query_params_preserved_in_root_view)Nr   )r{   r|   r}   r   r  r,   r#   r  r  r  r  r  r   r  r  r  r*   r*   r*   r+   r  1  s    


r  )+rl   urllib.parser   r   django.contrib.authr   django.testr   r   r   django.urlsr	   django.utils.htmlr
   django.utils.httpr   wagtail.admin.views.chooserr   wagtail.modelsr   r   wagtail.test.testapp.modelsr   r   r   r   wagtail.test.utilsr   r   r~   r   r   r   r  rZ  r_  rt  rv  rw  r  r  r  r  r*   r*   r*   r+   <module>   sZ    Q   Z YP G
S [s