o
    h`G                     @   sF  d dl Z d dl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 d dlmZ d dlmZmZ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mZm Z m!Z!m"Z" d dl#m$Z$m%Z% d dl&m'Z'm(Z(m)Z)m*Z* G dd de%eZ+G dd de$Z,G dd deZ-G dd de%eZ.e/ej0dG dd deZ1dS )    N)settings)ImproperlyConfigured)SimpleUploadedFile)ContextTemplate)TestCase)content_state_equal)PAGE_MODEL_CLASSESPageSite)DummyExternalStorage)BusinessChildBusinessIndexBusinessNowherePageBusinessSubIndex
EventIndex	EventPageNoCreatableSubpageTypesPageNoSubpageTypesPageSectionedRichTextPageSimpleChildPage
SimplePageSimpleParentPage
StreamPage)WagtailPageTestsWagtailTestUtils)inline_formsetnested_form_data	rich_textstreamfieldc                   @   $   e Zd Zdd Zdd Zdd ZdS )TestAssertTagInHTMLc                 C   s  d}|  d| | j d|dd | t |  d| W d    n1 s&w   Y  | t | j d|dd W d    n1 sCw   Y  | t |  d| W d    n1 s^w   Y  | t |  d| W d    d S 1 szw   Y  d S )	N<ul>
            <li class="normal">hugh</li>
            <li class="normal">pugh</li>
            <li class="really important" lang="en"><em>barney</em> mcgrew</li>
        </ul>z'<li lang="en" class="important really">z<li class="normal">   countz(<div lang="en" class="important really">z <li lang="en" class="important">z9<li lang="en" class="important really" data-extra="boom">assertTagInHTMLassertRaisesAssertionErrorselfhaystack r-   X/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/tests/test_tests.pytest_assert_tag_in_html&   s&   "z+TestAssertTagInHTML.test_assert_tag_in_htmlc                 C   s   d}| j d|dd | j d|ddd | t | j d|dd W d    n1 s+w   Y  | t | j d|d	dd W d    d S 1 sJw   Y  d S )
Nr"   z<li class="important really">T)allow_extra_attrsz<li>   )r%   r0   z<li class="normal" lang="en">r#   r&   r*   r-   r-   r.   (test_assert_tag_in_html_with_extra_attrs<   s$   "z<TestAssertTagInHTML.test_assert_tag_in_html_with_extra_attrsc                 C   s\   d}|  d| | j d|dd | t |  d| W d    d S 1 s'w   Y  d S )NaW  <html>
            <script type="text/template">
                <p class="really important">first template block</p>
            </script>
            <script type="text/template">
                <p class="really important">second template block</p>
            </script>
            <p class="normal">not in a script tag</p>
        </html>z<p class="important really">r#   r$   z<p class="normal">)assertTagInTemplateScriptr(   r)   r*   r-   r-   r.   "test_assert_tag_in_template_scriptS   s   
"z6TestAssertTagInHTML.test_assert_tag_in_template_scriptN)__name__
__module____qualname__r/   r2   r4   r-   r-   r-   r.   r!   %   s    r!   c                       s\   e Zd Z 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  ZS )TestWagtailPageTestsc                    s&   t    tjjdd}|jj| _d S )NT)is_default_site)supersetUpr   objectsget	root_pagespecificroot)r+   site	__class__r-   r.   r;   h   s   
zTestWagtailPageTests.setUpc                 C   s   |  tt |  tt | tt | t |  tt W d    n1 s(w   Y  | t | tt W d    d S 1 sDw   Y  d S N)	assertCanCreateAtr   r   r
   assertCanNotCreateAtr   r   r(   r)   r+   r-   r-   r.   test_assert_can_create_atm   s   "z.TestWagtailPageTests.test_assert_can_create_atc                 C   s   |  tj  | | jtddd | tj  | tj j | | jt	dddddd	d
ddddddddd | | jt
dddddddddddd d S )NEvent Indexz{"entityMap": {},"blocks": [
                {"inlineStyleRanges": [], "text": "Event intro", "depth": 0, "type": "unstyled", "key": "00000", "entityRanges": []}
            ]}titleintroFlierptextDit is onze mooie text0 r   z{"entityMap": {},"blocks": [
                {"inlineStyleRanges": [], "text": "Dit is onze mooie text in een ferrari", "depth": 0, "type": "unstyled", "key": "00000", "entityRanges": []}
            ]}1productpegsa pound23)rK   zbody-0-typezbody-0-valuezbody-0-orderzbody-0-deletedzbody-1-typezbody-1-valuezbody-1-orderzbody-1-deletedzbody-2-typezbody-2-value-namezbody-2-value-pricezbody-2-orderzbody-2-deletedz
body-count
Fight Club1000z{"entityMap": {},"blocks": [
                {"inlineStyleRanges": [], "text": "Rule 1: You do not talk about Fight Club", "depth": 0, "type": "unstyled", "key": "00000", "entityRanges": []}
            ]}z{"entityMap": {},"blocks": [
                {"inlineStyleRanges": [], "text": "Rule 2: You DO NOT talk about Fight Club", "depth": 0, "type": "unstyled", "key": "00000", "entityRanges": []}
            ]})rK   zsections-TOTAL_FORMSzsections-INITIAL_FORMSzsections-MIN_NUM_FORMSzsections-MAX_NUM_FORMSzsections-0-bodyzsections-0-ORDERzsections-0-DELETEzsections-1-bodyzsections-1-ORDERzsections-1-DELETE)assertFalser   r<   existsassertCanCreater@   
assertTruer=   liver   r   rG   r-   r-   r.   test_assert_can_create{   s\   
z+TestWagtailPageTests.test_assert_can_createc                 C   s8   | j | jtddddd tjjdd}| |j d S )NzSimple Lorem PagezLorem ipsum dolor sit amet)rK   contentF)publish)rK   )r\   r@   r   r
   r<   r=   rZ   r^   )r+   created_pager-   r-   r.   /test_assert_can_create_for_page_without_publish   s   zDTestWagtailPageTests.test_assert_can_create_for_page_without_publishc                 C   s   |  tj  | | jttdtdd | tj  | | jt	tdt
ddtdfdd	d
dfgd | | jttdtdtdidtdigd d S )NrI   z<p>Event intro</p>rJ   rM   )rN   rO   r   z,<p>Dit is onze mooie text in een ferrari</p>rS   rT   rU   )nameprice)rK   bodyrX   rf   z/<p>Rule 1: You do not talk about Fight Club</p>z/<p>Rule 2: You DO NOT talk about Fight Club</p>)rK   sections)rZ   r   r<   r[   r\   r@   r   r   r]   r   r   r   r   rG   r-   r-   r.   (test_assert_can_create_with_form_helpers   s\   z=TestWagtailPageTests.test_assert_can_create_with_form_helpersc                 C   s\   t dddd}| jj|d | td | |ti  W d    d S 1 s'w   Y  d S )NzSimple Pagesimplehello)rK   slugr`   )instancez=Can not create a tests.businesschild under a tests.simplepage)r   r@   	add_childassertRaisesRegexr)   r\   r   )r+   simple_pager-   r-   r.   $test_assert_can_create_subpage_rules   s   "z9TestWagtailPageTests.test_assert_can_create_subpage_rulesc                 C   sB   |  td | | jti  W d    d S 1 sw   Y  d S )Nz\bslug:\n[\s\S]*\btitle:\n)rn   r)   r\   r@   r   rG   r-   r-   r.   'test_assert_can_create_validation_error  s   "z<TestWagtailPageTests.test_assert_can_create_validation_errorc                 C   s|   |  ttth |  ti  tttttth }|  t| | 	t
 |  ttth W d    d S 1 s7w   Y  d S rD   )assertAllowedSubpageTypesr   r   r   setr	   r   r   r
   r(   r)   r+   all_but_businessr-   r-   r.   !test_assert_allowed_subpage_types  s   "z6TestWagtailPageTests.test_assert_allowed_subpage_typesc                 C   s   |  ttth |  tth tttttttth }|  t| | 	t
 |  ttth W d    d S 1 s:w   Y  d S rD   )assertAllowedParentPageTypesr   r   r   rs   r	   r   r   r   r(   r)   rt   r-   r-   r.   %test_assert_allowed_parent_page_types  s$   "z:TestWagtailPageTests.test_assert_allowed_parent_page_types)r5   r6   r7   r;   rH   r_   rc   rh   rp   rq   rv   rx   __classcell__r-   r-   rB   r.   r8   g   s    =
;
r8   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestFormDataHelpersc                 C   s(   t dddid}| |ddd d S )Nbarchildfield)fooparent)r~   zparent-child)r   assertEqualr+   resultr-   r-   r.   test_nested_form_data4  s   z)TestFormDataHelpers.test_nested_form_datac                 C   sN   t dtddddddfgi}| |dd	d
ddd	ddddddddd d S )Nr`   )rN   Hello, world)rN   Goodbye, worldcoffeelattesoya)typemilkrW   rN   r   rP   rQ   r   rR   rV   )zcontent-countzcontent-0-typezcontent-0-valuezcontent-0-orderzcontent-0-deletedzcontent-1-typezcontent-1-valuezcontent-1-orderzcontent-1-deletedzcontent-2-typezcontent-2-value-typezcontent-2-value-milkzcontent-2-orderzcontent-2-deleted)r   r   r   r   r-   r-   r.   test_streamfield?  s6   z$TestFormDataHelpers.test_streamfieldc                 C   sB   t dtddiddigi}| |ddddddddd	dd

 d S )NlinesrN   HelloWorldrV   rP   rY   rQ   rR   )
zlines-TOTAL_FORMSzlines-INITIAL_FORMSzlines-MIN_NUM_FORMSzlines-MAX_NUM_FORMSzlines-0-textzlines-0-ORDERzlines-0-DELETEzlines-1-textzlines-1-ORDERzlines-1-DELETE)r   r   r   r   r-   r-   r.   test_inline_formset`  s,   z'TestFormDataHelpers.test_inline_formsetc                 C   sH   t d}| tt|i g ddddg dg ddddg dgd	 d S )
N<h2>title</h2><p>para</p>rK   r   z
header-two00000inlineStyleRangesrN   depthr   keyentityRangesparaunstyled	entityMapblocksr   r]   r   jsonloadsr   r-   r-   r.   test_default_rich_text|  s.   	z*TestFormDataHelpers.test_default_rich_textc                 C   sN   t ddgd}| tt|i g ddddg dg d	dddg dgd
 d S )Nr   p)featuresrK   r   r   r   r   r   r   r   r   r-   r-   r.   #test_rich_text_with_custom_features  s.   	z7TestFormDataHelpers.test_rich_text_with_custom_featuresc                 C   s   t ddd}| |d d S )Nr   custom)editor)r   r   r   r-   r-   r.   &test_rich_text_with_alternative_editor  s   z:TestFormDataHelpers.test_rich_text_with_alternative_editorN)	r5   r6   r7   r   r   r   r   r   r   r-   r-   r-   r.   rz   3  s    !rz   c                   @   s   e Zd Zdd ZdS )TestDummyExternalStoragec                 C   sZ   d}t d|dd}|  | td t d| W d   dS 1 s&w   Y  dS )z
        Test that DummyExternalStorage correctly warns about attempts
        to write files that are not rewound to the start
        sF   PNG

   IHDR         ĉ   IDATxc````    E@    IENDB`ztest.pngz	image/png)rd   r`   content_typez4Content file pointer should be at 0 - got 70 insteadN)r   readassertRaisesMessage
ValueErrorr   save)r+   png
simple_pngr-   r-   r.   -test_save_with_incorrect_file_object_position  s   "zFTestDummyExternalStorage.test_save_with_incorrect_file_object_positionN)r5   r6   r7   r   r-   r-   r-   r.   r     s    r   z1Number formatting functions have not been patchedc                   @   r    )TestPatchedNumberFormatc                 C   sN   t ddi}td}| t || W d    d S 1 s w   Y  d S )Nnum*   zthe answer is {{ num }})r   r   r(   r   renderr+   contexttemplater-   r-   r.   -test_outputting_number_directly_is_disallowed  s
   "zETestPatchedNumberFormat.test_outputting_number_directly_is_disallowedc                 C   *   t ddi}td}| ||d d S )Nr   (#  z9{% load wagtailadmin_tags %}It's over {{ num|intcomma }}!zIt's over 9,000!r   r   r   r   r   r-   r-   r.   #test_outputting_number_via_intcomma     z;TestPatchedNumberFormat.test_outputting_number_via_intcommac                 C   r   )Nr   r   z.{% load l10n %}It's over {{ num|unlocalize }}!zIt's over 9000!r   r   r-   r-   r.   %test_outputting_number_via_unlocalize  r   z=TestPatchedNumberFormat.test_outputting_number_via_unlocalizeN)r5   r6   r7   r   r   r   r-   r-   r-   r.   r     s    r   )2r   unittestdjango.confr   django.core.exceptionsr   django.core.files.uploadedfiler   django.templater   r   django.testr   %wagtail.admin.tests.test_contentstater   wagtail.modelsr	   r
   r   #wagtail.test.dummy_external_storager   wagtail.test.testapp.modelsr   r   r   r   r   r   r   r   r   r   r   r   r   wagtail.test.utilsr   r   wagtail.test.utils.form_datar   r   r   r   r!   r8   rz   r   
skipUnless$WAGTAIL_CHECK_TEMPLATE_NUMBER_FORMATr   r-   r-   r-   r.   <module>   s0    <B M 
