U
    {hV                     @   s   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
 d dlmZ d dlmZ ddlmZ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ZdS )    )TestCase)reverse_lazy)RichTextField)ImageEmbedHandler)FeatureRegistry)WagtailTestUtils   )Imageget_test_image_filec                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestEditorHtmlImageEmbedHandlerc                 C   s2   |  d}|j}t|}| |dddd d S )NzJ<b data-id="test-id" data-format="test-format" data-alt="test-alt">foo</b>test-altztest-idztest-format)altidformat)Zget_soupbEditorHtmlImageEmbedHandlerZget_db_attributesassertEqual)selfZsouptagresult r   k/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/images/tests/test_rich_text.pytest_get_db_attributes   s    
z6TestEditorHtmlImageEmbedHandler.test_get_db_attributesc                 C   s:   t jjddt d tdddd}| jd|dd	 d S )
Nr   Testr   titlefiler   leftr   r   r   zm<img data-embedtype="image" data-id="1" data-format="left" data-alt="test-alt" class="richtext-image left" />TZallow_extra_attrsr	   objectscreater
   r   expand_db_attributesassertTagInHTMLr   r   r   r   r   $test_expand_db_attributes_for_editor   s    zDTestEditorHtmlImageEmbedHandler.test_expand_db_attributes_for_editorc                 C   s   |  tddid d S Nr   r   z<img alt="">)r   r   r#   r   r   r   r   6test_expand_db_attributes_for_editor_nonexistent_image1   s     zVTestEditorHtmlImageEmbedHandler.test_expand_db_attributes_for_editor_nonexistent_imagec                 C   sF   t jjddt d tdddd}| jd|dd	 | d
| d S )Nr   r   r   Arthur "two sheds" Jacksonr   r   z<img data-embedtype="image" data-id="1" data-format="left" data-alt="Arthur &quot;two sheds&quot; Jackson" class="richtext-image left" />Tr   *alt="Arthur &quot;two sheds&quot; Jackson")r	   r!   r"   r
   r   r#   r$   assertInr%   r   r   r   5test_expand_db_attributes_for_editor_escapes_alt_text6   s    	zUTestEditorHtmlImageEmbedHandler.test_expand_db_attributes_for_editor_escapes_alt_textc                 C   s8   t jjddt d tddd}| jd|dd d S )	Nr   r   r   r   r   r   ze<img data-embedtype="image" data-id="1" data-format="left" data-alt="" class="richtext-image left" />Tr   r    r%   r   r   r   5test_expand_db_attributes_for_editor_with_missing_altK   s    zUTestEditorHtmlImageEmbedHandler.test_expand_db_attributes_for_editor_with_missing_altN)__name__
__module____qualname__r   r&   r)   r-   r/   r   r   r   r   r      s
   r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestFrontendImageEmbedHandlerc                 C   s:   t jjddt d tdddd}| jd|dd	 d S )
Nr   r   r   r   r   r   z#<img class="richtext-image left" />Tr   r	   r!   r"   r
   FrontendImageEmbedHandlerr#   r$   r%   r   r   r   &test_expand_db_attributes_for_frontend^   s      zDTestFrontendImageEmbedHandler.test_expand_db_attributes_for_frontendc                 C   s   t ddi}| |d d S r'   )r5   r#   r   r%   r   r   r   =test_expand_db_attributes_for_frontend_with_nonexistent_imagek   s    z[TestFrontendImageEmbedHandler.test_expand_db_attributes_for_frontend_with_nonexistent_imagec                 C   s6   t jjddt d tdddd}| d| d S )Nr   r   r   r*   r   r   r+   )r	   r!   r"   r
   r5   r#   r,   r%   r   r   r   7test_expand_db_attributes_for_frontend_escapes_alt_texto   s    zUTestFrontendImageEmbedHandler.test_expand_db_attributes_for_frontend_escapes_alt_textc                 C   s8   t jjddt d tddd}| jd|dd d S )	Nr   r   r   r   r.   z*<img class="richtext-image left" alt="" />Tr   r4   r%   r   r   r   7test_expand_db_attributes_for_frontend_with_missing_altz   s      zUTestFrontendImageEmbedHandler.test_expand_db_attributes_for_frontend_with_missing_altN)r0   r1   r2   r6   r7   r8   r9   r   r   r   r   r3   ]   s   r3   c                   @   s   e Zd Zdd ZdS )TestExtractReferencesWithImagec                 C   s&   |  tt dtdddfg d S )NzA<embed alt="Olivia Ava" embedtype="image" format="left" id="52"/>52 )r   listr   Zextract_referencesr	   r(   r   r   r   test_extract_references   s    z6TestExtractReferencesWithImage.test_extract_referencesN)r0   r1   r2   r>   r   r   r   r   r:      s   r:   c                   @   s   e Zd Zdd ZdS )TestEntityFeatureChooserUrlsc                 C   sB   t  }|dd}| |jd | |jd d td d S )NZdraftailimageZchooserUrlsZimageChooserzwagtailimages_chooser:choose)r   Zget_editor_pluginZassertIsNotNonedatagetr   r   )r   featuresr@   r   r   r   test_chooser_urls_exist   s    z4TestEntityFeatureChooserUrls.test_chooser_urls_existN)r0   r1   r2   rD   r   r   r   r   r?      s   r?   N)Zdjango.testr   Zdjango.urlsr   Zwagtail.fieldsr   Zwagtail.images.rich_textr   r5   Z$wagtail.images.rich_text.editor_htmlr   Z"wagtail.rich_text.feature_registryr   Zwagtail.test.utilsr   utilsr	   r
   r   r3   r:   r?   r   r   r   r   <module>   s   N*