U
    {®Þh[  ã                   @   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 G dd	„ d	eeƒZG d
d„ deƒZG dd„ deƒZdS )é    )ÚTestCase)Úreverse_lazy)Úget_document_model)ÚDocumentLinkHandler)ÚRichTextField)ÚFeatureRegistry)ÚWagtailTestUtilsc                   @   s2   e Zd ZdgZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú!TestEditorHtmlDocumentLinkHandlerú	test.jsonc                 C   s.   |   d¡}|j}t |¡}|  |ddi¡ d S )Nz<a data-id="test-id">foo</a>Úidztest-id)Zget_soupÚaÚEditorHtmlDocumentLinkHandlerZget_db_attributesÚassertEqual)ÚselfZsoupÚtagÚresult© r   ún/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/documents/tests/test_rich_text.pyÚtest_get_db_attributes   s    

z8TestEditorHtmlDocumentLinkHandler.test_get_db_attributesc                 C   s   t  ddi¡}|  |d¡ d S )Nr   é   zE<a data-linktype="document" data-id="1" href="/documents/1/test.pdf">©r   Úexpand_db_attributesr   ©r   r   r   r   r   Ú$test_expand_db_attributes_for_editor   s
    þzFTestEditorHtmlDocumentLinkHandler.test_expand_db_attributes_for_editorc                 C   s   t  ddi¡}|  |d¡ d S )Nr   r   z(<a data-linktype="document" data-id="0">r   r   r   r   r   ÚItest_expand_db_attributes_for_editor_preserves_id_of_nonexistent_document    s    zkTestEditorHtmlDocumentLinkHandler.test_expand_db_attributes_for_editor_preserves_id_of_nonexistent_documentc                 C   s   t  i ¡}|  |d¡ d S )Nz<a data-linktype="document">r   r   r   r   r   Ú4test_expand_db_attributes_for_editor_with_missing_id$   s    
zVTestEditorHtmlDocumentLinkHandler.test_expand_db_attributes_for_editor_with_missing_idN)Ú__name__Ú
__module__Ú__qualname__Úfixturesr   r   r   r   r   r   r   r   r	      s
   r	   c                   @   s2   e Zd ZdgZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚTestFrontendDocumentLinkHandlerr
   c                 C   s   t  ddi¡}|  |d¡ d S )Nr   r   z <a href="/documents/1/test.pdf">©ÚFrontendDocumentLinkHandlerr   r   r   r   r   r   Ú&test_expand_db_attributes_for_frontend,   s    zFTestFrontendDocumentLinkHandler.test_expand_db_attributes_for_frontendc                 C   s   t  ddi¡}|  |d¡ d S )Nr   r   ú<a>r!   r   r   r   r   Ú1test_expand_db_attributes_document_does_not_exist0   s    zQTestFrontendDocumentLinkHandler.test_expand_db_attributes_document_does_not_existc                 C   s   t  i ¡}|  |d¡ d S )Nr$   r!   r   r   r   r   Ú)test_expand_db_attributes_with_missing_id4   s    
zITestFrontendDocumentLinkHandler.test_expand_db_attributes_with_missing_idc                 C   s(   |   ttƒ  d¡ƒtƒ dddfg¡ d S )Nz4<a linktype="document" id="1">Link to a document</a>Ú1Ú )r   Úlistr   Zextract_referencesr   )r   r   r   r   Útest_extract_references8   s    ÿÿúz7TestFrontendDocumentLinkHandler.test_extract_referencesN)r   r   r   r   r#   r%   r&   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draftailzdocument-linkZchooserUrlsZdocumentChooserzwagtaildocs_chooser:choose)r   Zget_editor_pluginZassertIsNotNoneÚdataÚgetr   r   )r   ÚfeaturesZdocumentr   r   r   Útest_chooser_urls_existD   s    þz4TestEntityFeatureChooserUrls.test_chooser_urls_existN)r   r   r   r/   r   r   r   r   r+   C   s   r+   N)Zdjango.testr   Zdjango.urlsr   Zwagtail.documentsr   Zwagtail.documents.rich_textr   r"   Z'wagtail.documents.rich_text.editor_htmlr   Zwagtail.fieldsr   Z"wagtail.rich_text.feature_registryr   Zwagtail.test.utilsr   r	   r    r+   r   r   r   r   Ú<module>   s   