a
    Dųgė  ć                   @   sD  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mZmZmZmZmZmZmZ G d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd  d eZ#d!S )"é    )Śpartial)ŚTestCase)Ś
SafeString)Ścompare)ŚStreamValue)Śget_image_model)Śget_test_image_file)	ŚAdvertWithCustomPrimaryKeyŚEventCategoryŚ	EventPageŚEventPageSpeakerŚHeadCountRelatedModelUsingPKŚ
SimplePageŚ'SnippetChooserModelWithCustomPrimaryKeyŚ
StreamPageŚ
TaggedPagec                   @   s*   e Zd ZejZdd Zdd Zdd ZdS )ŚTestFieldComparisonc                 C   s|   |   tj d”tddtdd”}|  |j” |  |j” |  | 	” d” |  | 
” d” |  | 
” t” |  | ” ” d S )NŚcontentŚContent©r   )Ścomparison_classr   Ś_metaŚ	get_fieldŚ
assertTrueŚis_fieldŚassertFalseŚis_child_relationŚassertEqualŚfield_labelŚhtmldiffŚassertIsInstancer   Śhas_changed©ŚselfŚ
comparison© r%   ś_/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/admin/tests/test_compare.pyŚtest_hasnt_changed   s    
żz&TestFieldComparison.test_hasnt_changedc                 C   sT   |   tj d”tddtdd”}|  | ” d” |  | ” t” |  | 	” ” d S )Nr   śOriginal contentr   śModified contentz\<span class="deletion">Original content</span><span class="addition">Modified content</span>©
r   r   r   r   r   r   r    r   r   r!   r"   r%   r%   r&   Śtest_has_changed(   s    
żžz$TestFieldComparison.test_has_changedc                 C   sF   |   tj d”tddtdd”}|  | ” d” |  | ” t” d S )Nr   r(   r   ś9<script type="text/javascript">doSomethingBad();</script>z<span class="deletion">Original content</span><span class="addition">&lt;script type=&quot;text/javascript&quot;&gt;doSomethingBad();&lt;/script&gt;</span>©r   r   r   r   r   r   r    r   r"   r%   r%   r&   Śtest_htmldiff_escapes_value6   s    
’żžz/TestFieldComparison.test_htmldiff_escapes_valueN)	Ś__name__Ś
__module__Ś__qualname__r   ŚFieldComparisonr   r'   r+   r.   r%   r%   r%   r&   r      s   r   c                   @   s*   e Zd ZejZdd Zdd Zdd ZdS )ŚTestTextFieldComparisonc                 C   sT   |   tj d”tddtdd”}|  | ” d” |  | ” t” |  | 	” ” d S ©Nr   r(   r   r)   śT<span class="deletion">Original</span><span class="addition">Modified</span> contentr*   r"   r%   r%   r&   r+   K   s    
żžz(TestTextFieldComparison.test_has_changedc                 C   sT   |   tj d”td dtdd”}|  | ” d” |  | ” t” |  | 	” ” d S )Nr   r   zAdded contentz+<span class="addition">Added content</span>r*   r"   r%   r%   r&   Ś+test_from_none_to_value_only_shows_additionY   s    
ż’zCTestTextFieldComparison.test_from_none_to_value_only_shows_additionc                 C   sT   |   tj d”tddtd d”}|  | ” d” |  | ” t” |  | 	” ” d S )Nr   zRemoved contentr   z-<span class="deletion">Removed content</span>r*   r"   r%   r%   r&   Ś+test_from_value_to_none_only_shows_deletionf   s    
ż’zCTestTextFieldComparison.test_from_value_to_none_only_shows_deletionN)	r/   r0   r1   r   ZTextFieldComparisonr   r+   r6   r7   r%   r%   r%   r&   r3   F   s   r3   c                   @   s*   e Zd ZejZdd Zdd Zdd ZdS )ŚTestRichTextFieldComparisonc                 C   sT   |   tj d”tddtdd”}|  | ” d” |  | ” t” |  | 	” ” d S r4   r*   r"   r%   r%   r&   r+   y   s    
żžz,TestRichTextFieldComparison.test_has_changedc                 C   sT   |   tj d”tddtdd”}|  | ” d” |  | ” t” |  | 	” ” d S )Nr   ś<b>Original</b> contentr   śModified <i>content</i>r5   r*   r"   r%   r%   r&   Śtest_has_changed_html   s    
żžz1TestRichTextFieldComparison.test_has_changed_htmlc                 C   sF   |   tj d”tddtdd”}|  | ” d” |  | ” t” d S )Nr   r(   r   zLDo something good. <script type="text/javascript">doSomethingBad();</script>z^<span class="deletion">Original content</span><span class="addition">Do something good.</span>r-   r"   r%   r%   r&   r.      s    
’żžz7TestRichTextFieldComparison.test_htmldiff_escapes_valueN)	r/   r0   r1   r   ZRichTextFieldComparisonr   r+   r;   r.   r%   r%   r%   r&   r8   t   s   r8   c                   @   s²   e Zd Zej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%d& Zd'd( Zd)S )*ŚTestStreamFieldComparisonc                 C   s   t j d”}|  |t t|jdgdt t|jdgd”}|  |j” |  |j	” |  
| ” d” |  
| ” d” |  | ” t” |  | ” ” d S )NŚbody©Śtextr   Ś1©r=   ZBodyz3<div class="comparison__child-object">Content</div>)r   r   r   r   r   Śstream_blockr   r   r   r   r   r   r   r    r   r!   ©r#   Śfieldr$   r%   r%   r&   r'   Ŗ   s4    ’ž’’ž’ö’z,TestStreamFieldComparison.test_hasnt_changedc                 C   sl   t j d”}|  |t t|jdgdt t|jdgd”}|  | ” d” |  | ” t	” |  
| ” ” d S )Nr=   )r?   r(   r@   rA   )r?   r)   r@   ś<div class="comparison__child-object"><span class="deletion">Original</span><span class="addition">Modified</span> content</div>©r   r   r   r   r   rB   r   r   r    r   r   r!   rC   r%   r%   r&   r+   Ź   s0    ’ž’’ž’öžz*TestStreamFieldComparison.test_has_changedc              	   C   sn   t j d”}|  |t t|jdgdt t|jddgd”}|  | ” d” |  | ” t	” |  
| ” ” d S )Nr=   r>   rA   )r?   zNew ContentŚ2zt<div class="comparison__child-object">Content</div>
<div class="comparison__child-object addition">New Content</div>rF   rC   r%   r%   r&   Śtest_add_blockč   s2    ’ž’žž’öžz(TestStreamFieldComparison.test_add_blockc              	   C   sp   t j d”}|  |t t|jg d¢dt t|jddgd”}|  | ” d” |  | ” t	” |  
| ” ” d S )Nr=   ©r>   )r?   zContent FoorG   ©r?   zContent BarŚ3rA   r>   rJ   z¬<div class="comparison__child-object">Content</div>
<div class="comparison__child-object deletion">Content Foo</div>
<div class="comparison__child-object">Content Bar</div>rF   rC   r%   r%   r&   Śtest_delete_block  s0    ž’
žž’ōžz+TestStreamFieldComparison.test_delete_blockc              	   C   sp   t j d”}|  |t t|jg d¢dt t|jg d¢d”}|  | ” d” |  | ” t	” |  
| ” ” d S )Nr=   rI   rA   )r>   )r?   zContent BazrG   rJ   zā<div class="comparison__child-object">Content</div>
<div class="comparison__child-object">Content <span class="deletion">Foo</span><span class="addition">Baz</span></div>
<div class="comparison__child-object">Content Bar</div>rF   rC   r%   r%   r&   Śtest_edit_block(  s,    ž’
ž’ōžz)TestStreamFieldComparison.test_edit_blockc                 C   sl   t j d”}|  |t t|jdgdt t|jdgd”}|  | ” d” |  | ” t	” |  
| ” ” d S )Nr=   )Ś	rich_textr9   r@   rA   )rN   r:   r@   rE   rF   rC   r%   r%   r&   Śtest_has_changed_richtextJ  s0    ’ž’’ž’öžz3TestStreamFieldComparison.test_has_changed_richtextc                 C   s^   t j d”}|  |t t|jdgdt t|jdgd”}|  | ” d” |  | ” t	” d S )Nr=   )r?   z/I <b>really</b> like original<i>ish</i> contentr@   rA   )r?   zXI <b>really</b> like evil code <script type="text/javascript">doSomethingBad();</script>r@   a  <div class="comparison__child-object">I &lt;b&gt;really&lt;/b&gt; like <span class="deletion">original&lt;i&gt;ish&lt;/i&gt; content</span><span class="addition">evil code &lt;script type=&quot;text/javascript&quot;&gt;doSomethingBad();&lt;/script&gt;</span></div>©
r   r   r   r   r   rB   r   r   r    r   rC   r%   r%   r&   Ś%test_htmldiff_escapes_value_on_changeh  s.    ’ž’’ž’ņžz?TestStreamFieldComparison.test_htmldiff_escapes_value_on_changec              	   C   s`   t j d”}|  |t t|jdgdt t|jddgd”}|  | ” d” |  | ” t	” d S )Nr=   ©r?   ś'Original <em>and unchanged</em> contentr@   rA   ©r?   r,   rG   śä<div class="comparison__child-object">Original &lt;em&gt;and unchanged&lt;/em&gt; content</div>
<div class="comparison__child-object addition">&lt;script type=&quot;text/javascript&quot;&gt;doSomethingBad();&lt;/script&gt;</div>rP   rC   r%   r%   r&   Ś'test_htmldiff_escapes_value_on_addition  s0    ’ž’žž’öžzATestStreamFieldComparison.test_htmldiff_escapes_value_on_additionc                 C   s`   t j d”}|  |t t|jddgdt t|jdgd”}|  | ” d” |  | ” t	” d S )Nr=   rR   rT   rA   śä<div class="comparison__child-object">Original &lt;em&gt;and unchanged&lt;/em&gt; content</div>
<div class="comparison__child-object deletion">&lt;script type=&quot;text/javascript&quot;&gt;doSomethingBad();&lt;/script&gt;</div>rP   rC   r%   r%   r&   Ś'test_htmldiff_escapes_value_on_deletionÆ  s0    žž’’ž’ńžzATestStreamFieldComparison.test_htmldiff_escapes_value_on_deletionc                 C   s^   t j d”}|  |t t|jdgdt t|jdgd”}|  | ” d” |  | ” t	” d S )Nr=   )rN   z"I <b>really</b> like Wagtail &lt;3r@   rA   )rN   śbI <b>really</b> like evil code &gt;_&lt; <script type="text/javascript">doSomethingBad();</script>r@   z<div class="comparison__child-object">I really like <span class="deletion">Wagtail &lt;3</span><span class="addition">evil code &gt;_&lt;</span></div>rP   rC   r%   r%   r&   Ś,test_htmldiff_richtext_strips_tags_on_changeŃ  s.    ’ž’’ž’öžzFTestStreamFieldComparison.test_htmldiff_richtext_strips_tags_on_changec              	   C   s`   t j d”}|  |t t|jdgdt t|jddgd”}|  | ” d” |  | ” t	” d S )Nr=   ©rN   rS   r@   rA   ©rN   rY   rG   z”<div class="comparison__child-object">Original and unchanged content</div>
<div class="comparison__child-object addition">I really like evil code &gt;_&lt;</div>rP   rC   r%   r%   r&   Ś.test_htmldiff_richtext_strips_tags_on_additionņ  s0    ’ž’žž’öžzHTestStreamFieldComparison.test_htmldiff_richtext_strips_tags_on_additionc                 C   s`   t j d”}|  |t t|jddgdt t|jdgd”}|  | ” d” |  | ” t	” d S )Nr=   r[   r\   rA   z”<div class="comparison__child-object">Original and unchanged content</div>
<div class="comparison__child-object deletion">I really like evil code &gt;_&lt;</div>rP   rC   r%   r%   r&   Ś.test_htmldiff_richtext_strips_tags_on_deletion  s0    žž’’ž’ńžzHTestStreamFieldComparison.test_htmldiff_richtext_strips_tags_on_deletionc                 C   s^   t j d”}|  |t t|jdgdt t|jdgd”}|  | ” d” |  | ” t	” d S )Nr=   )Śraw_htmlzOriginal<i>ish</i> contentr@   rA   )r_   r,   r@   zŻ<div class="comparison__child-object"><span class="deletion">Original&lt;i&gt;ish&lt;/i&gt; content</span><span class="addition">&lt;script type=&quot;text/javascript&quot;&gt;doSomethingBad();&lt;/script&gt;</span></div>rP   rC   r%   r%   r&   Ś.test_htmldiff_raw_html_escapes_value_on_change6  s.    ’ž’’ž’öžzHTestStreamFieldComparison.test_htmldiff_raw_html_escapes_value_on_changec              	   C   s`   t j d”}|  |t t|jdgdt t|jddgd”}|  | ” d” |  | ” t	” d S )Nr=   ©r_   rS   r@   rA   ©r_   r,   rG   rU   rP   rC   r%   r%   r&   Ś0test_htmldiff_raw_html_escapes_value_on_additionV  s0    ’ž’žž’öžzJTestStreamFieldComparison.test_htmldiff_raw_html_escapes_value_on_additionc                 C   s`   t j d”}|  |t t|jddgdt t|jdgd”}|  | ” d” |  | ” t	” d S )Nr=   ra   rb   rA   rW   rP   rC   r%   r%   r&   Ś0test_htmldiff_raw_html_escapes_value_on_deletionw  s0    žž’’ž’ńžzJTestStreamFieldComparison.test_htmldiff_raw_html_escapes_value_on_deletionc                 C   s   t j d”}|  |t t|jdddddfgdt t|jdddddfgd”}d	}|  | ” |” |  | ” t	” |  
| ” ” d S )
Nr=   Śproductza packet of rolosZ75p)ŚnameZpricer@   rA   Z85pa  
            <div class="comparison__child-object"><dl>
                <dt>Name</dt>
                <dd>a packet of rolos</dd>
                <dt>Price</dt>
                <dd><span class="deletion">75p</span><span class="addition">85p</span></dd>
            </dl></div>
        )r   r   r   r   r   rB   ŚassertHTMLEqualr   r    r   r   r!   )r#   rD   r$   Śexpectedr%   r%   r&   Śtest_compare_structblock  s,    ’ž’’ž’öz2TestStreamFieldComparison.test_compare_structblockc              
   C   sÄ   t j d”}|jjd }| ddddddddg”}| dd	dddd
ddg”}|  |t t|jd|dfgdt t|jd|dfgd”}| ” }d}|  	||” |  
|t” |  | ” ” d S )Nr=   Ś
title_listŚitemŚfooz$11111111-1111-1111-1111-111111111111)ŚtypeŚvalueŚidŚbarz$22222222-2222-2222-2222-222222222222ZbardZfoodr@   rA   aĘ  
            <div class="comparison__child-object">
                <div class="comparison__child-object">
                    <span class="deletion">bar</span>
                    <span class="addition">bard</span>
                </div>

                <div class="comparison__child-object">
                    <span class="deletion">foo</span>
                    <span class="addition">food</span>
                </div>
            </div>
        )r   r   r   rB   Śchild_blocksŚ	to_pythonr   r   r   rg   r    r   r   r!   )r#   rD   ŚblockŚ	block_valŚblock_val_2r$   r   rh   r%   r%   r&   Śtest_compare_listblock»  s\    żżś’żżś’’ž’’ž’öz0TestStreamFieldComparison.test_compare_listblockc                 C   s  t j d”}|jjd }d}d}d}ddgddg|fddgg d¢|fg d	¢d
dg|fg}|D ]¶\}}}	| j||d | |”}
| |”}|  |t t|jd|
dfgdt t|jd|dfgd”}| 	” }|  
||	” |  |t” |  | ” ” W d    q\1 s0    Y  q\d S )Nr=   rj   zŠ
            <div class="comparison__child-object">
                <div class="comparison__child-object">foo</div>

                <div class="comparison__child-object">bar</div>
            </div>
        aŗ  
            <div class="comparison__child-object">
                <div class="comparison__child-object">
                    foo
                </div>

                <div class="comparison__child-object">
                    <span class="deletion">bar</span>
                    <span class="addition">bap</span>
                </div>

                <div class="comparison__child-object addition">baz</div>
            </div>
        a  
            <div class="comparison__child-object">
                <div class="comparison__child-object">
                    <span class="deletion">foo</span>
                    <span class="addition">fo</span>
                </div>

                <div class="comparison__child-object">bar</div>

                <div class="comparison__child-object deletion">baz</div>
            </div>
        rl   rp   )rl   ZbapŚbaz)rl   rp   rw   Śfo)Ślist_1Ślist_2r@   rA   )r   r   r   rB   rq   ZsubTestrr   r   r   r   rg   r    r   r   r!   )r#   rD   rs   Zno_diffZedit_and_add_diffZedit_and_add_diff_reversedZold_format_listblock_fixturesry   rz   Zexpected_diffrt   ru   r$   r   r%   r%   r&   Ś!test_compare_listblock_old_format  sD    ż

’ž’’ž’öz;TestStreamFieldComparison.test_compare_listblock_old_formatc                 C   s   t j d”}|jjd }|  |t t|jdt|dgdfgdt t|jdt|dgdfgd”}d}|  | ” |” |  	| ” t
” |  | ” ” d S )Nr=   Zbooks)ŚtitlezThe Old Man and the SeaŚ10r@   rA   )ŚauthorzOscar WildeZ11zž
            <div class="comparison__child-object">
                <div class="comparison__child-object addition">Oscar Wilde</div>

                <div class="comparison__child-object deletion">The Old Man and the Sea</div>
            </div>
        )r   r   r   rB   rq   r   r   rg   r   r    r   r   r!   )r#   rD   rB   r$   rh   r%   r%   r&   Ś5test_compare_nested_streamblock_uses_comparison_classD  sD    žś’ž’’ū’ž’ļ zOTestStreamFieldComparison.test_compare_nested_streamblock_uses_comparison_classc              
   C   sĘ   t  }|jjdt d}|jjdt d}tj d”}|  |tt|j	d|dfgdtt|j	d|dfgd”}| 
” }|  d|” |  d	|” |  d
|” |  d|” |  |t” |  | ” ” d S )NśTest image 1©r|   ŚfileśTest image 2r=   Śimager@   rA   z$<div class="preview-image deletion">zalt="Test image 1"z$<div class="preview-image addition">zalt="Test image 2")r   ŚobjectsŚcreater   r   r   r   r   r   rB   r   ZassertInr    r   r   r!   )r#   Śimage_modelŚtest_image_1Śtest_image_2rD   r$   Śresultr%   r%   r&   Śtest_compare_imagechooserblockq  sD    žž’ž’’ž’öz8TestStreamFieldComparison.test_compare_imagechooserblockN)r/   r0   r1   r   ZStreamFieldComparisonr   r'   r+   rH   rL   rM   rO   rQ   rV   rX   rZ   r]   r^   r`   rc   rd   ri   rv   r{   r   r   r%   r%   r%   r&   r<   §   s*    !"%""!"" !!#FC-r<   c                   @   s2   e Zd ZejZdd Zdd Zdd Zdd Z	d	S )
ŚTestChoiceFieldComparisonc                 C   s|   |   tj d”tddtdd”}|  |j” |  |j” |  | 	” d” |  | 
” d” |  | 
” t” |  | ” ” d S )NŚaudienceŚpublic©r   ZAudienceZPublic)r   r   r   r   r   r   r   r   r   r   r   r    r   r!   r"   r%   r%   r&   r'     s    
żz,TestChoiceFieldComparison.test_hasnt_changedc                 C   sT   |   tj d”tddtdd”}|  | ” d” |  | ” t” |  | 	” ” d S )Nr   r   r   ŚprivatezI<span class="deletion">Public</span><span class="addition">Private</span>©
r   r   r   r   r   r   r    r   r   r!   r"   r%   r%   r&   r+   ­  s    
żžz*TestChoiceFieldComparison.test_has_changedc                 C   sT   |   tj d”td dtdd”}|  | ” d” |  | ” t” |  | 	” ” d S )Nr   r   r   z%<span class="addition">Private</span>r   r"   r%   r%   r&   r6   »  s    
żzETestChoiceFieldComparison.test_from_none_to_value_only_shows_additionc                 C   sT   |   tj d”tddtd d”}|  | ” d” |  | ” t” |  | 	” ” d S )Nr   r   r   z$<span class="deletion">Public</span>r   r"   r%   r%   r&   r7   Ę  s    
żzETestChoiceFieldComparison.test_from_value_to_none_only_shows_deletionN)
r/   r0   r1   r   ZChoiceFieldComparisonr   r'   r+   r6   r7   r%   r%   r%   r&   r     s
   r   c                   @   s"   e Zd ZejZdd Zdd ZdS )ŚTestTagsFieldComparisonc                 C   s¬   t  }|j d” |j d” t  }|j d” |j d” |  t j d”||”}|  |j” |  |j	” |  
| ” d” |  
| ” d” |  | ” t” |  | ” ” d S )NŚwagtailŚbirdŚtagsZTagszwagtail, bird)r   r   Śaddr   r   r   r   r   r   r   r   r   r   r    r   r!   ©r#   ŚaŚbr$   r%   r%   r&   r'   Õ  s    z*TestTagsFieldComparison.test_hasnt_changedc                 C   s   t  }|j d” |j d” t  }|j d” |j d” |  t j d”||”}|  | ” d” |  | ” t	” |  
| ” ” d S )Nr   r   Z	motacillar   zTwagtail, <span class="deletion">bird</span>, <span class="addition">motacilla</span>)r   r   r   r   r   r   r   r   r    r   r   r!   r   r%   r%   r&   r+   ē  s    žz(TestTagsFieldComparison.test_has_changedN)r/   r0   r1   r   ZTagsFieldComparisonr   r'   r+   r%   r%   r%   r&   r   Ņ  s   r   c                   @   s0   e Zd ZdgZejZdd Zdd Zdd Z	dS )	ŚTestM2MFieldComparisonz	test.jsonc                 C   s4   t jjdd| _t jjdd| _t jjdd| _d S )NZMeetings)rf   ZPartiesZHolidays)r
   r   r   Śmeetings_categoryŚparties_categoryŚholidays_category)r#   r%   r%   r&   ŚsetUpž  s    zTestM2MFieldComparison.setUpc                 C   sØ   t jjdd}t jjdd}| j| jg|_| j| jg|_|  t j d”||”}|  	|j
” |  |j” |  | ” d” |  | ” ” |  | ” d” |  | ” t” d S )Nś/home/events/christmas/©Zurl_pathś/home/events/saint-patrick/Ś
categoriesZ
CategorieszMeetings, Parties)r   r   Śgetr   r   r¢   r   r   r   r   r   r   r   r   r   r!   r   r    r   ©r#   Zchristmas_eventZsaint_patrick_eventr$   r%   r%   r&   r'     s"    ’
żz)TestM2MFieldComparison.test_hasnt_changedc                 C   s   t jjdd}t jjdd}| j| jg|_| j| jg|_|  t j 	d”||”}|  
| ” ” |  | ” d” |  | ” t” d S )Nr   r    r”   r¢   zWMeetings, <span class="deletion">Parties</span>, <span class="addition">Holidays</span>)r   r   r£   r   r   r¢   r   r   r   r   r   r!   r   r   r    r   r¤   r%   r%   r&   r+     s&    ’ž
żžz'TestM2MFieldComparison.test_has_changedN)
r/   r0   r1   Zfixturesr   ZM2MFieldComparisonr   r   r'   r+   r%   r%   r%   r&   r   ś  s
   r   c                   @   s.   e Zd ZejZedd Zdd Zdd Z	dS )ŚTestForeignObjectComparisonc                 C   s2   t  }|jjdt d| _|jjdt d| _d S )Nr   r   r   )r   r   r   r   r   r   )Śclsr   r%   r%   r&   ŚsetUpTestData6  s    žžz)TestForeignObjectComparison.setUpTestDatac                 C   s   |   tj d”t| jdt| jd”}|  |j” |  |j” |  	| 
” d” |  	| ” d” |  | ” t” |  | ” ” d S )NŚ
feed_image©rØ   z
Feed imager   )r   r   r   r   r   r   r   r   r   r   r   r   r    r   r!   r"   r%   r%   r&   r'   B  s    


żz.TestForeignObjectComparison.test_hasnt_changedc                 C   sX   |   tj d”t| jdt| jd”}|  | ” d” |  | ” t	” |  
| ” ” d S )NrØ   r©   zT<span class="deletion">Test image 1</span><span class="addition">Test image 2</span>)r   r   r   r   r   r   r   r   r    r   r   r!   r"   r%   r%   r&   r+   P  s    


żžz,TestForeignObjectComparison.test_has_changedN)
r/   r0   r1   r   ŚForeignObjectComparisonr   Śclassmethodr§   r'   r+   r%   r%   r%   r&   r„   3  s
   
r„   c                   @   s2   e Zd ZdZejZedd Zdd Z	dd Z
dS )	Ś'TestForeignObjectComparisonWithCustomPKzNForeignObjectComparison works with models declaring a custom primary key fieldc                 C   sD   t jjddd}t jjddd}tjj|d| _tjj|d| _d S )NŚad1śAdvert 1)Z	advert_idr?   Śad2zAdvert 2)Śadvertwithcustomprimarykey)r	   r   r   r   Ś
test_obj_1Ś
test_obj_2)r¦   r­   rÆ   r%   r%   r&   r§   d  s    ’’’’z5TestForeignObjectComparisonWithCustomPK.setUpTestDatac                 C   st   |   tj d”| j| j”}|  |j” |  |j” |  	| 
” d” |  	| ” d” |  | ” t” |  | ” ” d S )Nr°   ZAdvertwithcustomprimarykeyr®   )r   r   r   r   r±   r   r   r   r   r   r   r   r    r   r!   r"   r%   r%   r&   r'   s  s    ’ūz:TestForeignObjectComparisonWithCustomPK.test_hasnt_changedc                 C   sL   |   tj d”| j| j”}|  | ” d” |  | ” t	” |  
| ” ” d S )Nr°   zL<span class="deletion">Advert 1</span><span class="addition">Advert 2</span>)r   r   r   r   r±   r²   r   r   r    r   r   r!   r"   r%   r%   r&   r+     s    ’ūžz8TestForeignObjectComparisonWithCustomPK.test_has_changedN)r/   r0   r1   Ś__doc__r   rŖ   r   r«   r§   r'   r+   r%   r%   r%   r&   r¬   _  s   
r¬   c                   @   s@   e Zd ZejZejZdd Zdd Z	dd Z
dd Zd	d
 ZdS )ŚTestChildRelationComparisonc           
   	   C   s  t ddd}|j tddd” t ddd}|j tddd” |  t j d”t| jtj d”t| jtj d	”g||”}|  	|j
” |  |j” |  | ” d
” |  	| ” ” t|j ” }t|j ” }| ||”\}}}}	|  |ddi” |  |ddi” |  |g ” |  |	g ” d S )Nś
Event pageŚevent©r|   ZslugŚFatherŚ	Christmas©Ś
first_nameŚ	last_nameŚspeakerr»   r¼   ŚSpeakerr   ©r   Śspeakersr   r   r   r   r   r   Śfield_comparison_classr   r   r   r   r   r   r!   ŚlistŚval_aŚallŚval_bŚget_mapping©
r#   Ś
event_pageZmodified_event_pager$   Zobjs_aZobjs_bZmap_forwardsZmap_backwardsŚaddedZdeletedr%   r%   r&   r'     sR    ž’ž’

ž
žū
ó’z.TestChildRelationComparison.test_hasnt_changedc           
   	   C   s:  t ddd}|j tdddd” t ddd}|j tdd	dd” |j tdd
dd” |  t j d”t| jtj d”t| jtj d”g||”}|  	|j
” |  |j” |  | ” d” |  | ” ” t|j ” }t|j ” }| ||”\}}}}	|  |ddi” |  |ddi” |  |dg” |  |	g ” d S )Nrµ   r¶   r·   rø   r¹   r   ©r»   r¼   Ś
sort_orderŚSantaŚClausŚTedé   r½   r»   r¼   r¾   ræ   rĒ   r%   r%   r&   r+   Ģ  sd    ż’ż’ż’

ž
žū
ó’z,TestChildRelationComparison.test_has_changedc           
   	   C   s>  t ddd}|j tddddd” t ddd}|j tdd	d
dd” |j tdddd” |  t j d”t| jtj d”t| jtj d”g||”}|  	|j
” |  |j” |  | ” d” |  | ” ” t|j ” }t|j ” }| ||”\}}}}	|  |ddi” |  |ddi” |  |dg” |  |	g ” d S )Nrµ   r¶   r·   rĻ   rø   r¹   r   )ro   r»   r¼   rĖ   rĢ   rĶ   rĪ   rŹ   r½   r»   r¼   r¾   ræ   rĒ   r%   r%   r&   Śtest_has_changed_with_same_id	  sh    ü’	ü’ż’

ž
žū
ó’z9TestChildRelationComparison.test_has_changed_with_same_idc           
   	   C   s  t ddd}|j tdddd” t ddd}|j tdddd” |  t j d	”t| jtj d
”t| jtj d”g||”}|  	|j
” |  |j” |  | ” d” |  | ” ” t|j ” }t|j ” }| ||”\}}}}	|  |i ” |  |i ” |  |dg” |  |	dg” d S )Nrµ   r¶   r·   rĻ   rø   r¹   )ro   r»   r¼   é   r½   r»   r¼   r¾   r   ræ   rĒ   r%   r%   r&   Ś$test_hasnt_changed_with_different_idH  sV    ż’ż’

ž
žū
ó’z@TestChildRelationComparison.test_hasnt_changed_with_different_idc                 C   s`   t ddd}|j tdd” | jt j d”t| jtj d”g||dd	}|  	| 
” d” d S )
Nrµ   r¶   r·   rø   )r»   r½   r»   ZSpeakers)Ślabel)r   rĄ   r   r   r   r   r   r   rĮ   r   r   )r#   rČ   r$   r%   r%   r&   Śtest_panel_label_as_field_label}  s$    ’’

ž’öz;TestChildRelationComparison.test_panel_label_as_field_labelN)r/   r0   r1   r   r2   rĮ   ŚChildRelationComparisonr   r'   r+   rŠ   rŅ   rŌ   r%   r%   r%   r&   r“     s   4=?5r“   c                   @   s@   e Zd ZejZejZdd Zdd Z	dd Z
dd Zd	d
 ZdS )ŚTestChildObjectComparisonc              	   C   s   t ddd}t ddd}|  t t| jt j d”t| jt j d”g||”}|  | ” ” |  | ” ” |  | 	” ” |  
| ” d” |  
| ” d” d S ©Nrø   r¹   rŗ   r»   r¼   r   ©r   r   r   rĮ   r   r   r   Śis_additionŚis_deletionr!   r   Śget_position_changeŚget_num_differences©r#   Zobj_aZobj_br$   r%   r%   r&   Śtest_same_object  s6    žž
ž
žū
óz*TestChildObjectComparison.test_same_objectc              	   C   s   t ddd}t ddd}|  t t| jt j d”t| jt j d”g||”}|  | ” ” |  | ” ” |  	| 
” ” |  | ” d” |  | ” d	” d S )
Nrø   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&   Śtest_different_object»  s6    žž
ž
žū
óz/TestChildObjectComparison.test_different_objectc              	   C   s   t dddd}t dddd}|  t t| jt j d”t| jt j d”g||”}|  | ” ” |  | ” ” |  | 	” ” |  
| ” d” |  
| ” d	” d S )
Nrø   r¹   rĻ   rŹ   é   r»   r¼   é   r   rŲ   rŻ   r%   r%   r&   Śtest_moved_objectÜ  s:    żż
ž
žū
óz+TestChildObjectComparison.test_moved_objectc              	   C   s   t ddd}|  t t| jt j d”t| jt j d”gd |”}|  | ” ” |  | 	” ” |  | 
” ” |  | ” d” |  | ” d” d S r×   )r   r   r   rĮ   r   r   r   rŁ   r   rŚ   r!   ŚassertIsNonerŪ   r   rÜ   ©r#   Śobjr$   r%   r%   r&   Śtest_addition’  s.    ž
ž
žū
óz'TestChildObjectComparison.test_additionc              	   C   s   t ddd}|  t t| jt j d”t| jt j d”g|d ”}|  | ” ” |  | 	” ” |  | 
” ” |  | ” ” |  | ” d” d S r×   )r   r   r   rĮ   r   r   r   rŁ   r   rŚ   r!   rć   rŪ   r   rÜ   rä   r%   r%   r&   Śtest_deletion  s.    ž
ž
žū
óz'TestChildObjectComparison.test_deletionN)r/   r0   r1   r   r2   rĮ   ZChildObjectComparisonr   rŽ   rß   rā   rę   rē   r%   r%   r%   r&   rÖ     s   !!#rÖ   c                   @   s,   e Zd ZdZejZejZdd Z	dd Z
dS )Ś"TestChildRelationComparisonUsingPKzITest related objects can be compred if they do not use id for primary keyc           
      C   s   t ddd}|j tddd” t ddd}|j tddd” |j tdd	” |  t j d
”t| jtj d”g||”}|  	|j
” |  |j” |  | ” d” |  | ” ” t|j ” }t|j ” }| ||”\}}}}	|  |ddi” |  |ddi” |  |dg” |  |	g ” d S )NzSemi Finalszsemi-finals-2018r·   rĻ   é   ©Z	custom_idŚ
head_counté   é   )rė   Śhead_countsrė   śHead countsr   ©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Š   >  sT    ž’ž’’’

ž’÷’z@TestChildRelationComparisonUsingPK.test_has_changed_with_same_idc           
      C   s  t ddd}|j tddd” t ddd}|j tddd” |  t j d”t| jtj d	”g||”}|  	|j
” |  |j” |  | ” d
” |  | ” ” t|j ” }t|j ” }| ||”\}}}}	|  |i ” |  |i ” |  |dg” |  |	dg” d S )NZFinalszfinals-event-abcr·   rĻ   éÜ   rź   rŃ   rī   rė   rļ   r   rš   rĒ   r%   r%   r&   rŅ   s  s>    
’
’

ž’÷’zGTestChildRelationComparisonUsingPK.test_hasnt_changed_with_different_idN)r/   r0   r1   r³   r   r2   rĮ   rÕ   r   rŠ   rŅ   r%   r%   r%   r&   rč   8  s
   5rč   N)$Ś	functoolsr   Zdjango.testr   Zdjango.utils.safestringr   Zwagtail.adminr   Zwagtail.blocksr   Zwagtail.imagesr   Zwagtail.images.tests.utilsr   Zwagtail.test.testapp.modelsr	   r
   r   r   r   r   r   r   r   r   r3   r8   r<   r   r   r   r„   r¬   r“   rÖ   rč   r%   r%   r%   r&   Ś<module>   s6   ,/.3     z6(9,5   #