o
    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)get_soupbEditorHtmlImageEmbedHandlerget_db_attributesassertEqual)selfsouptagresult r   c/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/images/tests/test_rich_text.pytest_get_db_attributes   s   
z6TestEditorHtmlImageEmbedHandler.test_get_db_attributesc                 C   :   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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   8   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.   r2   r5   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   r   )
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,   )r;   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"   r0   )r	   r&   r'   r
   r;   r(   r1   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   r3   )	Nr   r   r   r!   r4   z*<img class="richtext-image left" alt="" />Tr#   r:   r*   r   r   r   7test_expand_db_attributes_for_frontend_with_missing_altz   s   
zUTestFrontendImageEmbedHandler.test_expand_db_attributes_for_frontend_with_missing_altN)r6   r7   r8   r<   r=   r>   r?   r   r   r   r   r9   ]   s
    r9   c                   @      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   extract_referencesr	   r-   r   r   r   test_extract_references   s   z6TestExtractReferencesWithImage.test_extract_referencesN)r6   r7   r8   rF   r   r   r   r   rA          rA   c                   @   r@   )TestEntityFeatureChooserUrlsc                 C   sB   t  }|dd}| |jd | |jd d td d S )NdraftailimagechooserUrlsimageChooserzwagtailimages_chooser:choose)r   get_editor_pluginassertIsNotNonedatagetr   r   )r   featuresrJ   r   r   r   test_chooser_urls_exist   s   z4TestEntityFeatureChooserUrls.test_chooser_urls_existN)r6   r7   r8   rR   r   r   r   r   rH      rG   rH   N)django.testr   django.urlsr   wagtail.fieldsr   wagtail.images.rich_textr   r;   $wagtail.images.rich_text.editor_htmlr   "wagtail.rich_text.feature_registryr   wagtail.test.utilsr   utilsr	   r
   r   r9   rA   rH   r   r   r   r   <module>   s    N*