o
    hW                    @   s  d dl Z d dlZd dlZd dlZ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 d dlmZ d dlmZ d dlmZmZ d d	lmZ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% d dl&m'Z' d dl(m)Z)m*Z* d dl+m,Z,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z4 d dl2m5Z5 d dl6m7Z7m8Z8 d dl9m:Z: d dl;m<Z< G dd dej=Z>G dd dej?Z@G dd deZAG d d! d!e:eZBG d"d# d#ejZCG d$d% d%ejZDG d&d' d'ejZEG d(d) d)ejZFG d*d+ d+eZGG d,d- d-eZHG d.d/ d/eZIG d0d1 d1eZJG d2d3 d3e:eZKG d4d5 d5e:eZLG d6d7 d7ejZMG d8d9 d9ejZNG d:d; d;eZOG d<d= d=eZPG d>d? d?e:eZQG d@dA dAeZRG dBdC dCe:eZSG dDdE dEeZTG dFdG dGeZUG dHdI dIeZVG dJdK dKeZWG dLdM dMejZXG dNdO dOeZYG dPdQ dQeZZG dRdS dSeZ[G dTdU dUeZ\G dVdW dWeZ]G dXdY dYeZ^G dZd[ d[eZ_G d\d] d]eZ`G d^d_ d_eZadS )`    N)Decimal)formsValidationError)DjangoJSONEncoder)	ErrorList)render_to_string)SimpleTestCaseTestCase)SafeData	mark_safe)gettext_lazy)blocks)get_error_json_data)BlockDefinitionLookup)FieldBlockAdapter)ListBlockAdapterListBlockValidationError)StaticBlockAdapter)StreamBlockAdapterStreamBlockValidationError)StructBlockAdapterStructBlockValidationError)Page)RichText)	LinkBlock)SectionBlock)	EventPage
SimplePage)WagtailTestUtils)RemovedInWagtail70Warningc                       s(   e Zd Ze ZdZ fddZ  ZS )FooStreamBlockz!At least one block must say "foo"c                    s6   t  |}tdd |D stjt| jgd|S )Nc                 s   s    | ]}|j d kV  qdS )fooNvalue.0block r(   Y/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/tests/test_blocks.py	<genexpr>*   s    z'FooStreamBlock.clean.<locals>.<genexpr>non_block_errors)supercleananyr   r   r   errorselfr$   	__class__r(   r)   r.   (   s   
zFooStreamBlock.clean)	__name__
__module____qualname__r   	CharBlocktextr0   r.   __classcell__r(   r(   r3   r)   r!   $   s    r!   c                       s   e Zd Zd fdd	Z  ZS )ContextCharBlockNc                    s    t | }ttj| ||S N)strupperr-   r   r8   get_contextr2   r$   parent_contextr3   r(   r)   r?   2      zContextCharBlock.get_contextr<   )r5   r6   r7   r?   r:   r(   r(   r3   r)   r;   1   s    r;   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )	TestBlockc                 C   s    t  }| t || dS )zFThe base normalize implementation should return its argument unchangedN)objectassertIsr   Block	normalize)r2   objr(   r(   r)   test_normalize8   s   zTestBlock.test_normalizec                 C   s"   t  }| t jj|j | dS )zCInstantiating a Block should register it in the definition registryN)r   rF   rE   definition_registrydefinition_prefixr2   r'   r(   r(   r)   test_block_definition_registry=   s   z(TestBlock.test_block_definition_registryc           	   
   C   s  G dd dt j}G dd dt j}G dd dt j}t  gt jdd| gt jd	d
t jdd| | gt jdddgt t  t  t  gd}g d}|D ])\}}| j|dd || D ]	}| |j| qcW d    n1 sww   Y  qStj	j
ddd; g d}|D ]+\}}| j|dd || D ]}|`| |j| qW d    n1 sw   Y  qW d    d S 1 sw   Y  d S )Nc                   @      e Zd ZdddZdS )z?TestBlock.test_block_is_previewable.<locals>.CustomContextBlockNc                 S   s
   |ddS )Nbar)r$   r"   r(   r@   r(   r(   r)   get_preview_contextD      
zSTestBlock.test_block_is_previewable.<locals>.CustomContextBlock.get_preview_contextr<   )r5   r6   r7   rP   r(   r(   r(   r)   CustomContextBlockC       rR   c                   @   rN   )z@TestBlock.test_block_is_previewable.<locals>.CustomTemplateBlockNc                 S      dS )Nfoo.htmlr(   r2   r$   contextr(   r(   r)   get_preview_templateH      zUTestBlock.test_block_is_previewable.<locals>.CustomTemplateBlock.get_preview_templateNN)r5   r6   r7   rX   r(   r(   r(   r)   CustomTemplateBlockG   rS   r[   c                   @      e Zd Zdd ZdS )z=TestBlock.test_block_is_previewable.<locals>.CustomValueBlockc                 S   rT   )Nr"   r(   r2   r(   r(   r)   get_preview_valueL   rY   zOTestBlock.test_block_is_previewable.<locals>.CustomValueBlock.get_preview_valueN)r5   r6   r7   r^   r(   r(   r(   r)   CustomValueBlockK       r_   rU   )preview_templater"   )preview_valuerO   default)ra   rb   )	no_configspecific_templatecustom_value"specific_template_and_custom_valueunset_default_not_none)re   Frf   T)rg   Frh   Tri   FF)variantcustom_global_templatez*wagtail.blocks.base.template_is_overriddenT)return_value)rj   rk   )rg   Trl   rm   )r   rF   	ListBlockStreamBlockStructBlocksubTestrE   is_previewableunittestmockpatch)	r2   rR   r[   r_   variantscasesrn   ru   r'   r(   r(   r)   test_block_is_previewableB   sV   


"z#TestBlock.test_block_is_previewableN)r5   r6   r7   rI   rM   r{   r(   r(   r(   r)   rC   7   s    rC   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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 ) TestFieldBlockc                 C   "   t  }|d}| |d d S NHello world!r   r8   renderassertEqualr2   r'   htmlr(   r(   r)   test_charfield_render      
z$TestFieldBlock.test_charfield_renderc                 C   sH   t jdd}t jj|j }| |t j | |jjd | 	|| d S )N
Test block)label)
r   r8   rF   rJ   rK   assertIsInstancer   metar   rE   )r2   r'   registered_blockr(   r(   r)   rM      s
   z-TestFieldBlock.test_block_definition_registryc                 C   s&   t jdd}|d}| |d d S )Ntests/blocks/heading_block.htmltemplater   <h1>Hello world!</h1>r   r   r(   r(   r)   #test_charfield_render_with_template      
z2TestFieldBlock.test_charfield_render_with_templatec                 C   sv   t jdd}|d t |}| |d d | |d tj | |d ddddd	|j	|j
d
dddid
 d S )NzSome helpful text	help_text
test_blockr         r   Tplaceholderz/w-field w-field--char_field w-field--text_inputADD_COMMENTAdd Comment)
r   descriptionhelpTextrequiredicon
blockDefIdisPreviewable	classnameshowAddCommentButtonstrings)r   r8   set_namer   js_argsr   r   r   	TextInputrK   ru   r2   r'   r   r(   r(   r)   test_charblock_adapter   s&   
z%TestFieldBlock.test_charblock_adapterc                 C   sp   t jdd}|d t |}| d|d d  t jdd}|d t |}| d	|d d  d
S )z
        Meta data test for FormField; this checks if both the meta values
        form_classname and classname are accepted and are rendered
        in the form
        zspecial-char-formclassnameform_classnamer   z special-char-formclassnamer   r   zspecial-char-classname)r   z special-char-classnameN)r   r8   r   r   r   assertIn)r2   r'   r   block_with_classnamer(   r(   r)   %test_charblock_adapter_form_classname   s   

z4TestFieldBlock.test_charblock_adapter_form_classnamec                 C   s,   t dd}|jdddid}| |d d S )Nr   r   Bonjour le monde!languagefrrW   z$<h1 lang="fr">BONJOUR LE MONDE!</h1>)r;   r   r   r   r(   r(   r)   6test_charfield_render_with_template_with_extra_context   s   
zETestFieldBlock.test_charfield_render_with_template_with_extra_contextc                 C   r}   r~   r   r8   get_form_stater   r2   r'   
form_stater(   r(   r)   test_charfield_get_form_state   r   z,TestFieldBlock.test_charfield_get_form_statec                 C   s$   t  }|d}| |dg d S r~   r   r8   get_searchable_contentr   r2   r'   contentr(   r(   r)   !test_charfield_searchable_content      
z0TestFieldBlock.test_charfield_searchable_contentc                 C   s&   t jdd}|d}| |g  d S )NFsearch_indexr   r   r   r(   r(   r)   $test_search_index_searchable_content   r   z3TestFieldBlock.test_search_index_searchable_contentc                 C   P   dd }t j|gd}| t |d W d    d S 1 s!w   Y  d S )Nc                 S      | dkrt dd S Nr"   zValue must be 'foo'r   r#   r(   r(   r)   validate_is_foo      zETestFieldBlock.test_charfield_with_validator.<locals>.validate_is_foo
validatorsrO   )r   r8   assertRaisesr   r.   r2   r   r'   r(   r(   r)   test_charfield_with_validator   
   "z,TestFieldBlock.test_charfield_with_validatorc                 C   2   G dd dt j}| }|d}| |d d S )Nc                   @      e Zd ZejddZdS )z;TestFieldBlock.test_choicefield_render.<locals>.ChoiceBlockchoice-1Choice 1choice-2Choice 2choicesNr5   r6   r7   r   ChoiceFieldfieldr(   r(   r(   r)   ChoiceBlock      
r   r   )r   
FieldBlockr   r   )r2   r   r'   r   r(   r(   r)   test_choicefield_render  s   
z&TestFieldBlock.test_choicefield_renderc                 C   s   G dd dt j}|dd}|d t |}| |d d | |d tj | |d j	dd	g | |d
 dddd|j
|jddddid	 d S )Nc                   @   r   )zATestFieldBlock.test_adapt_custom_choicefield.<locals>.ChoiceBlockr   r   Nr   r(   r(   r(   r)   r     r   r   zA selection of two choices)r   test_choiceblockr   r   r   r   r   Test choiceblockTr   -w-field w-field--choice_field w-field--selectr   r   	r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   Selectr   rK   ru   )r2   r   r'   r   r(   r(   r)   test_adapt_custom_choicefield  s2   

z,TestFieldBlock.test_adapt_custom_choicefieldc                 C   s.   G dd dt j}| }| |dg  dS )z
        FieldBlock should not return anything for `get_searchable_content` by
        default. Subclasses are free to override it and provide relevant
        content.
        c                   @   r   )z;TestFieldBlock.test_searchable_content.<locals>.CustomBlockTr   N)r5   r6   r7   r   	CharFieldr   r(   r(   r(   r)   CustomBlock<  s    r   zfoo barN)r   r   r   r   )r2   r   r'   r(   r(   r)   test_searchable_content5  s   z&TestFieldBlock.test_searchable_contentc                 C   r   )Nc                   @   s    e Zd ZdZdd Zdd ZdS )zbTestFieldBlock.test_form_handling_is_independent_of_serialisation.<locals>.Base64EncodingCharBlockzA CharBlock with a deliberately perverse JSON (de)serialisation format
            so that it visibly blows up if we call to_python / get_prep_value where we shouldn't
            c                 S   
   t |S r<   )base64	b64decode)r2   jsonish_valuer(   r(   r)   	to_pythonH     
zlTestFieldBlock.test_form_handling_is_independent_of_serialisation.<locals>.Base64EncodingCharBlock.to_pythonc                 S   r   r<   )r   	b64encode)r2   native_valuer(   r(   r)   get_prep_valueL  r   zqTestFieldBlock.test_form_handling_is_independent_of_serialisation.<locals>.Base64EncodingCharBlock.get_prep_valueN)r5   r6   r7   __doc__r   r   r(   r(   r(   r)   Base64EncodingCharBlockC  s    r   zhello worldr   )r2   r   r'   r   r(   r(   r)   2test_form_handling_is_independent_of_serialisationB  s   
zATestFieldBlock.test_form_handling_is_independent_of_serialisationc                    s   G dd dG fdddt j G  fdddtj}| }d}||}| |d d	d
i}|||i d	}| |d dS )a  
        Check that Field.prepare_value is called before sending the value to
        the widget for rendering.

        Actual real-world use case: A Youtube field that produces YoutubeVideo
        instances from IDs, but videos are entered using their full URLs.
        c                   @   s4   e Zd ZdZdd Zdd Zedd Zdd	 Zd
S )z?TestFieldBlock.test_prepare_value_called.<locals>.PrefixWrapperhttp://example.com/c                 S   s
   || _ d S r<   r#   r1   r(   r(   r)   __init__`  rQ   zHTestFieldBlock.test_prepare_value_called.<locals>.PrefixWrapper.__init__c                 S   s   | j | j S r<   )prefixr$   r]   r(   r(   r)   with_prefixc     zKTestFieldBlock.test_prepare_value_called.<locals>.PrefixWrapper.with_prefixc                 S   s&   | | jst| |t| jd  S r<   )
startswithr   
ValueErrorlen)clsr$   r(   r(   r)   from_prefixedf  s   zMTestFieldBlock.test_prepare_value_called.<locals>.PrefixWrapper.from_prefixedc                 S   s   | j |j kS r<   r#   )r2   otherr(   r(   r)   __eq__l  r   zFTestFieldBlock.test_prepare_value_called.<locals>.PrefixWrapper.__eq__N)	r5   r6   r7   r   r   r   classmethodr   r   r(   r(   r(   r)   PrefixWrapper]  s    
r   c                       s&   e Zd Z fddZdd Z  ZS )z=TestFieldBlock.test_prepare_value_called.<locals>.PrefixFieldc                    s   t  |} |S r<   )r-   r.   r   r1   )r   r4   r(   r)   r.   p  s   
zCTestFieldBlock.test_prepare_value_called.<locals>.PrefixField.cleanc                 S   s   |  S r<   )r   r1   r(   r(   r)   prepare_valuet     zKTestFieldBlock.test_prepare_value_called.<locals>.PrefixField.prepare_value)r5   r6   r7   r.   r  r:   r(   )r   r3   r)   PrefixFieldo  s    r  c                       s    e Zd Zd fdd	Z  ZS )z?TestFieldBlock.test_prepare_value_called.<locals>.PrefixedBlockT c                    s$   t  jdi |  ||d| _d S )N)r   r   r(   )r-   r   r   )r2   r   r   kwargs)r  r4   r(   r)   r   x  s   zHTestFieldBlock.test_prepare_value_called.<locals>.PrefixedBlock.__init__)Tr  )r5   r6   r7   r   r:   r(   )r  r3   r)   PrefixedBlockw  s    r  r"   zhttp://example.com/foourlzhttp://example.com/barrO   N)r   Fieldr   r   r   r   r.   value_from_datadict)r2   r  r'   r$   r   data	new_valuer(   )r  r   r)   test_prepare_value_calledT  s   	
z(TestFieldBlock.test_prepare_value_calledN)r5   r6   r7   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r  r(   r(   r(   r)   r|      s     
&r|   c                   @   <   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestIntegerBlockc                 C   &   t  }|d}| t|t d S Ni  )r   IntegerBlockvalue_from_formr   typeintr2   r'   digitr(   r(   r)   	test_type  s   
zTestIntegerBlock.test_typec                 C   r}   r  )r   r  r  r   r  r(   r(   r)   test_render  r   zTestIntegerBlock.test_renderc                 C   B   t  }| t |d W d    d S 1 sw   Y  d S Nr  r   r  r   r   r.   rL   r(   r(   r)   test_render_required_error     "z+TestIntegerBlock.test_render_required_errorc                 C   F   t jdd}| t |d W d    d S 1 sw   Y  d S )N   	max_value   r  rL   r(   r(   r)    test_render_max_value_validation     "z1TestIntegerBlock.test_render_max_value_validationc                 C   r  )Nr  	min_value
   r  rL   r(   r(   r)    test_render_min_value_validation  r$  z1TestIntegerBlock.test_render_min_value_validationc                 C   r   )Nc                 S      | d dkr
t dd S Nr   r   zValue must be evenr   r#   r(   r(   r)   validate_is_even     zETestIntegerBlock.test_render_with_validator.<locals>.validate_is_evenr      r  r2   r+  r'   r(   r(   r)   test_render_with_validator  r   z+TestIntegerBlock.test_render_with_validatorN)	r5   r6   r7   r  r  r  r#  r(  r/  r(   r(   r(   r)   r    s    r  c                   @   ,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestEmailBlockc                 C   r}   )Nzexample@email.com)r   
EmailBlockr   r   )r2   r'   emailr(   r(   r)   r    r   zTestEmailBlock.test_renderc                 C   r  r  r   r2  r   r   r.   rL   r(   r(   r)   r    r  z)TestEmailBlock.test_render_required_errorc                 C   r  )Nzexample.email.comr4  rL   r(   r(   r)   test_format_validation  r  z%TestEmailBlock.test_format_validationc                 C   r   )Nc                 S      |  ds	tdd S )Nz@example.comz'E-mail address must end in @example.com)endswithr   r#   r(   r(   r)   validate_is_example_domain     
zMTestEmailBlock.test_render_with_validator.<locals>.validate_is_example_domainr   zfoo@example.netr4  )r2   r8  r'   r(   r(   r)   r/    r   z)TestEmailBlock.test_render_with_validatorN)r5   r6   r7   r  r  r5  r/  r(   r(   r(   r)   r1    s
    r1  c                   @   r\   )TestBooleanBlockc                 C   s<   t jdd}|d}| |d |d}| |d d S )NFr   T)r   BooleanBlockr   rE   r   r(   r(   r)   test_get_form_state  s
   

z$TestBooleanBlock.test_get_form_stateN)r5   r6   r7   r<  r(   r(   r(   r)   r:    r`   r:  c                   @      e Zd Zdd Zdd ZdS )TestBlockQuoteBlockc                 C   s"   t  }|d}| |d d S )NzNow is the time...z+<blockquote>Now is the time...</blockquote>)r   BlockQuoteBlockr   r   )r2   r'   quoter(   r(   r)   r    r   zTestBlockQuoteBlock.test_renderc                 C   r   )Nc                 S   r6  )NzOnce upon a timezValue must be a proper story)r   r   r#   r(   r(   r)   validate_is_proper_story  r9  zPTestBlockQuoteBlock.test_render_with_validator.<locals>.validate_is_proper_storyr   zA long, long time ago)r   r?  r   r   r.   )r2   rA  r'   r(   r(   r)   r/    r   z.TestBlockQuoteBlock.test_render_with_validatorN)r5   r6   r7   r  r/  r(   r(   r(   r)   r>    s    r>  c                   @   r  )TestFloatBlockc                 C   *   t  }|td}| t|t d S NGz?)r   
FloatBlockr  floatr   r  r2   r'   	block_valr(   r(   r)   r       zTestFloatBlock.test_typec                 C   *   t  }td}||}| || d S rD  )r   rF  rG  r  r   r2   r'   test_valrI  r(   r(   r)   r    s   
zTestFloatBlock.test_renderc                 C   r  r  r   rF  r   r   r.   rL   r(   r(   r)   test_raises_required_error  r  z)TestFloatBlock.test_raises_required_errorc                 C   r  Nr  r   z20.01rN  rL   r(   r(   r)   &test_raises_max_value_validation_error  r$  z5TestFloatBlock.test_raises_max_value_validation_errorc                 C   r  Nr  r%  z19.99rN  rL   r(   r(   r)   &test_raises_min_value_validation_error  r$  z5TestFloatBlock.test_raises_min_value_validation_errorc                 C   r   )Nc                 S   r)  r*  r   r#   r(   r(   r)   r+    r,  zCTestFloatBlock.test_render_with_validator.<locals>.validate_is_evenr   3.0rN  r.  r(   r(   r)   r/    r   z)TestFloatBlock.test_render_with_validatorN)	r5   r6   r7   r  r  rO  rQ  rS  r/  r(   r(   r(   r)   rB    s    rB  c                   @   sT   e Z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 )TestDecimalBlockc                 C   rC  Nz1.63)r   DecimalBlockr  r   r   r  rH  r(   r(   r)   r    rJ  zTestDecimalBlock.test_typec                 C   r  rV  )r   rW  r   r   r  r   rH  r(   r(   r)   test_type_to_python  s
   z$TestDecimalBlock.test_type_to_pythonc                 C       t  }|d }| | d S r<   )r   rW  r   assertIsNonerH  r(   r(   r)   &test_type_to_python_decimal_none_value#     
z7TestDecimalBlock.test_type_to_python_decimal_none_valuec                 C   rK  rD  )r   rW  r   r  r   rL  r(   r(   r)   r  (  s   
zTestDecimalBlock.test_renderc                 C   r  r  r   rW  r   r   r.   rL   r(   r(   r)   rO  /  r  z+TestDecimalBlock.test_raises_required_errorc                 C   r  rP  r]  rL   r(   r(   r)   rQ  5  r$  z7TestDecimalBlock.test_raises_max_value_validation_errorc                 C   r  rR  r]  rL   r(   r(   r)   rS  ;  r$  z7TestDecimalBlock.test_raises_min_value_validation_errorc                 C   r   )Nc                 S   r)  r*  r   r#   r(   r(   r)   r+  B  r,  zETestDecimalBlock.test_render_with_validator.<locals>.validate_is_evenr   rT  r]  r.  r(   r(   r)   r/  A  r   z+TestDecimalBlock.test_render_with_validatorc                 C   sT   t  }td}tj||td}|t|}| 	t
|t | 	|| d S )NrE  r   )r   rW  r   jsondumpsr   r   r   loadsr   r  )r2   r'   original_valuedb_valuerestored_valuer(   r(   r)   $test_round_trip_to_db_preserves_typeK  s   
z5TestDecimalBlock.test_round_trip_to_db_preserves_typeN)r5   r6   r7   r  rX  r[  r  rO  rQ  rS  r/  re  r(   r(   r(   r)   rU    s    
rU  c                   @   r  )TestRegexBlockc                 C   s*   t jdd}d}||}| || d S )N
^[0-9]{3}$regex123)r   
RegexBlockr  r   rL  r(   r(   r)   r  W  s   
zTestRegexBlock.test_renderc                 C   T   t jdd}| t}|d W d    n1 sw   Y  | d|jj d S )Nrg  rh  r  This field is required.r   rk  r   r   r.   r   	exceptionmessagesr2   r'   rW   r(   r(   r)   rO  ^  
   z)TestRegexBlock.test_raises_required_errorc                 C   ^   d}t jdd|id}| t}|d W d    n1 s w   Y  | ||jj d S )NzOops, you missed a bit.rg  r   ri  error_messagesr  rn  r2   test_messager'   rW   r(   r(   r)   !test_raises_custom_required_errorf  s   z0TestRegexBlock.test_raises_custom_required_errorc                 C   rl  )Nrg  rh  [/]zEnter a valid value.rn  rq  r(   r(   r)   test_raises_validation_errort  rr  z+TestRegexBlock.test_raises_validation_errorc                 C   rs  )Nz Not a valid library card number.rg  invalidrt  ry  rn  rv  r(   r(   r)    test_raises_custom_error_message|  s   z/TestRegexBlock.test_raises_custom_error_messagec                 C   sR   dd }t jd|gd}| t |d W d    d S 1 s"w   Y  d S )Nc                 S   r   r   r   r#   r(   r(   r)   r     r   zBTestRegexBlock.test_render_with_validator.<locals>.validate_is_fooz^.*$)ri  r   rO   )r   rk  r   r   r.   r   r(   r(   r)   r/    s
   "z)TestRegexBlock.test_render_with_validatorN)	r5   r6   r7   r  rO  rx  rz  r|  r/  r(   r(   r(   r)   rf  V  s    rf  c                   @   s   e Zd Zdg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 )'TestRichTextBlock	test.jsonc                 C   s*   t   }| |t | |jd d S r  r   RichTextBlockget_defaultr   r   r   sourcer2   default_valuer(   r(   r)   $test_get_default_with_fallback_value  s   z6TestRichTextBlock.test_get_default_with_fallback_valuec                 C   s.   t jd d }| |t | |jd d S Nrc   r  r  r  r(   r(   r)   "test_get_default_with_default_none     z4TestRichTextBlock.test_get_default_with_default_nonec                 C   .   t jdd }| |t | |jd d S Nr  rc   r  r  r(   r(   r)   "test_get_default_with_empty_string  r  z4TestRichTextBlock.test_get_default_with_empty_stringc                 C   r  Nz
<p>foo</p>rc   r  r  r(   r(   r)   %test_get_default_with_nonempty_string  r  z7TestRichTextBlock.test_get_default_with_nonempty_stringc                 C   s2   t jtdd }| |t | |jd d S r  )r   r  r   r  r   r   r  r  r(   r(   r)   $test_get_default_with_richtext_value  s   z6TestRichTextBlock.test_get_default_with_richtext_valuec                 C   s*   t  }td}||}| |d d S )Nz5<p>Merry <a linktype="page" id="4">Christmas</a>!</p>z8<p>Merry <a href="/events/christmas/">Christmas</a>!</p>)r   r  r   r   r   r2   r'   r$   resultr(   r(   r)   r    s   
zTestRichTextBlock.test_renderc                 C   s~   ddl m} tjdd}|d t |}| |d d | |d | | |d dd	d
d|j	|j
ddddid	 d S )Nr   )CustomRichTextAreacustom)editortest_richtextblockr   r   z:w-field w-field--char_field w-field--custom_rich_text_areapilcrowTest richtextblockr  Tr   r   )	r   r   r   r   r   r   r   r   r   )wagtail.test.testapp.rich_textr  r   r  r   r   r   r   r   rK   ru   )r2   r  r'   r   r(   r(   r)   test_adapter  s&   
zTestRichTextBlock.test_adapterc                 C   sz   ddl m} t }|d t |}| |d d | |d | | |d dddd	|j	|j
d
dddid	 d S )Nr   DraftailRichTextArear  r   r   r  r  Tr  <w-field w-field--char_field w-field--draftail_rich_text_areaFr   r   r   wagtail.admin.rich_textr  r   r  r   r   r   r   r   rK   ru   r2   r  r'   r   r(   r(   r)   test_adapter_with_draftail  s&   
z,TestRichTextBlock.test_adapter_with_draftailc                 C   s   ddl m} tjdd}|d t |}| |d d | |d | | |d dd	d
d|j	|j
ddddidd
 d S )Nr   r  i  
max_lengthr  r   r   r  r  Tr  r  Fr   r   )
r   r   r   r   r   r   r   r   r   	maxLengthr  r  r(   r(   r)   test_adapter_with_max_length  s(   
z.TestRichTextBlock.test_adapter_with_max_lengthc                 C   sF   t  }| t |td W d    d S 1 sw   Y  d S r  r   r  r   r   r.   r   rL   r(   r(   r)   %test_validate_required_richtext_block  s   "z7TestRichTextBlock.test_validate_required_richtext_blockc                 C   s8   t jdd}|td}| |t | |jd d S )NFr   r  )r   r  r.   r   r   r   r  r2   r'   r  r(   r(   r)   )test_validate_non_required_richtext_block
  s   z;TestRichTextBlock.test_validate_non_required_richtext_blockc                 C   T   dd }t j|gd}| t |td W d    d S 1 s#w   Y  d S )Nc                 S      d| vrt dd S Nr"   zValue must contain 'foo'r   r#   r(   r(   r)   validate_contains_foo  r   zKTestRichTextBlock.test_render_with_validator.<locals>.validate_contains_foor   
<p>bar</p>r  r2   r  r'   r(   r(   r)   r/    
   "z,TestRichTextBlock.test_render_with_validatorc                 C   sd   t jdd}|td | t |td W d    n1 s$w   Y  |td d S )Nr  r  z<p>short</p>z*<p>this exceeds the 20 character limit</p>zJ<p><a href="http://really-long-domain-name.example.com">also</a> short</p>)r   r  r.   r   r   r   rL   r(   r(   r)   test_validate_max_length  s   z*TestRichTextBlock.test_validate_max_lengthc                 C   ,   t  }td}||}| |dg d S )N<p>Merry <a linktype="page" id="4">Christmas</a>! &amp; a happy new year</p>
<p>Our Santa pet <b>Wagtail</b> has some cool stuff in store for you all!</p>zdMerry Christmas! & a happy new year 
Our Santa pet Wagtail has some cool stuff in store for you all!r   r  r   r   r   r  r(   r(   r)   test_get_searchable_content(  s   
z-TestRichTextBlock.test_get_searchable_contentc                 C   s.   t jdd}td}||}| |g  d S )NFr   r  r  r  r(   r(   r)   (test_search_index_get_searchable_content7  s   
z:TestRichTextBlock.test_search_index_get_searchable_contentc                 C   r  )Nz#<p>mashed</p><p>po<i>ta</i>toes</p>zmashed potatoesr  r  r(   r(   r)   &test_get_searchable_content_whitespaceC  s   
z8TestRichTextBlock.test_get_searchable_content_whitespacec                 C   s4   t  }td}| t||tdddfg d S )Nz6<a linktype="page" id="1">Link to an internal page</a>1r  )r   r  r   r   listextract_referencesr   r2   r'   r$   r(   r(   r)   test_extract_referencesI  s   $z)TestRichTextBlock.test_extract_referencesc              	   C   sn   t  }dtdfD ]*}| j|d ||}| |t | |jd W d    n1 s/w   Y  q
d S )NHello, worldr#   )r   r  r   rt   rG   r   r   r  r2   r'   r$   
normalizedr(   r(   r)   rI   O  s   
z TestRichTextBlock.test_normalizeN)r5   r6   r7   fixturesr  r  r  r  r  r  r  r  r  r  r  r/  r  r  r  r  r  rI   r(   r(   r(   r)   r}    s(    
r}  c                   @      e Z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'd( Zd)d* Zd+d, Zd-d. Zd/S )0TestChoiceBlockc                 C      ddl m} |d d | _d S Nr   )BLANK_CHOICE_DASHr   django.db.models.fieldsr  blank_choice_dash_labelr2   r  r(   r(   r)   setUpY     zTestChoiceBlock.setUpc                 C   s   t jddgd}|d t |}| |d d | |d tj | t	|d j
g d | |d d	d
dd|j|jddddid	 d S )NteaTeacoffeeCoffeer   r   r   r   r  z	---------r  r  r   r   r  Tr   r   r   r   r   )r   r   r   r   r   r   r   r   r   r  r   rK   ru   r   r(   r(   r)   test_adapt_choice_block^  s,   
z'TestChoiceBlock.test_adapt_choice_blockc                 C   &   t jddgdd}| | d d S Nr  r  r  )r   rd   )r   r   r   r  rL   r(   r(   r)   test_choice_block_with_defaulty     z.TestChoiceBlock.test_choice_block_with_defaultc                 C   sZ   dd }t j|d}|d t |}| |d tj | t	|d j
g d d S )Nc                   S      ddgS Nr  r  r(   r(   r(   r(   r)   callable_choices  r  zWTestChoiceBlock.test_adapt_choice_block_with_callable_choices.<locals>.callable_choicesr   r   r   r  )r   r   r   r   r   r   r   r   r   r  r   r2   r  r'   r   r(   r(   r)   -test_adapt_choice_block_with_callable_choices  s   
z=TestChoiceBlock.test_adapt_choice_block_with_callable_choicesc                 C   s   t jddgd}| |dd | t |d W d    n1 s&w   Y  | t |d W d    n1 s@w   Y  | t |d  W d    d S 1 s[w   Y  d S Nr  r  r   r  whiskyr  r   r   r   r.   r   r   rL   r(   r(   r)   #test_validate_required_choice_block  s   "z3TestChoiceBlock.test_validate_required_choice_blockc                 C   >   t jddgdd}|d t |}| |d d  d S Nr  r  Fr   r   r   r   r   )r   r   r   r   r   assertFalser   r(   r(   r)   $test_adapt_non_required_choice_block     
z4TestChoiceBlock.test_adapt_non_required_choice_blockc                 C   s   t jddgdd}| |dd | t |d W d    n1 s'w   Y  | |dd | |d d d S Nr  r  Fr  r  r  r  r  rL   r(   r(   r)   'test_validate_non_required_choice_block  s   z7TestChoiceBlock.test_validate_non_required_choice_blockc                 C   F   t jg ddd}|d t |}| t|d jg d d S Nr  r  r  z	No thanksFr  r   r   r   r   r   r   r   r   r  r   r   r(   r(   r)   2test_adapt_choice_block_with_existing_blank_choice     
zBTestChoiceBlock.test_adapt_choice_block_with_existing_blank_choicec                 C   J   dd }t j|dd}|d t |}| t|d jg d d S )Nc                   S      g dS Nr  r(   r(   r(   r(   r)   r    r  zvTestChoiceBlock.test_adapt_choice_block_with_existing_blank_choice_and_with_callable_choices.<locals>.callable_choicesFr  r   r   r  r  r  r(   r(   r)   Ltest_adapt_choice_block_with_existing_blank_choice_and_with_callable_choices     
z\TestChoiceBlock.test_adapt_choice_block_with_existing_blank_choice_and_with_callable_choicesc                 C   sf   t jdddgfdddgfgd}|d t |}| t|d	 jd
dddgfdddgfg d S )N	AlcoholicginGinr  WhiskyNon-alcoholicr  r  r   r   r   r  r  r   r(   r(   r)   &test_named_groups_without_blank_option  s<   
z6TestChoiceBlock.test_named_groups_without_blank_optionc                 C   v   t jdddgfdddgfddgfgd	d
}|d t |}| t|d jdddgfdddgfddgfg d S Nr  r  r  r  r  r  zNot thirstyr  Fr  r   r   r  r   r(   r(   r)   #test_named_groups_with_blank_option  s@   
z3TestChoiceBlock.test_named_groups_with_blank_optionc                 C   sp   G dd dt j}|dd}|d t |}| t|d jg d | | dg d	d
gddf d S )Nc                   @      e Zd ZddgZdS )z=TestChoiceBlock.test_subclassing.<locals>.BeverageChoiceBlockr  r  Nr5   r6   r7   r   r(   r(   r(   r)   BeverageChoiceBlock+      r  Fr   r   r   r  wagtail.blocks.ChoiceBlockr  r  r  	r   r   r   r   r   r   r  r   deconstruct)r2   r  r'   r   r(   r(   r)   test_subclassing*  s"   


z TestChoiceBlock.test_subclassingc                 C   (   t jddgd}| |ddg d S Nr   r   r   r   r   r   r   r   r   rL   r(   r(   r)   r   L     z'TestChoiceBlock.test_searchable_contentc                 C   (   t jddgdd}| |dg  d S Nr   r   F)r   r   r   r	  rL   r(   r(   r)   r   U     z4TestChoiceBlock.test_search_index_searchable_contentc                 C   ,   dd }t j|d}| |ddg d S )Nc                   S   r  Nr   r   r(   r(   r(   r(   r)   r  `     zWTestChoiceBlock.test_searchable_content_with_callable_choices.<locals>.callable_choicesr   r   r   r	  r2   r  r'   r(   r(   r)   -test_searchable_content_with_callable_choices_     z=TestChoiceBlock.test_searchable_content_with_callable_choicesc                 C   :   t jdddgfdddgfgd}| |ddd	g d S 
N	Section 1)1-1Block 1)1-2Block 2	Section 2)2-1r  )2-2r  r   r  r  r	  rL   r(   r(   r)    test_optgroup_searchable_contenti     z0TestChoiceBlock.test_optgroup_searchable_contentc                 C   &   t jddgd}| |dg  d S N)oneOne)twoTwor   threer	  rL   r(   r(   r)   test_invalid_searchable_content~     z/TestChoiceBlock.test_invalid_searchable_contentc                 C   L   t jdtdfdtdfgd}|d}tt|}| |dg d S Nr   r   r   r   r   r   r   _r   r_  ra  r`  r   r  r(   r(   r)   -test_searchable_content_with_lazy_translation     


z=TestChoiceBlock.test_searchable_content_with_lazy_translationc                 C   v   t jtddtdfdtdfgftddtdfdtdfgfgd	}|d}tt|}| |ddg d S 
Nr  r  r  r  r  r  r  r  r   r+  r  r(   r(   r)   6test_optgroup_searchable_content_with_lazy_translation      




zFTestChoiceBlock.test_optgroup_searchable_content_with_lazy_translationc                 C   sf   dd }t j|dd}|d t |}| t|d jg d | | dg |ddf d S )	Nc                   S   r  r  r(   r(   r(   r(   r)   r    r  zPTestChoiceBlock.test_deconstruct_with_callable_choices.<locals>.callable_choicesFr  r   r   r  r  r  r  r(   r(   r)   &test_deconstruct_with_callable_choices  s"   
	z6TestChoiceBlock.test_deconstruct_with_callable_choicesc                 C   Z   ddg}dd }t j||gd}| t |d W d    d S 1 s&w   Y  d S )Nr  r  c                 S      t dNzYou must select 'tea'r   r#   r(   r(   r)   validate_tea_is_selected  r  zLTestChoiceBlock.test_render_with_validator.<locals>.validate_tea_is_selectedr   r   r  )r   r   r   r   r.   r2   r   r7  r'   r(   r(   r)   r/       "z*TestChoiceBlock.test_render_with_validatorc                 C   s,   t jddgd}|d}| |dg d S )Nr  r  r   r  )r   r   r   r   r   r(   r(   r)   r<    s   
z#TestChoiceBlock.test_get_form_statec                 C   s0   t jddgtjd}|d}| |dg d S )Nr  r  r   widgetr  )r   r   r   RadioSelectr   r   r   r(   r(   r)   %test_get_form_state_with_radio_widget  s
   

z5TestChoiceBlock.test_get_form_state_with_radio_widgetN)r5   r6   r7   r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r  r'  r-  r1  r3  r/  r<  r>  r(   r(   r(   r)   r  X  s0    
,/"	

	!r  c                   @   r  )0TestMultipleChoiceBlockc                 C   r  r  r  r  r(   r(   r)   r    r  zTestMultipleChoiceBlock.setUpc                 C   s   t jddgd}|d t |}| |d d | |d tj | t	|d j
ddg | |d dd	d
d|j|jdd
ddid	 d S )Nr  r  r   r   r   r   r   r   r  Tr   z?w-field w-field--multiple_choice_field w-field--select_multipler   r   r   )r   MultipleChoiceBlockr   r   r   r   r   r   r   r  r   rK   ru   r   r(   r(   r)    test_adapt_multiple_choice_block  s.   
z8TestMultipleChoiceBlock.test_adapt_multiple_choice_blockc                 C   r  r  )r   r@  r   r  rL   r(   r(   r)   'test_multiple_choice_block_with_default  r  z?TestMultipleChoiceBlock.test_multiple_choice_block_with_defaultc                 C   sZ   dd }t j|d}|d t |}| |d tj | t	|d j
ddg d S )Nc                   S   r  r  r(   r(   r(   r(   r)   r    r  zhTestMultipleChoiceBlock.test_adapt_multiple_choice_block_with_callable_choices.<locals>.callable_choicesr   r   r   r  r  )r   r@  r   r   r   r   r   r   r   r  r   r  r(   r(   r)   6test_adapt_multiple_choice_block_with_callable_choices  s   
zNTestMultipleChoiceBlock.test_adapt_multiple_choice_block_with_callable_choicesc                 C   s   t jddgd}| |dgdg | t |dg W d    n1 s)w   Y  | t |d W d    n1 sCw   Y  | t |d  W d    d S 1 s^w   Y  d S r  r   r@  r   r.   r   r   rL   r(   r(   r)   ,test_validate_required_multiple_choice_block!  s   "zDTestMultipleChoiceBlock.test_validate_required_multiple_choice_blockc                 C   r  r  )r   r@  r   r   r   r  r   r(   r(   r)   -test_adapt_non_required_multiple_choice_block0  r  zETestMultipleChoiceBlock.test_adapt_non_required_multiple_choice_blockc                 C   s   t jddgdd}| |dgdg | t |dg W d    n1 s*w   Y  | |dg  | |d g  d S r  rD  rL   r(   r(   r)   0test_validate_non_required_multiple_choice_block:  s   zHTestMultipleChoiceBlock.test_validate_non_required_multiple_choice_blockc                 C   r  r  r   r@  r   r   r   r   r  r   r   r(   r(   r)   ;test_adapt_multiple_choice_block_with_existing_blank_choiceF  r  zSTestMultipleChoiceBlock.test_adapt_multiple_choice_block_with_existing_blank_choicec                 C   r  )Nc                   S   r  r  r(   r(   r(   r(   r)   r  W  r  zTestMultipleChoiceBlock.test_adapt_multiple_choice_block_with_existing_blank_choice_and_with_callable_choices.<locals>.callable_choicesFr  r   r   r  rH  r  r(   r(   r)   Utest_adapt_multiple_choice_block_with_existing_blank_choice_and_with_callable_choicesT  r  zmTestMultipleChoiceBlock.test_adapt_multiple_choice_block_with_existing_blank_choice_and_with_callable_choicesc                 C   sd   t jdddgfdddgfgd}|d t |}| t|d	 jdddgfdddgfg d S )
Nr  r  r  r  r  r  r   r   r   rH  r   r(   r(   r)   r  d  s:   
z>TestMultipleChoiceBlock.test_named_groups_without_blank_optionc                 C   r  r  rH  r   r(   r(   r)   r    s@   
z;TestMultipleChoiceBlock.test_named_groups_with_blank_optionc                 C   sp   G dd dt j}|dd}|d t |}| t|d jddg | | d	g ddgdd
f d S )Nc                   @   r  )zMTestMultipleChoiceBlock.test_subclassing.<locals>.BeverageMultipleChoiceBlockr  r  Nr   r(   r(   r(   r)   BeverageMultipleChoiceBlock  r  rK  Fr   r   r   r  r  "wagtail.blocks.MultipleChoiceBlockr  	r   r@  r   r   r   r   r  r   r  )r2   rK  r'   r   r(   r(   r)   r    s&   

	z(TestMultipleChoiceBlock.test_subclassingc                 C   r  r  r   r@  r   r   rL   r(   r(   r)   r     r
  z/TestMultipleChoiceBlock.test_searchable_contentc                 C   r  r  rN  rL   r(   r(   r)   r     r  z<TestMultipleChoiceBlock.test_search_index_searchable_contentc                 C   r  )Nc                   S   r  r  r(   r(   r(   r(   r)   r    r  z_TestMultipleChoiceBlock.test_searchable_content_with_callable_choices.<locals>.callable_choicesr   r   r   rN  r  r(   r(   r)   r    r  zETestMultipleChoiceBlock.test_searchable_content_with_callable_choicesc                 C   r  r  rN  rL   r(   r(   r)   r    r  z8TestMultipleChoiceBlock.test_optgroup_searchable_contentc                 C   r   r!  rN  rL   r(   r(   r)   r'    r(  z7TestMultipleChoiceBlock.test_invalid_searchable_contentc                 C   r)  r*  r   r@  r,  r   r_  ra  r`  r   r  r(   r(   r)   r-    r.  zETestMultipleChoiceBlock.test_searchable_content_with_lazy_translationc                 C   r/  r0  rO  r  r(   r(   r)   r1  &  r2  zNTestMultipleChoiceBlock.test_optgroup_searchable_content_with_lazy_translationc                 C   sf   dd }t j|dd}|d t |}| t|d jddg | | d	g |ddf d S )
Nc                   S   r  r  r(   r(   r(   r(   r)   r  @  r  zXTestMultipleChoiceBlock.test_deconstruct_with_callable_choices.<locals>.callable_choicesFr  r   r   r  r  rL  rM  r  r(   r(   r)   r3  ?  s&   
z>TestMultipleChoiceBlock.test_deconstruct_with_callable_choicesc                 C   r4  )Nr  r  c                 S   r5  r6  r   r#   r(   r(   r)   r7  e  r  zTTestMultipleChoiceBlock.test_render_with_validator.<locals>.validate_tea_is_selectedr8  r  )r   r@  r   r   r.   r9  r(   r(   r)   r/  _  r:  z2TestMultipleChoiceBlock.test_render_with_validatorc                 C   s2   t jddgd}|ddg}| |ddg d S )Nr  r  r   r  r  )r   r@  r   r   r   r(   r(   r)   r<  o  s
   z+TestMultipleChoiceBlock.test_get_form_statec                 C   s6   t jddgtjd}|ddg}| |ddg d S )Nr  r  r;  r  r  )r   r   r   CheckboxSelectMultipler   r   r   r(   r(   r)   (test_get_form_state_with_checkbox_widgetv  s   z@TestMultipleChoiceBlock.test_get_form_state_with_checkbox_widgetN)r5   r6   r7   r  rA  rB  rC  rE  rF  rG  rI  rJ  r  r  r  r   r   r  r  r'  r-  r1  r3  r/  r<  rQ  r(   r(   r(   r)   r?    s0    
+.!	

	 r?  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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 )TestRawHTMLBlockc                 C   s(   t   }| |d | |t d S r  r   RawHTMLBlockr  r   r   r   r  r(   r(   r)   r    s   z5TestRawHTMLBlock.test_get_default_with_fallback_valuec                 C   s,   t jd d }| |d | |t d S r  rS  r  r(   r(   r)   test_get_default_with_none     z+TestRawHTMLBlock.test_get_default_with_nonec                 C   ,   t jdd }| |d | |t d S r  rS  r  r(   r(   r)   r    rV  z3TestRawHTMLBlock.test_get_default_with_empty_stringc                 C   rW  )N   <blink>BÖÖM</blink>rc   rS  r  r(   r(   r)   r    rV  z6TestRawHTMLBlock.test_get_default_with_nonempty_stringc                 C   2   t  }|td}| |d | |t d S NrX  )r   rT  r   r   r   assertNotIsInstancer   r  r(   r(   r)   test_serialize     zTestRawHTMLBlock.test_serializec                 C   s.   t  }|d}| |d | |t d S rZ  )r   rT  r   r   r   r   r  r(   r(   r)   test_deserialize  s   
z!TestRawHTMLBlock.test_deserializec                 C   rY  rZ  )r   rT  r   r   r   r   r   r  r(   r(   r)   r    r]  zTestRawHTMLBlock.test_renderc                 C   r}   rZ  )r   rT  r   r   r   r(   r(   r)   r<    r   z$TestRawHTMLBlock.test_get_form_statec                 C   s   t  }|d t |}| |d d | |d tj | |d j	ddd | |d dd	d
d|j
|jdd
ddid	 d S )Ntest_rawhtmlblockr   r   4010)colsrowsr   zTest rawhtmlblockr  Tcodez-w-field w-field--char_field w-field--textarear   r   r   )r   rT  r   r   r   r   r   r   TextareaattrsrK   ru   r   r(   r(   r)   
test_adapt  s&   
zTestRawHTMLBlock.test_adaptc                 C   s8   t  }|jddii dd}| |d | |t d S )NrawhtmlrX  r   )r   rT  r	  r   r   r   r  r(   r(   r)   test_form_response  s   
z#TestRawHTMLBlock.test_form_responsec                 C   sT   t  }| |ddii d | |ddii d | |ddii d d S )Nrh  ohair  nothing-herenope)r   rT  r  value_omitted_from_data
assertTruerL   r(   r(   r)   test_value_omitted_from_data  s   z-TestRawHTMLBlock.test_value_omitted_from_datac                 C   sl   t  }|td}| |d | |t | t |td W d    d S 1 s/w   Y  d S )NrX  r  )	r   rT  r.   r   r   r   r   r   r   r  r(   r(   r)   test_clean_required_field  s   "z*TestRawHTMLBlock.test_clean_required_fieldc                 C   s\   t jdd}|td}| |d | |t |td}| |d | |t d S )NFr   rX  r  )r   rT  r.   r   r   r   r   r  r(   r(   r)   test_clean_nonrequired_field  s   z-TestRawHTMLBlock.test_clean_nonrequired_fieldc                 C   r  )Nc                 S   r  r  r   r#   r(   r(   r)   r    r   zJTestRawHTMLBlock.test_render_with_validator.<locals>.validate_contains_foor   r  )r   rT  r   r   r.   r   r  r(   r(   r)   r/    r  z+TestRawHTMLBlock.test_render_with_validatorN)r5   r6   r7   r  rU  r  r  r\  r^  r  r<  rg  rj  rp  rq  rr  r/  r(   r(   r(   r)   rR    s    
	
rR  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestMetac                 C   s,   G dd dt j}| }| |jjd d S )Nc                   @      e Zd ZG dd dZdS )z:TestMeta.test_set_template_with_meta.<locals>.HeadingBlockc                   @      e Zd ZdZdS )z?TestMeta.test_set_template_with_meta.<locals>.HeadingBlock.Metaheading.htmlNr5   r6   r7   r   r(   r(   r(   r)   Meta      rx  Nr5   r6   r7   rx  r(   r(   r(   r)   HeadingBlock      r{  rv  r   r8   r   r   r   r2   r{  r'   r(   r(   r)   test_set_template_with_meta  s   z$TestMeta.test_set_template_with_metac                 C   s    t jdd}| |jjd d S )Nrv  r   r}  rL   r(   r(   r)   "test_set_template_with_constructor  rB   z+TestMeta.test_set_template_with_constructorc                 C   s0   G dd dt j}|dd}| |jjd d S )Nc                   @   rt  )zPTestMeta.test_set_template_with_constructor_overrides_meta.<locals>.HeadingBlockc                   @   ru  )zUTestMeta.test_set_template_with_constructor_overrides_meta.<locals>.HeadingBlock.Metarv  Nrw  r(   r(   r(   r)   rx    ry  rx  Nrz  r(   r(   r(   r)   r{    r|  r{  subheading.htmlr   r}  r~  r(   r(   r)   1test_set_template_with_constructor_overrides_meta  s   
z:TestMeta.test_set_template_with_constructor_overrides_metac                 C   sL   G dd dt j}G dd d|}| }| |jjd | |jjd dS )zI
        Check that having a multi-level inheritance chain works
        c                   @   rt  )z;TestMeta.test_meta_nested_inheritance.<locals>.HeadingBlockc                   @      e Zd ZdZdZdS )z@TestMeta.test_meta_nested_inheritance.<locals>.HeadingBlock.Metarv  FooN)r5   r6   r7   r   testr(   r(   r(   r)   rx        rx  Nrz  r(   r(   r(   r)   r{    r|  r{  c                   @   rt  )z>TestMeta.test_meta_nested_inheritance.<locals>.SubHeadingBlockc                   @   ru  )zCTestMeta.test_meta_nested_inheritance.<locals>.SubHeadingBlock.Metar  Nrw  r(   r(   r(   r)   rx    ry  rx  Nrz  r(   r(   r(   r)   SubHeadingBlock  r|  r  r  r  N)r   r8   r   r   r   r  )r2   r{  r  r'   r(   r(   r)   test_meta_nested_inheritance	  s
   z%TestMeta.test_meta_nested_inheritancec                 C   s   G dd dt j}G dd dt j}G dd d||}| }| |jjd | |jjd | |jjd	 | |jjd
 dS )zM
        Check that multi-inheritance and Meta classes work together
        c                   @   rt  )z7TestMeta.test_meta_multi_inheritance.<locals>.LeftBlockc                   @      e Zd ZdZdZdZdS )z<TestMeta.test_meta_multi_inheritance.<locals>.LeftBlock.Metatemplate.htmlthe bandz
Left blockN)r5   r6   r7   r   clashr   r(   r(   r(   r)   rx  !      rx  Nrz  r(   r(   r(   r)   	LeftBlock   r|  r  c                   @   rt  )z8TestMeta.test_meta_multi_inheritance.<locals>.RightBlockc                   @   r  )z=TestMeta.test_meta_multi_inheritance.<locals>.RightBlock.Metahelloz	the albumzRight blockN)r5   r6   r7   rd   r  r   r(   r(   r(   r)   rx  '  r  rx  Nrz  r(   r(   r(   r)   
RightBlock&  r|  r  c                   @   rt  )z8TestMeta.test_meta_multi_inheritance.<locals>.ChildBlockc                   @   ru  )z=TestMeta.test_meta_multi_inheritance.<locals>.ChildBlock.MetaChild blockNr5   r6   r7   r   r(   r(   r(   r)   rx  -  ry  rx  Nrz  r(   r(   r(   r)   
ChildBlock,  r|  r  r  r  r  r  N)r   r8   r   r   r   rd   r  r   )r2   r  r  r  r'   r(   r(   r)   test_meta_multi_inheritance  s   z$TestMeta.test_meta_multi_inheritanceN)r5   r6   r7   r  r  r  r  r  r(   r(   r(   r)   rs    s    rs  c                   @     e Z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'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAS )BTestStructBlockc                 C   s<   t dt  fdt  fg}| t|j ddg d S )Ntitlelink)r   rs   r8   URLBlockr   r  child_blockskeysrL   r(   r(   r)   test_initialisation?     

z#TestStructBlock.test_initialisationc                 C   6   G dd dt j}| }| t|j ddg d S )Nc                   @      e Zd Ze Ze ZdS )zDTestStructBlock.test_initialisation_from_subclass.<locals>.LinkBlockNr5   r6   r7   r   r8   r  r  r  r(   r(   r(   r)   r   J      r   r  r  r   rs   r   r  r  r  r2   r   r'   r(   r(   r)   !test_initialisation_from_subclassI     z1TestStructBlock.test_initialisation_from_subclassc                 C   B   G dd dt j}|dt  fg}| t|j g d d S )Nc                   @   r  )zOTestStructBlock.test_initialisation_from_subclass_with_extra.<locals>.LinkBlockNr  r(   r(   r(   r)   r   S  r  r   r   r  r  r   )r   rs   r8   r   r  r  r  r  r(   r(   r)   ,test_initialisation_from_subclass_with_extraR  
   z<TestStructBlock.test_initialisation_from_subclass_with_extrac                 C   F   G dd dt j}G dd d|}| }| t|j g d d S )Nc                   @   r  )zPTestStructBlock.test_initialisation_with_multiple_subclassses.<locals>.LinkBlockNr  r(   r(   r(   r)   r   ^  r  r   c                   @      e Zd Ze ZdS )zVTestStructBlock.test_initialisation_with_multiple_subclassses.<locals>.StyledLinkBlockNr5   r6   r7   r   r8   r   r(   r(   r(   r)   StyledLinkBlockb  r`   r  r  r  )r2   r   r  r'   r(   r(   r)   -test_initialisation_with_multiple_subclassses]     z=TestStructBlock.test_initialisation_with_multiple_subclasssesc                 C   Z   G dd dt j}G dd dt j}G dd d||}| }| t|j g d dS )	a'  
        The order of fields of classes with multiple parent classes is slightly
        surprising at first. Child fields are inherited in a bottom-up order,
        by traversing the MRO in reverse. In the example below,
        ``StyledLinkBlock`` will have an MRO of::

            [StyledLinkBlock, StylingMixin, LinkBlock, StructBlock, ...]

        This will result in ``classname`` appearing *after* ``title`` and
        ``link`` in ``StyleLinkBlock`.child_blocks`, even though
        ``StylingMixin`` appeared before ``LinkBlock``.
        c                   @   r  )zBTestStructBlock.test_initialisation_with_mixins.<locals>.LinkBlockNr  r(   r(   r(   r)   r   y  r  r   c                   @   r  )zETestStructBlock.test_initialisation_with_mixins.<locals>.StylingMixinNr  r(   r(   r(   r)   StylingMixin}  r`   r  c                   @   r  )zHTestStructBlock.test_initialisation_with_mixins.<locals>.StyledLinkBlockNr5   r6   r7   r   r8   r  r(   r(   r(   r)   r    r`   r  r  r  r   r  Nr  )r2   r   r  r  r'   r(   r(   r)   test_initialisation_with_mixinsk  s   z/TestStructBlock.test_initialisation_with_mixinsc                 C   sL   G dd dt j}| }||ddd}dg d}| || d S )Nc                   @   r  )z.TestStructBlock.test_render.<locals>.LinkBlockNr  r(   r(   r(   r)   r     r  r   Wagtail sitehttp://www.wagtail.orgr  r  
)z<dl><dt>title</dt><dd>Wagtail site</dd><dt>link</dt><dd>http://www.wagtail.org</dd>z</dl>)r   rs   r   r   joinassertHTMLEqual)r2   r   r'   r   expected_htmlr(   r(   r)   r    s   zTestStructBlock.test_renderc                    s^   G dd dt j G  fdddt j}| }|jddddd	d
d}| |dd	d dS )z
        The get_api_representation method of a StructBlock should invoke
        the block's get_api_representation method on each field and the
        context should be passed on.
        c                   @   rN   )zjTestStructBlock.test_get_api_representation_calls_same_method_on_fields_with_context.<locals>.ContextBlockNc                 S      || S r<   r(   rV   r(   r(   r)   get_api_representation  r  zTestStructBlock.test_get_api_representation_calls_same_method_on_fields_with_context.<locals>.ContextBlock.get_api_representationr<   r5   r6   r7   r  r(   r(   r(   r)   ContextBlock  rS   r  c                       s   e Zd Z  Z  ZdS )ziTestStructBlock.test_get_api_representation_calls_same_method_on_fields_with_context.<locals>.AuthorBlockN)r5   r6   r7   r   authorr(   r  r(   r)   AuthorBlock  s    
r  enwagtail)r   r  EnglishWagtail!r  r  r   N)r   r8   rs   r  assertDictEqual)r2   r  r'   api_representationr(   r  r)   Dtest_get_api_representation_calls_same_method_on_fields_with_context  s   
zTTestStructBlock.test_get_api_representation_calls_same_method_on_fields_with_contextc                 C   sp   G dd dt j}| }||dddd}| d| | d| | d	| | d
| | d| d S )Nc                   @   r  )z<TestStructBlock.test_render_unknown_field.<locals>.LinkBlockNr  r(   r(   r(   r)   r     r  r   r  r  r'  )r  r  imager  r  r  r  z<dt>image</dt>)r   rs   r   r   r   assertNotIn)r2   r   r'   r   r(   r(   r)   test_render_unknown_field  s   
z)TestStructBlock.test_render_unknown_fieldc                 C   sJ   G dd dt j}| }|ddd}|jd }d}| t|| d S )Nc                   @   r  )z=TestStructBlock.test_render_bound_block.<locals>.SectionBlockN)r5   r6   r7   r   r8   r  r  bodyr(   r(   r(   r)   r     r  r   r  <b>world</b>r  r  r  )r   rs   r   bound_blocksr   r=   )r2   r   r'   struct_valuebody_bound_blockexpectedr(   r(   r)   test_render_bound_block  s   
z'TestStructBlock.test_render_bound_blockc                 C   s   G dd dt j}| }|j|ddddd}| |d tj | t|d d	 | |d d
 t j	 | |d d
 j
d | |d d t j	 | |d d j
d | |d | | |d d d S )Nc                   @   r  )z8TestStructBlock.test_get_form_context.<locals>.LinkBlockNr  r(   r(   r(   r)   r     r  r   r  r  r  mylinkri  childrenr   r  r  block_definitionr   )r   rs   get_form_contextr   r   collectionsOrderedDictr   r   
BoundBlockr$   )r2   r   r'   rW   r(   r(   r)   test_get_form_context  s$   
z%TestStructBlock.test_get_form_contextc                 C   s   G dd dt j}| }|d t |}| |d d | |d dddd	|j|jd
d | t|d d |d \}}| ||j	d  | ||j	d  d S )Nc                   @   s$   e Zd ZejddZejddZdS )z-TestStructBlock.test_adapt.<locals>.LinkBlockFr   Nr  r(   r(   r(   r)   r         r   test_structblockr   r   Test structblockr  Fr   struct-block)r   r   r   r   r   r   r   r   r  r  )
r   rs   r   r   r   r   rK   ru   r   r  )r2   r   r'   r   title_field
link_fieldr(   r(   r)   rg    s(   
zTestStructBlock.test_adaptc                 C   X   G dd dt j}| }|d t |}| |d dddd|j|jd	d
d d S )Nc                   @   2   e Zd ZejddZejddZG dd dZdS )z@TestStructBlock.test_adapt_with_form_template.<locals>.LinkBlockFr   c                   @   ru  )zETestStructBlock.test_adapt_with_form_template.<locals>.LinkBlock.Metaz1tests/block_forms/struct_block_form_template.htmlNr5   r6   r7   form_templater(   r(   r(   r)   rx  &  ry  rx  N	r5   r6   r7   r   r8   r  r  r  rx  r(   r(   r(   r)   r   "      r   r  r   r  r  Fr   r  <div>Hello</div>r   r   r   r   r   r   r   formTemplater   rs   r   r   r   r   rK   ru   r2   r   r'   r   r(   r(   r)   test_adapt_with_form_template!      
z-TestStructBlock.test_adapt_with_form_templatec                 C   r  )Nc                   @   r  )zFTestStructBlock.test_adapt_with_form_template_jinja.<locals>.LinkBlockFr   c                   @   ru  )zKTestStructBlock.test_adapt_with_form_template_jinja.<locals>.LinkBlock.Metaz,tests/jinja2/struct_block_form_template.htmlNr  r(   r(   r(   r)   rx  A  ry  rx  Nr  r(   r(   r(   r)   r   =  r  r   r  r   r  r  Fr   r  r  r  r  r  r(   r(   r)   #test_adapt_with_form_template_jinja<  r  z3TestStructBlock.test_adapt_with_form_template_jinjac                 C   s6   G dd dt j}| }| }| |dd d S )Nc                   @   s$   e Zd ZejddZejddZdS )z3TestStructBlock.test_get_default.<locals>.LinkBlockTorchboxrc   http://www.torchbox.comNr  r(   r(   r(   r)   r   X  r  r   r  r  )r   rs   r  r   get)r2   r   r'   default_valr(   r(   r)   test_get_defaultW  s   z TestStructBlock.test_get_defaultc                 C   sZ   G dd dt j}| }|d t |}| |d dddd|j|jd	d
dd	 d S )Nc                   @   s*   e Zd Ze Ze ZG dd dZdS )zDTestStructBlock.test_adapt_with_help_text_on_meta.<locals>.LinkBlockc                   @   ru  )zITestStructBlock.test_adapt_with_help_text_on_meta.<locals>.LinkBlock.MetaSelf-promotion is encouragedN)r5   r6   r7   r   r(   r(   r(   r)   rx  e  ry  rx  Nr  r(   r(   r(   r)   r   a      r   r  r   r  r  Fr   r  Z<svg class="icon icon-help default" aria-hidden="true"><use href="#icon-help"></use></svg>	r   r   r   r   r   r   r   helpIconr   r  r  r(   r(   r)   !test_adapt_with_help_text_on_meta`  s"   
z1TestStructBlock.test_adapt_with_help_text_on_metac                 C   s^   G dd dt j}|dd}|d t |}| |d dddd	|j|jd
ddd	 d S )Nc                   @   r  )zHTestStructBlock.test_adapt_with_help_text_as_argument.<locals>.LinkBlockNr  r(   r(   r(   r)   r     r  r   r  r   r  r   r  Fr   r  r  r  r  r  r(   r(   r)   %test_adapt_with_help_text_as_argument  s"   

z5TestStructBlock.test_adapt_with_help_text_as_argumentc                 C   s@   G dd dt j}| }||ddd}| |dg d S )Nc                   @   r  )z:TestStructBlock.test_searchable_content.<locals>.LinkBlockNr  r(   r(   r(   r)   r     r  r   r  r  r  )r   rs   r   r   r   r2   r   r'   r   r(   r(   r)   r     s   	z'TestStructBlock.test_searchable_contentc                 C   sz   t dt  fdt  fg}|dddi d}| |d d | |d d | |t j | |jd j	t j d S )Nr  r  r  r  mylink-titlezmylink-linkr  )
r   rs   r8   r  r	  r   r   StructValuer  r'   )r2   r'   
struct_valr(   r(   r)   test_value_from_datadict  s   

z(TestStructBlock.test_value_from_datadictc                 C   sR   t dt  fdt  fg}| |ddii d | |ddii d d S )Nr  r  r  r  r  rl  rm  )r   rs   r8   r  r  rn  ro  rL   r(   r(   r)   rp    s   

z,TestStructBlock.test_value_omitted_from_datac                    sf   G dd dt j G  fdddt j}| }|ddi}| |d d d	 | |d t j d
S )zWhen returning the default value of a StructBlock (e.g. because it's
        a child of another StructBlock, and the outer value is missing that key)
        we should receive it as a StructValue, not just a plain dictc                   @      e Zd Ze Ze ZdS )zLTestStructBlock.test_default_is_returned_as_structvalue.<locals>.PersonBlockNr5   r6   r7   r   r8   
first_namesurnamer(   r(   r(   r)   PersonBlock  r  r  c                       $   e Zd Ze Z ddddZdS )zKTestStructBlock.test_default_is_returned_as_structvalue.<locals>.EventBlockEdBallsr
  r  rc   Nr5   r6   r7   r   r8   r  guest_speakerr(   r  r(   r)   
EventBlock  
    
r  r  Birthday partyr  r
  r  N)r   rs   r   r   r   r  )r2   r  event_blockeventr(   r  r)   'test_default_is_returned_as_structvalue  s   z7TestStructBlock.test_default_is_returned_as_structvaluec                    s   G dd dt j G  fdddt j}| }|ddi}|ddi}d|d	 d
< | |d	 d
 d | |d	 d
 d dS )z
        Whenever the default value of a StructBlock is invoked, it should be a distinct
        instance of the dict so that modifying it doesn't modify other places where the
        default value appears.
        c                   @   r  )zLTestStructBlock.test_default_value_is_distinct_instance.<locals>.PersonBlockNr	  r(   r(   r(   r)   r    r  r  c                       r  )zKTestStructBlock.test_default_value_is_distinct_instance.<locals>.EventBlockr  r  r  rc   Nr  r(   r  r(   r)   r    r  r  r  r  zChristmas partyMilibandr  r  r  N)r   rs   r   r   )r2   r  r  event1event2r(   r  r)   'test_default_value_is_distinct_instance  s   z7TestStructBlock.test_default_value_is_distinct_instancec                 C   sz   G dd dt j}| }|ddiddig}|d d d | t|d d d	dg | t|d
 d d	g dS )a  
        Whenever StructBlock.bulk_to_python invokes a child block's get_default method to
        fill in missing fields, it should use a separate invocation for each record so that
        we don't end up with the same instance of a mutable value on multiple records
        c                   @   &   e Zd Ze ZeejddZdS )zaTestStructBlock.test_bulk_to_python_returns_distinct_default_instances.<locals>.ShoppingListBlock	chocolaterc   Nr5   r6   r7   r   r8   shoprq   itemsr(   r(   r(   r)   ShoppingListBlock	      r#  r!  TescoAsdar   r"  caker  r   N)r   rs   bulk_to_pythonappendr   r  )r2   r#  r'   shopping_listsr(   r(   r)   6test_bulk_to_python_returns_distinct_default_instances	  s   	zFTestStructBlock.test_bulk_to_python_returns_distinct_default_instancesc                 C   s   t dt  fdt  fg}|ddd}||}| |t j | |d d |ddd}| 	t
 || W d    d S 1 sIw   Y  d S )Nr  r  r  http://www.torchbox.com/r  	not a url)r   rs   r8   r  r   r.   r   r  r   r   r   )r2   r'   r$   clean_valuer(   r(   r)   
test_clean	  s   


"zTestStructBlock.test_cleanc                 C   sv   G dd dt j}| }d dd}| t || W d    n1 s&w   Y  d dd}| ||| d S )Nc                       s4   e Zd ZejddZejddZ fddZ  Z	S )zBTestStructBlock.test_non_block_validation_error.<locals>.LinkBlockFr   c                    s0   t  |}|d s|d sttdgd|S )Npager  z$Either page or URL must be specifiedr+   )r-   r.   r   r   )r2   r$   r  r3   r(   r)   r.   7	  s   zHTestStructBlock.test_non_block_validation_error.<locals>.LinkBlock.clean)
r5   r6   r7   r   PageChooserBlockr0  r  r  r.   r:   r(   r(   r3   r)   r   3	  s    r   r  )r0  r  zhttps://wagtail.org/)r   rs   r   r   r.   r   )r2   r   r'   bad_data	good_datar(   r(   r)   test_non_block_validation_error2	  s   

z/TestStructBlock.test_non_block_validation_errorc                 C   s0   t  }|ddd}||}| |d dS )z
        Test that we are able to use value.bound_blocks within templates
        to access a child block's own HTML rendering
        Hello<i>italic</i> worldr  !<h1>Hello</h1><i>italic</i> worldNr   r   r   r   r  r(   r(   r)   +test_bound_blocks_are_available_on_templateI	  s   
z;TestStructBlock.test_bound_blocks_are_available_on_templatec                 C   s8   t  }|ddd}|j|ddid}| |d d S NBonjourmonde <i>italique</i>r  r   r   r   z/<h1 lang="fr">Bonjour</h1>monde <i>italique</i>r8  r  r(   r(   r)   $test_render_block_with_extra_contextS	  s   z4TestStructBlock.test_render_block_with_extra_contextc                 C   sB   t  }|ddd}| }| |d | }| |d dS )zZ
        The HTML representation of a StructValue should use the block's template
        r5  r6  r  r7  N)r   r   __html__r   render_as_blockr  r(   r(   r)   test_render_structvalueY	  s   z'TestStructBlock.test_render_structvaluec                 C   sR   t  }|ddd}t|}| d| | d| | d| | d| dS )a  
        The str() representation of a StructValue should NOT render the template, as that's liable
        to cause an infinite loop if any debugging / logging code attempts to log the fact that
        it rendered a template with this object in the context:
        https://github.com/wagtail/wagtail/issues/2874
        https://github.com/jazzband/django-debug-toolbar/issues/950
        r5  r6  r  z<h1>r  r  N)r   r   r=   r  r   r  r(   r(   r)   test_str_structvaluef	  s   z$TestStructBlock.test_str_structvaluec                 C   s6   t  }|ddd}|jddid}| |d d S r:  )r   r   r?  r   r  r(   r(   r)   *test_render_structvalue_with_extra_contexty	  s   z:TestStructBlock.test_render_structvalue_with_extra_contextc                 C   sZ   t  }|ddd}t|}| || | |tj | |j|j | 	|| d S )Nr5  worldr  )
r   r   copyassertIsNotr   r   r  rE   r'   r   )r2   r'   r$   copiedr(   r(   r)   test_copy_structvalue	  s   
z%TestStructBlock.test_copy_structvaluec                 C   s^   t dt  fg}| |ddi|ddi | ||ddi|ddi dS )z9Test the trivially recursive and already normalized casesr  r  N)r   rs   r8   r   rG   _to_struct_valuerL   r(   r(   r)   test_normalize_base_cases	  s   z)TestStructBlock.test_normalize_base_casesc              	   C   s   t dt dt  fdt  fgfdt t  fg}ddgg dd}||}| |t j | |d t j	 | |d d	 t j	j
 | |d d
 t j	j
 | |d t jj | |d d	 t dS )z?StructBlock.normalize should recursively normalize all childreninner_stream
inner_char	inner_intlist_of_ints)rK  r  )rL  *   )            )rJ  rM  r   r   N)r   rs   rr   r8   r  rq   rG   r   r  StreamValueStreamChild
list_block	ListValuer  r  r(   r(   r)   test_recursive_normalize	  s2   

	
z(TestStructBlock.test_recursive_normalizeN)#r5   r6   r7   r  r  r  r  r  r  r  r  r  r  rg  r  r  r  r   r  r   r  rp  r  r  r+  r/  r4  r9  r=  r@  rA  rB  rG  rI  rW  r(   r(   r(   r)   r  >  sB    
		
r  c                   @   L   e Z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 )$TestStructBlockWithCustomStructValuec                 C   s  G dd dt j}t jdt  fdt  fg|d}| t|j ddg |	ddd}| 
|| | }| 
|| |d	d
di d}| 
|| |	d	dd}||}| 
|| | |d d	 |	d	dd}| t || W d    d S 1 sw   Y  d S )Nc                   @   r\   )zSTestStructBlockWithCustomStructValue.test_initialisation.<locals>.CustomStructValuec                 S   s   |  dd|  dd S )Nr  r  r  r  r]   r(   r(   r)   joined	  s   zZTestStructBlockWithCustomStructValue.test_initialisation.<locals>.CustomStructValue.joinedN)r5   r6   r7   r[  r(   r(   r(   r)   CustomStructValue	  r`   r\  r  r  )value_classr  zhttps://myparty.co.ukr  r  r  r  r  r,  r-  )r   r  rs   r8   r  r   r  r  r  r   r   r  r	  r.   r   r   )r2   r\  r'   block_valuer  r	  r$   r.  r(   r(   r)   r  	  s<   


"z8TestStructBlockWithCustomStructValue.test_initialisationc                    s|   G dd dt j G  fdddt j}| }| t|j g d |ddd}| |  |	 }| |  d S )	Nc                   @   r\   )z_TestStructBlockWithCustomStructValue.test_initialisation_from_subclass.<locals>.LinkStructValuec                 S      |  dp	|  dS Nr0  r  rZ  r]   r(   r(   r)   r  	     zcTestStructBlockWithCustomStructValue.test_initialisation_from_subclass.<locals>.LinkStructValue.urlNr5   r6   r7   r  r(   r(   r(   r)   LinkStructValue	  r`   rc  c                       >   e Zd Ze ZejddZejddZ	G  fdddZ
dS )zYTestStructBlockWithCustomStructValue.test_initialisation_from_subclass.<locals>.LinkBlockFr   c                          e Zd Z ZdS )z^TestStructBlockWithCustomStructValue.test_initialisation_from_subclass.<locals>.LinkBlock.MetaNr5   r6   r7   r]  r(   rc  r(   r)   rx  	  ry  rx  Nr5   r6   r7   r   r8   r  r1  r0  r  r  rx  r(   rg  r(   r)   r   	  
    r   )r  r0  r  Websitehttps://website.comr  )
r   r  rs   r   r  r  r  r   r   r  )r2   r   r'   r^  r  r(   rg  r)   r  	  s   zFTestStructBlockWithCustomStructValue.test_initialisation_from_subclassc                    s~   G dd dt j G  fdddt j}G dd d|}| }| t|j g d |dd	d
di d}| |  d S )Nc                   @   r\   )zkTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.LinkStructValuec                 S   r_  r`  rZ  r]   r(   r(   r)   r  
  ra  zoTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.LinkStructValue.urlNrb  r(   r(   r(   r)   rc  
  r`   rc  c                       rd  )zeTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.LinkBlockFr   c                       re  )zjTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.LinkBlock.MetaNrf  r(   rg  r(   r)   rx  

  ry  rx  Nrh  r(   rg  r(   r)   r   
  ri  r   c                   @   r  )zkTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.StyledLinkBlockNr  r(   r(   r(   r)   r  
  r`   r  )r  r0  r  r   r  r  fullsize)zqueen-titlez
queen-linkzqueen-classnamequeen)	r   r  rs   r   r  r  r  r	  r   )r2   r   r  r'   r	  r(   rg  r)   r   
  s    
zRTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclasssesc                    s   G dd dt j G  fdddt j}G dd dt j}G dd d||}| }| t|j g d	 |d
dddd}| |  d S )Nc                   @      e Zd ZdS )z]TestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.LinkStructValueNr5   r6   r7   r(   r(   r(   r)   rc  #
      rc  c                       .   e Zd Ze Ze ZG  fdddZdS )zWTestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.LinkBlockc                       re  )z\TestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.LinkBlock.MetaNrf  r(   rg  r(   r)   rx  *
  ry  rx  Nr  r(   rg  r(   r)   r   &
      r   c                   @   r  )zZTestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.StylingMixinNr  r(   r(   r(   r)   r  -
  r`   r  c                   @   r  )z]TestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.StyledLinkBlockNr  r(   r(   r(   r)   r  0
  r`   r  r  rj  rk  googlez	full-size)r  r  r  r   )	r   r  rs   r   r  r  r  r   r   )r2   r   r  r  r'   r^  r(   rg  r)   r  "
  s    zDTestStructBlockWithCustomStructValue.test_initialisation_with_mixinsc                    sT   G dd dt j G  fdddt j}| }|ddd}|j}| |d d S )	Nc                   @   s   e Zd Zedd ZdS )zTTestStructBlockWithCustomStructValue.test_value_property.<locals>.SectionStructValuec                 S   s   d|  dd S )Nzbar %sr  r  rZ  r]   r(   r(   r)   r"   E
  s   zXTestStructBlockWithCustomStructValue.test_value_property.<locals>.SectionStructValue.fooN)r5   r6   r7   propertyr"   r(   r(   r(   r)   SectionStructValueD
  s    ru  c                       rq  )zNTestStructBlockWithCustomStructValue.test_value_property.<locals>.SectionBlockc                       re  )zSTestStructBlockWithCustomStructValue.test_value_property.<locals>.SectionBlock.MetaNrf  r(   ru  r(   r)   rx  M
  ry  rx  N)	r5   r6   r7   r   r8   r  r  r  rx  r(   rv  r(   r)   r   I
  rr  r   r  r  r  z	bar hello)r   r  rs   r   r"   r   )r2   r   r'   r  r$   r(   rv  r)   test_value_propertyC
  s   z8TestStructBlockWithCustomStructValue.test_value_propertyc                    sz   G dd dt j G  fdddt j}|dd}|ddi}||}| |d	 |i }||}| |d
 d S )Nc                   @   r\   )zZTestStructBlockWithCustomStructValue.test_render_with_template.<locals>.SectionStructValuec                 S   s   |  d}|rd| S dS )Nr  z	SUFFIX %szEMPTY TITLErZ  )r2   r  r(   r(   r)   title_with_suffixW
  s   
zlTestStructBlockWithCustomStructValue.test_render_with_template.<locals>.SectionStructValue.title_with_suffixN)r5   r6   r7   rx  r(   r(   r(   r)   ru  V
  r`   ru  c                       s*   e Zd ZejddZG  fdddZdS )zTTestStructBlockWithCustomStructValue.test_render_with_template.<locals>.SectionBlockFr   c                       re  )zYTestStructBlockWithCustomStructValue.test_render_with_template.<locals>.SectionBlock.MetaNrf  r(   rv  r(   r)   rx  `
  ry  rx  N)r5   r6   r7   r   r8   r  rx  r(   rv  r(   r)   r   ]
  s    r   z+tests/blocks/struct_block_custom_value.htmlr   r  r  z<div>SUFFIX hello</div>
z<div>EMPTY TITLE</div>
)r   r  rs   r   r   r   )r2   r   r'   r  r   r(   rv  r)   test_render_with_templateU
  s   



z>TestStructBlockWithCustomStructValue.test_render_with_templatec                    sD   G dd dt j G  fdddt j}| | ddi  dS )zUA normalized StructBlock value should be an instance of the StructBlock's value_classc                   @   rn  )zNTestStructBlockWithCustomStructValue.test_normalize.<locals>.CustomStructValueNro  r(   r(   r(   r)   r\  o
  rp  r\  c                       &   e Zd Ze ZG  fdddZdS )zNTestStructBlockWithCustomStructValue.test_normalize.<locals>.CustomStructBlockc                       re  )zSTestStructBlockWithCustomStructValue.test_normalize.<locals>.CustomStructBlock.MetaNrf  r(   r\  r(   r)   rx  u
  ry  rx  Nr5   r6   r7   r   	TextBlockr9   rx  r(   r{  r(   r)   CustomStructBlockr
      r~  r9   zShe sells sea shellsNr   r  rs   r   rG   )r2   r~  r(   r{  r)   rI   l
  s   z3TestStructBlockWithCustomStructValue.test_normalizec                    sT   G dd dt j G  fdddt j}| }t |ddi}| ||  dS )z
        If StructBlock.normalize is passed a StructValue instance that doesn't
        match the StructBlock's `value_class', it should convert the value
        to the correct class.
        c                   @   rn  )zdTestStructBlockWithCustomStructValue.test_normalize_incorrect_value_class.<locals>.CustomStructValueNro  r(   r(   r(   r)   r\  
  rp  r\  c                       rz  )zdTestStructBlockWithCustomStructValue.test_normalize_incorrect_value_class.<locals>.CustomStructBlockc                       re  )ziTestStructBlockWithCustomStructValue.test_normalize_incorrect_value_class.<locals>.CustomStructBlock.MetaNrf  r(   r{  r(   r)   rx  
  ry  rx  Nr|  r(   r{  r(   r)   r~  
  r  r~  r9   zThe quick brown foxNr  )r2   r~  r'   r$   r(   r{  r)   $test_normalize_incorrect_value_class}
  s
   zITestStructBlockWithCustomStructValue.test_normalize_incorrect_value_classN)r5   r6   r7   r  r  r  r  rw  ry  rI   r  r(   r(   r(   r)   rY  	  s    *"!rY  c                   @   r  )BTestListBlockc                 C   s   |  t|t| d S r<   )r   r  )r2   pqr(   r(   r)   assert_eq_list_values
  s   z#TestListBlock.assert_eq_list_valuesc                 C   s    t t j}| |jt j d S r<   )r   rq   r8   r   child_blockrL   r(   r(   r)   test_initialise_with_class
  s   z(TestListBlock.test_initialise_with_classc                 C   s$   t  }t |}| |j| d S r<   )r   r8   rq   r   r  )r2   r  r'   r(   r(   r)   test_initialise_with_instance
  r   z+TestListBlock.test_initialise_with_instancec                 C   s8   G dd dt j}t | }|ddddddgS )Nc                   @   r  )z'TestListBlock.render.<locals>.LinkBlockNr  r(   r(   r(   r)   r   
  r  r   Wagtailr  r  Djangohttp://www.djangoproject.com)r   rs   rq   r   r  r(   r(   r)   r   
  s   zTestListBlock.renderc                 C   $   |   }| d| | d| d S )Nz<ul>z</ul>r   r   r2   r   r(   r(   r)   test_render_uses_ul
     z!TestListBlock.test_render_uses_ulc                 C   r  )Nz<li>z</li>r  r  r(   r(   r)   test_render_uses_li
  r  z!TestListBlock.test_render_uses_lic                 C   s<   t t jdd}|ddg}| d| | d| dS )z
        The default rendering of a ListBlock should invoke the block's render method
        on each child, rather than just outputting the child value as a string.
        r   r   r   zGoodbye world!r   z<h1>Goodbye world!</h1>Nr   rq   r8   r   r   r   r(   r(   r)   *test_render_calls_block_render_on_children
  s   
z8TestListBlock.test_render_calls_block_render_on_childrenc                 C   sD   t t jdd}|jddgddid}| d| | d	| d
S )z
        Template context passed to the render method should be passed on
        to the render method of the child block.
        r   r   r   zAu revoir le monde!r   r   r   z$<h1 lang="fr">Bonjour le monde!</h1>z&<h1 lang="fr">Au revoir le monde!</h1>Nr  r   r(   r(   r)   &test_render_passes_context_to_children
  s   
z4TestListBlock.test_render_passes_context_to_childrenc                 C   sJ   G dd dt j}t | }|jddgdddd}| |ddg d	S )
z
        The get_api_representation method of a ListBlock should invoke
        the block's get_api_representation method on each child and
        the context should be passed on.
        c                   @   rN   )zjTestListBlock.test_get_api_representation_calls_same_method_on_children_with_context.<locals>.ContextBlockNc                 S   r  r<   r(   rV   r(   r(   r)   r  
  r  zTestListBlock.test_get_api_representation_calls_same_method_on_children_with_context.<locals>.ContextBlock.get_api_representationr<   r  r(   r(   r(   r)   r  
  rS   r  r  r   r   r   )r  r   r   N)r   r8   rq   r  r   r2   r  r'   r  r(   r(   r)   Ftest_get_api_representation_calls_same_method_on_children_with_context
  s   zTTestListBlock.test_get_api_representation_calls_same_method_on_children_with_contextc                 C   s   G dd dt j}t |}|d t |}| |d d | |d | | |d d d d | |d d	d
d|j|j	d ddddddddd d S )Nc                   @   r  )z+TestListBlock.test_adapt.<locals>.LinkBlockNr  r(   r(   r(   r)   r   
  r  r   test_listblockr   r   r   r  r-  Test listblockr  r   FDelete	Duplicate	Move downMove upDragAddDELETE	DUPLICATE	MOVE_DOWNMOVE_UPDRAGADDr   r   r   r   r   r   	collapsedr   
r   rs   rq   r   r   r   r   r   rK   ru   r  r(   r(   r)   rg  
  s2   

zTestListBlock.test_adaptc                 C   s   G dd dt j}t j|ddd}|d t |}| |d d | |d | | |d d d d	 | |d
 ddd|j|j	d ddddddddddd
 d S )Nc                   @   r  )z@TestListBlock.test_adapt_with_min_num_max_num.<locals>.LinkBlockNr  r(   r(   r(   r)   r     r  r   r   rO  )min_nummax_numr  r   r   r  r-  r  r  r   Fr  r  r  r  r  r  r  )
r   r   r   r   r   r   r  minNummaxNumr   r  r  r(   r(   r)   test_adapt_with_min_num_max_num  s6   
z-TestListBlock.test_adapt_with_min_num_max_numc                 C   sL   G dd dt j}t | }|ddddddg}| |ddg d S )Nc                   @   r  )z8TestListBlock.test_searchable_content.<locals>.LinkBlockNr  r(   r(   r(   r)   r   ;  r  r   r  r  r  r  r  )r   rs   rq   r   r   r  r(   r(   r)   r   :  s   z%TestListBlock.test_searchable_contentc              	   C   s`   t t  }| |ddii d | |dddddi d | |dd	ii d d S )
Nmylist-count0mylistr  r  r  )r  zmylist-0-valuezmylist-0-deletedzmylist-0-orderrl  rm  )r   rq   r8   r  rn  ro  rL   r(   r(   r)   rp  O  s$   z*TestListBlock.test_value_omitted_from_datac                 C   s   t t  }ddi}tddD ]}|d| dd| t|d| d	| d
| d| i q||i d}| |jd j	d | |jd j
d d S )Nshoppinglist-count3r   r-  shoppinglist-%d-deletedr  shoppinglist-%d-ordershoppinglist-%d-valueitem %dshoppinglist-%d-id	0000000%dshoppinglistr   zitem 100000001)r   rq   r8   rangeupdater=   r	  r   r  r$   idr2   r'   	post_datair^  r(   r(   r)   )test_id_from_form_submission_is_preservedf  s   	z7TestListBlock.test_id_from_form_submission_is_preservedc                 C   s   t t  }ddi}tddD ]}|d| dd| td| d	| d
| d| d| i q||i d}| |d d d S )Nr  r  r   r-  r  r  r  r   r  r  r  r  r  zitem 0r   rq   r8   r  r  r=   r	  r   r  r(   r(   r)   1test_ordering_in_form_submission_uses_order_fieldx  s   	z?TestListBlock.test_ordering_in_form_submission_uses_order_fieldc                 C   s~   t t  }ddi}tddD ]}|d| dd| t|d| d	| d
| d| i q||i d}| |d d d S )Nr  12r      r  r  r  r  r  r  r  r  r   zitem 2r  r  r(   r(   r)   +test_ordering_in_form_submission_is_numeric  s   	z9TestListBlock.test_ordering_in_form_submission_is_numericc                 C   s2   t jt  g dd}| t| g d d S )N)peasbeanscarrotsrc   )r   rq   r8   r   r  r  rL   r(   r(   r)   test_can_specify_default  s   z&TestListBlock.test_can_specify_defaultc                 C   sR   t t jdd}| t| dg |d t |}| |d d dS )z
        if no explicit 'default' is set on the ListBlock, it should fall back on
        a single instance of the child block in its default state.
        r  rc   test_shoppinglistblockr   N)	r   rq   r8   r   r  r  r   r   r   r   r(   r(   r)   test_default_default  s
   
z"TestListBlock.test_default_defaultc                 C   st   G dd dt j}| }|ddi}|ddi}|d d | t|d ddg | t|d dg d	S )
z
        Whenever the default value of a ListBlock is invoked, it should be a distinct
        instance of the list so that modifying it doesn't modify other places where the
        default value appears.
        c                   @   r  )zPTestListBlock.test_default_value_is_distinct_instance.<locals>.ShoppingListBlockr  rc   Nr   r(   r(   r(   r)   r#    r$  r#  r!  r%  r&  r"  r'  r  N)r   rs   r   r)  r   r  )r2   r#  r'   tesco_shoppingasda_shoppingr(   r(   r)   r    s   z5TestListBlock.test_default_value_is_distinct_instancec                 C   sn   G dd dt j}t j|dd}|d t |}| |d ddd	|j|jdd
dddddddd dS )zVform_classname from kwargs to be used as an additional class when rendering list blockc                   @   r  )zDTestListBlock.test_adapt_with_classname_via_kwarg.<locals>.LinkBlockNr  r(   r(   r(   r)   r     r  r   zspecial-list-classr   r  r-  r  r  r   Fr  r  r  r  r  r  r  r  N	r   rs   rq   r   r   r   r   rK   ru   r  r(   r(   r)   #test_adapt_with_classname_via_kwarg  s,   
z1TestListBlock.test_adapt_with_classname_via_kwargc                 C   sz   G dd dt j}G dd dt j}||}|d t |}| |d ddd	|j|jd
ddddddddd dS )zTform_classname from meta to be used as an additional class when rendering list blockc                   @   r  )zITestListBlock.test_adapt_with_classname_via_class_meta.<locals>.LinkBlockNr  r(   r(   r(   r)   r     r  r   c                   @   rt  )zOTestListBlock.test_adapt_with_classname_via_class_meta.<locals>.CustomListBlockc                   @   ru  )zTTestListBlock.test_adapt_with_classname_via_class_meta.<locals>.CustomListBlock.Metacustom-list-classNr5   r6   r7   r   r(   r(   r(   r)   rx    ry  rx  Nrz  r(   r(   r(   r)   CustomListBlock  r|  r  r  r-  r  r  r   r  Fr  r  r  r  r  r  r  r  Nr  )r2   r   r  r'   r   r(   r(   r)   (test_adapt_with_classname_via_class_meta  s.   
z6TestListBlock.test_adapt_with_classname_via_class_metac                 C   sN   t t  }|ddddddddg}||}| |jd jd d S )Nitemr"   $11111111-1111-1111-1111-111111111111r  r$   r  rO   $22222222-2222-2222-2222-222222222222r   )r   rq   r8   r   r.   r   r  r  )r2   r'   rI  cleaned_block_valr(   r(   r)   test_clean_preserves_block_ids  s    
z,TestListBlock.test_clean_preserves_block_idsc                 C   s   t jt  dd}|dg}| t}|| W d    n1 s$w   Y  | |j	 ddgi |ddg}| 
|| d S )Nr   r  r"   rp   The minimum number of items is 2rO   r   rq   r8   r   r   r   r.   r   ro  as_json_dataro  r2   r'   rI  catcherr(   r(   r)   test_min_num_validation_errors$  s   z,TestListBlock.test_min_num_validation_errorsc                 C   s   t jt  dd}|g d}| t}|| W d    n1 s%w   Y  | |j	 ddgi |ddg}| 
|| d S )Nr   r  )r"   rO   bazrp  z The maximum number of items is 2r"   rO   r  r  r(   r(   r)   test_max_num_validation_errors5  s   z,TestListBlock.test_max_num_validation_errorsc                 C   sz   t t  }|ddg}| t|d | |d d | t|jd | |jd jd | |jd j	d d S )Nr"   rO   r   r   
[0-9a-f-]+)
r   rq   r8   r   r   r   r  r$   assertRegexr  r2   r'   list_valr(   r(   r)   test_unpack_old_database_formatF  s   z-TestListBlock.test_unpack_old_database_formatc                 C   s   t t  }|ddgg dg\}}| t|d | t|d | |d d | |d d | t|jd | |jd jd | |jd j	d d S )	Nr"   rO   )xxxyyyzzzr   r-  r   r  r  )
r   rq   r8   r(  r   r   r  r$   r  r  r2   r'   list_1list_2r(   r(   r)   $test_bulk_unpack_old_database_formatU  s   z2TestListBlock.test_bulk_unpack_old_database_formatc                 C   s   t t  }|ddddddddg}| t|d | |d d | t|jd | |jd jd | |jd jd d S )	Nr  r"   r  r  rO   r  r   r   )	r   rq   r8   r   r   r   r  r$   r  r  r(   r(   r)   test_unpack_new_database_formate  s&   z-TestListBlock.test_unpack_new_database_formatc                 C   s   t t  }|ddddddddgddddgg\}}| t|d	 | t|d
 | |d d | |d d | t|jd	 | |jd jd | |jd jd d S )Nr  r"   r  r  rO   r  r  z$33333333-3333-3333-3333-333333333333r   r   r   )	r   rq   r8   r(  r   r   r  r$   r  r  r(   r(   r)   $test_bulk_unpack_new_database_format  s6   z2TestListBlock.test_bulk_unpack_new_database_formatc                 C   s   t dt t  fg}|g }|dddgf ||}||}| |d d d | t	|d d d | |d d d d d d S )Nbullet_listr"   rO   r   r  r$   r   )
r   rr   rq   r8   r   r)  r.   r   r   r   )r2   stream_blockstream_valueclean_stream_valuer  r(   r(   r)   test_assign_listblock_with_list  s   


 z-TestListBlock.test_assign_listblock_with_listc                 C   sv   t t j}|g d}| |t jj | |g d |t j|g d}| |t jj | |g d dS )z?Test normalize when trivially recursive, or already a ListValue)r   r   r   r   r-  Nr   rq   r  rG   r   rU  rV  r  r2   r'   r  r(   r(   r)   test_normalize_base_case  s   z&TestListBlock.test_normalize_base_casec                 C   s8   t t  }|g }| |t jj | |g  d S r<   r  r  r(   r(   r)   test_normalize_empty  s   
z"TestListBlock.test_normalize_emptyc                 C   sr   t t  }t |}g dgt j|g dgg}|D ]}||}| |t jj | |d g d qdS )z{
        ListBlock.normalize should recursively normalize all values passed to
        it, and return a ListValue.
        )r   r   r-  r   N)r   rq   r  rU  rV  rG   r   r  )r2   inner_list_blockr'   valuesr$   r  r(   r(   r)   rW    s   

z&TestListBlock.test_recursive_normalizeN)#r5   r6   r7   r  r  r  r   r  r  r  r  r  rg  r  r   rp  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rW  r(   r(   r(   r)   r  
  sB    "$!%&r  c                   @   s*   e Zd ZdgZdd Zdd Zdd ZdS )	TestListBlockWithFixturesr~  c                 C   sh   g d}t jj|d}tt }| d ||}W d    n1 s'w   Y  | || d S N)r   r-     rO  )pk__inr   )	r   objectsfilterr   rq   r1  assertNumQueriesr   assertSequenceEqualr2   page_idsexpected_pagesr'   pagesr(   r(   r)   .test_calls_child_bulk_to_python_when_available  s   zHTestListBlockWithFixtures.test_calls_child_bulk_to_python_when_availablec                 C   s   t t  }| d |ddgg dgg}dd |D }W d    n1 s)w   Y  | |tjjddtjjddgg tjjddgg d S )Nr   r   rO  r   c                 S      g | ]}t |qS r(   r  r&   valr(   r(   r)   
<listcomp>      zATestListBlockWithFixtures.test_bulk_to_python.<locals>.<listcomp>r  )	r   rq   r1  r  r(  r   r   r  r  )r2   r'   r  clean_resultr(   r(   r)   test_bulk_to_python  s   z-TestListBlockWithFixtures.test_bulk_to_pythonc                 C   s   t t  }tjjdd}tjjdd}| t||	dd|j
ddd|j
dgtt|j
ddftt|j
ddfg d S )N	christmasslugsaint-patrickblock1r  r  r  r$   block2)r   rq   r1  r   r  r  assertListEqualr  r  r   r  r=   r2   r'   christmas_pagesaint_patrick_pager(   r(   r)   r    s.   z1TestListBlockWithFixtures.test_extract_referencesN)r5   r6   r7   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	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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2dadb Z3dcdd Z4deS )fTestStreamBlockc                 C   <   t dt  fdt  fg}| t|j ddg d S )Nheading	paragraphr   rr   r8   r   r  r  r  rL   r(   r(   r)   r    r  z#TestStreamBlock.test_initialisationc                 C   r   )N   heading	   paragraphr#  rL   r(   r(   r)   ,test_initialisation_with_binary_string_names#  s   

z<TestStreamBlock.test_initialisation_with_binary_string_namesc                 C   r  )Nc                   @   r  )zGTestStreamBlock.test_initialisation_from_subclass.<locals>.ArticleBlockNr5   r6   r7   r   r8   r!  r"  r(   r(   r(   r)   ArticleBlock/  r  r(  r!  r"  r   rr   r   r  r  r  r2   r(  r'   r(   r(   r)   r  .  r  z1TestStreamBlock.test_initialisation_from_subclassc                 C   r  )Nc                   @   r  )zRTestStreamBlock.test_initialisation_from_subclass_with_extra.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(  8  r  r(  intror!  r"  r+  r#  r*  r(   r(   r)   r  7  r  z<TestStreamBlock.test_initialisation_from_subclass_with_extrac                 C   r  )Nc                   @   r  )zSTestStreamBlock.test_initialisation_with_multiple_subclassses.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(  C  r  r(  c                   @   r  )z\TestStreamBlock.test_initialisation_with_multiple_subclassses.<locals>.ArticleWithIntroBlockNr5   r6   r7   r   r8   r+  r(   r(   r(   r)   ArticleWithIntroBlockG  r`   r.  r,  r)  )r2   r(  r.  r'   r(   r(   r)   r  B  r  z=TestStreamBlock.test_initialisation_with_multiple_subclasssesc                 C   r  )	aO  
        The order of child blocks of a ``StreamBlock`` with multiple parent
        classes is slightly surprising at first. Child blocks are inherited in
        a bottom-up order, by traversing the MRO in reverse. In the example
        below, ``ArticleWithIntroBlock`` will have an MRO of::

            [ArticleWithIntroBlock, IntroMixin, ArticleBlock, StreamBlock, ...]

        This will result in ``intro`` appearing *after* ``heading`` and
        ``paragraph`` in ``ArticleWithIntroBlock.child_blocks``, even though
        ``IntroMixin`` appeared before ``ArticleBlock``.
        c                   @   r  )zETestStreamBlock.test_initialisation_with_mixins.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(  ^  r  r(  c                   @   r  )zCTestStreamBlock.test_initialisation_with_mixins.<locals>.IntroMixinNr-  r(   r(   r(   r)   
IntroMixinb  r`   r/  c                   @   r  )zNTestStreamBlock.test_initialisation_with_mixins.<locals>.ArticleWithIntroBlockN)r5   r6   r7   r   r8   by_liner(   r(   r(   r)   r.  e  r`   r.  )r!  r"  r+  r0  Nr)  )r2   r(  r/  r.  r'   r(   r(   r)   r  P  s   z/TestStreamBlock.test_initialisation_with_mixinsc                 C   s   t dt  fg}t |dg}d|d _t |dg}d|d _| t ||| t |dg}d|d _| t ||| d S )Nr"  )r"  r  ar   )r"  z
not a test)	r   rr   r8   rS  r  r  
BlockFieldhas_changedro  )r2   r'   initial_value
data_valuechanged_data_valuer(   r(   r)   test_field_has_changedo  s   


z&TestStreamBlock.test_field_has_changedc                 C   s`   t jdt  fgdd}t |g }| t j || W d    d S 1 s)w   Y  d S )Nr"  Tr   r   rr   r8   rS  r   r   r.   r  r(   r(   r)   *test_required_raises_an_exception_if_empty  s
   "z:TestStreamBlock.test_required_raises_an_exception_if_emptyc                 C   s\   t jdt  fgdd}|dddg}z|| W d S  t jy-   | dt j w )Nr"  Tr   r5  r  r$   %s was raised)r   rr   r8   r   r.   r   failureExceptionr  r(   r(   r)   6test_required_does_not_raise_an_exception_if_not_empty  s   zFTestStreamBlock.test_required_does_not_raise_an_exception_if_not_emptyc                 C   sV   t jdt  fgdd}t |g }z|| W d S  t jy*   | dt j w )Nr"  Fr   r;  )r   rr   r8   rS  r.   r   r<  r  r(   r(   r)   6test_not_required_does_not_raise_an_exception_if_empty  s   zFTestStreamBlock.test_not_required_does_not_raise_an_exception_if_emptyc                 C   s\   t dt  fg}t |g }| t j || W d    d S 1 s'w   Y  d S )Nr"  r8  r  r(   r(   r)   test_required_by_default  s
   "z(TestStreamBlock.test_required_by_defaultc                 C   s,   G dd dt j}| }||}||S )Nc                   @   r  )z4TestStreamBlock.render_article.<locals>.ArticleBlockN)r5   r6   r7   r   r8   r!  r  r"  r(   r(   r(   r)   r(    r  r(  )r   rr   r   r   )r2   r
  r(  r'   r$   r(   r(   r)   render_article  s   

zTestStreamBlock.render_articlec                 C   s|   G dd dt j}t d| fd| fg}|j|ddddddd	gd
ddd}| |dd
dd	dddd	g dS )z
        The get_api_representation method of a StreamBlock should invoke
        the block's get_api_representation method on each child and
        the context should be passed on.
        c                   @   rN   )zlTestStreamBlock.test_get_api_representation_calls_same_method_on_children_with_context.<locals>.ContextBlockNc                 S   r  r<   r(   rV   r(   r(   r)   r    r  zTestStreamBlock.test_get_api_representation_calls_same_method_on_children_with_context.<locals>.ContextBlock.get_api_representationr<   r  r(   r(   r(   r)   r    rS   r  r   r  r  r:  r  111111r  r  r  r  r   N)r   r8   rr   r  r   r  r  r(   r(   r)   r    s(   



zVTestStreamBlock.test_get_api_representation_calls_same_method_on_children_with_contextc                 C   sJ   |  dddddddddg}| d| | d| | d	| d S )
Nr!  My titler:  r"  zMy <i>first</i> paragraphMy second paragraphz)<div class="block-heading">My title</div>z<<div class="block-paragraph">My <i>first</i> paragraph</div>z6<div class="block-paragraph">My second paragraph</div>)r@  r   r  r(   r(   r)   r    s"   zTestStreamBlock.test_renderc                 C   sB   |  ddddddg}| d| | d| | d| d S )Nr"   r5  r:  r"  My first paragraphz5<div class="block-paragraph">My first paragraph</div>)r@  r  r   r  r(   r(   r)   test_render_unknown_type  s   z(TestStreamBlock.test_render_unknown_typec                 C   sb   t dt jddfdt  fg}|dddg}||}| d| | }| d| dS )	z
        The default rendering of a StreamBlock should invoke the block's render method
        on each child, rather than just outputting the child value as a string.
        r!  r   r   r"  r5  r:  z/<div class="block-heading"><h1>Hello</h1></div>Nr   rr   r8   r   r   r   r?  r2   r'   r$   r   r(   r(   r)   r    s   

	
z:TestStreamBlock.test_render_calls_block_render_on_childrenc                 C   sr   t dt jddfdt  fg}|dddg}|j|ddid	}| d
| |jddid	}| d
| d S )Nr!  r   r   r"  r;  r:  r   r   r   z;<div class="block-heading"><h1 lang="fr">Bonjour</h1></div>rF  rG  r(   r(   r)   r    s.   

	z6TestStreamBlock.test_render_passes_context_to_childrenc                 C   s   t dt jddfdt  fg}|dddg}|d  }| d| t|d }| d| |d  }| d| d	S )
z
        Accessing a child element of the stream (giving a StreamChild object) and rendering it
        should use the block template, not just render the value's string representation
        r!  r   r   r"  r5  r:  r   z<h1>Hello</h1>N)r   rr   r8   r   r   r   r=   r?  rG  r(   r(   r)   /test_render_on_stream_child_uses_child_template5  s   

	z?TestStreamBlock.test_render_on_stream_child_uses_child_templatec                 C   sx   t dt jddfdt  fg}|dddg}|d jdd	id
}| d| |d jdd	id
}| d| d S )Nr!  r   r   r"  r;  r:  r   r   r   r   z<h1 lang="fr">Bonjour</h1>)r   rr   r8   r   r   r   r?  rG  r(   r(   r)   .test_can_pass_context_to_stream_child_templateO  s   

	z>TestStreamBlock.test_can_pass_context_to_stream_child_templatec                 C   s  G dd dt j}| }|d t |}| |d d dd |d D }| t|d |d \}}| |d t|}| |d t j	 | |d j
d	 | |d t j	 | |d j
d
 | |d d d d | |d ddd|j|jd dd d i ddddddddd d S )Nc                   @   r  )z0TestStreamBlock.test_adapt.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(  b  r  r(  test_streamblockr   c                 S   s   g | ]
\}}|t |fqS r(   r  )r&   
group_name
group_iterr(   r(   r)   r  n  s    z.TestStreamBlock.test_adapt.<locals>.<listcomp>r   r  r!  r"  r   )r!  r"  r-  Test streamblockr   FTr  r  r  r  r  r  r  )r   r   r   r   r   r   r  r  r  blockCountsr   r   )r   rr   r   r   r   r   r   r  r   r8   namerK   ru   )r2   r(  r'   r   grouped_blocksrK  
block_iter
block_listr(   r(   r)   rg  a  sN   
zTestStreamBlock.test_adaptc              
   C   sh   t dt  fg}| |ddii d | |ddddddi d | |d	d
ii d d S )Nr!  mystream-countr  mystreamr  r  r  )rS  zmystream-0-typezmystream-0-valuezmystream-0-deletedzmystream-0-orderrl  rm  )r   rr   r8   r  rn  ro  rL   r(   r(   r)   rp    s,   
z,TestStreamBlock.test_value_omitted_from_datac                 C   s   G dd dt j}| }t |g d}| t}|| W d    n1 s)w   Y  | |j dddgiddgidi d S )	Nc                   @   r  )z>TestStreamBlock.test_validation_errors.<locals>.ValidatedBlockNr5   r6   r7   r   r8   charr  r  r(   r(   r(   r)   ValidatedBlock  r  rW  ))rV  r  rV  r"   r  r   )r  r-  blockErrorsrp  rm  zEnter a valid URL.)r   r-  )	r   rr   rS  r   r   r.   r   ro  r  r2   rW  r'   r$   r  r(   r(   r)   test_validation_errors  s"   
z&TestStreamBlock.test_validation_errorsc                 C   s   G dd dt j}|dd}t |g }| t}|| W d    n1 s)w   Y  | |j ddgi t |dg}| 	|| d S )Nc                   @   r  )zFTestStreamBlock.test_min_num_validation_errors.<locals>.ValidatedBlockNrU  r(   r(   r(   r)   rW    r  rW  r   r  rp  z The minimum number of items is 1rX  
r   rr   rS  r   r   r.   r   ro  r  ro  r[  r(   r(   r)   r    s   
z.TestStreamBlock.test_min_num_validation_errorsc                 C   s   G dd dt j}|dd}t |g d}| t}|| W d    n1 s+w   Y  | |j ddgi t |dg}| 	|| d S )	Nc                   @   r  )zFTestStreamBlock.test_max_num_validation_errors.<locals>.ValidatedBlockNrU  r(   r(   r(   r)   rW    r  rW  r   r  rX  rX  rY  rY  rp  z The maximum number of items is 1rX  r]  r[  r(   r(   r)   r    s   

z.TestStreamBlock.test_max_num_validation_errorsc                 C   s   G dd dt j}|dddiid}t |ddg}| t}|| W d    n1 s/w   Y  | |j dd	gi t |g d
}| 	|| d S )Nc                   @   r  )zOTestStreamBlock.test_block_counts_min_validation_errors.<locals>.ValidatedBlockNrU  r(   r(   r(   r)   rW    r  rW  rV  r  r   block_countsrY  rp  z&Char: The minimum number of items is 1)rY  rX  rY  r]  r[  r(   r(   r)   'test_block_counts_min_validation_errors  s(   z7TestStreamBlock.test_block_counts_min_validation_errorsc                 C   s   G dd dt j}|dddiid}t |g d}| t}|| W d    n1 s/w   Y  | |j dd	gi t |g d
}| 	|| d S )Nc                   @   r  )zOTestStreamBlock.test_block_counts_max_validation_errors.<locals>.ValidatedBlockNrU  r(   r(   r(   r)   rW    r  rW  rV  r  r   r_  r^  rp  z&Char: The maximum number of items is 1)rX  rY  rY  r]  r[  r(   r(   r)   'test_block_counts_max_validation_errors  s$   
z7TestStreamBlock.test_block_counts_max_validation_errorsc                 C   s   G dd dt j}| }ddi}tddD ]#}|d| dd	| td
| d| dd| d| d| d| i q||i d}| |d
 jd | |d
 jd d S )Nc                   @   r  )zWTestStreamBlock.test_ordering_in_form_submission_uses_order_field.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(  B  r  r(  article-countr  r   r-  article-%d-deletedr  article-%d-orderr   article-%d-typer!  article-%d-value
heading %dzarticle-%d-idz000%darticlez	heading 00000)	r   rr   r  r  r=   r	  r   r$   r  r2   r(  r'   r  r  r^  r(   r(   r)   r  A  s   
zATestStreamBlock.test_ordering_in_form_submission_uses_order_fieldc                 C   s   G dd dt j}| }ddi}tddD ]}|d| dd	| t|d
| dd| d| i q||i d}| |d jd d S )Nc                   @   r  )zQTestStreamBlock.test_ordering_in_form_submission_is_numeric.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(  Z  r  r(  rc  r  r   r  rd  r  re  rf  r!  rg  rh  ri  r   z	heading 2)r   rr   r  r  r=   r	  r   r$   rk  r(   r(   r)   r  Y  s   	z;TestStreamBlock.test_ordering_in_form_submission_is_numericc                 C   sX   G dd dt j}| }|dddddddddg}||}| |g d	 d S )
Nc                   @   r  )z=TestStreamBlock.test_searchable_content.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(  p  r  r(  r!  rB  r:  r"  rD  rC  )rB  rD  rC  )r   rr   r   r   r   )r2   r(  r'   r$   r   r(   r(   r)   r   o  s&   
z'TestStreamBlock.test_searchable_contentc                       G dd dt j G  fdddt j}| }|ddi}|d }| |t j | t|d | |d	 jd
 | |d	 j	d dS )zETest that we can specify a default value in the Meta of a StreamBlockc                   @   *   e Zd Ze Ze ZG dd dZdS )z7TestStreamBlock.test_meta_default.<locals>.ArticleBlockc                   @      e Zd ZdgZdS )z<TestStreamBlock.test_meta_default.<locals>.ArticleBlock.Metar!  A default headingNr5   r6   r7   rd   r(   r(   r(   r)   rx        
rx  Nr5   r6   r7   r   r8   r!  r"  rx  r(   r(   r(   r)   r(    r  r(  c                       s   e Zd Ze Z  ZdS )z@TestStreamBlock.test_meta_default.<locals>.ArticleContainerBlockNr5   r6   r7   r   r8   r  ri  r(   r(  r(   r)   ArticleContainerBlock  s    
rv  r  Bobri  r   r   r!  rp  N
r   rr   rs   r   r   rS  r   r   
block_typer$   r2   rv  r'   r  r  r(   ru  r)   test_meta_default     	z!TestStreamBlock.test_meta_defaultc                    rl  )zLTest that we can specify a default value in the constructor of a StreamBlockc                   @   rm  )z>TestStreamBlock.test_constructor_default.<locals>.ArticleBlockc                   @   rn  )zCTestStreamBlock.test_constructor_default.<locals>.ArticleBlock.Metaro  Nrq  r(   r(   r(   r)   rx    rr  rx  Nrs  r(   r(   r(   r)   r(    r  r(  c                       s    e Zd Ze Z dgdZdS )zGTestStreamBlock.test_constructor_default.<locals>.ArticleContainerBlock)r!  A different default headingrc   Nrt  r(   ru  r(   r)   rv    s    rv  r  rw  ri  r   r   r!  r}  Nrx  rz  r(   ru  r)   test_constructor_default  r|  z(TestStreamBlock.test_constructor_defaultc                 C   sf   t dt  fg}|dddg}|dddg}|dddg}| || | || d S )Nr9   r  r:  goodbye)r   rr   r8   r   r   assertNotEqual)r2   r'   value1value2value3r(   r(   r)   test_stream_value_equality  s   
z*TestStreamBlock.test_stream_value_equalityc           	      C   s   G dd dt j}G dd dt j}G dd dt j}G dd dt j}G d	d
 d
t j}t d| fd| fd| fd| fd| fg}|d t |}t|d }| | h d dS )z\If group attributes are set in Block Meta classes, make sure the blocks are grouped togetherc                   @   rt  )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group1Block1c                   @   ru  )zOTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group1Block1.Metagroup1Nr5   r6   r7   groupr(   r(   r(   r)   rx    ry  rx  Nrz  r(   r(   r(   r)   Group1Block1  r|  r  c                   @   rt  )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group1Block2c                   @   ru  )zOTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group1Block2.Metar  Nr  r(   r(   r(   r)   rx    ry  rx  Nrz  r(   r(   r(   r)   Group1Block2  r|  r  c                   @   rt  )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group2Block1c                   @   ru  )zOTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group2Block1.Metagroup2Nr  r(   r(   r(   r)   rx    ry  rx  Nrz  r(   r(   r(   r)   Group2Block1  r|  r  c                   @   rt  )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group2Block2c                   @   ru  )zOTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group2Block2.Metar  Nr  r(   r(   r(   r)   rx    ry  rx  Nrz  r(   r(   r(   r)   Group2Block2  r|  r  c                   @   rn  )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.NoGroupBlockNro  r(   r(   r(   r)   NoGroupBlock  rp  r  b1b2b3b4ngbrJ  r   >   r  r  r  N)	r   r8   rr   r   r   r   dictr   r  )	r2   r  r  r  r  r  r'   r   blockdefs_dictr(   r(   r)   $test_adapt_considers_group_attribute  s"   

z4TestStreamBlock.test_adapt_considers_group_attributec                 C   s  G dd dt j}| }|ji ddddddd	d
dddddddddd
ddddddddddddddi dd }| t|d! | |d" jd | |d" jd | |d" jd | |d# jd
 | |d# jd | |d# jd d S )$Nc                   @   r  )z>TestStreamBlock.test_value_from_datadict.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(    r  r(  z	foo-countr  zfoo-0-deletedr  zfoo-0-order2z
foo-0-typer!  zfoo-0-idrj  zfoo-0-valuethis is my headingzfoo-1-deletedr  zfoo-1-orderz
foo-1-typezfoo-1-id0001zfoo-1-valueza deleted headingzfoo-2-deletedzfoo-2-orderr  z
foo-2-typer"  zfoo-2-idzfoo-2-value<p>this is a paragraph</p>r"   ri  r   r   r   )r   rr   r	  r   r   ry  r  r$   )r2   r(  r'   r$   r(   r(   r)   r    s\   	
z(TestStreamBlock.test_value_from_datadictc                 C   s   G dd dt j}| }t j|||d}||}| t|d | |d dddd	 | |d
 d d | |d
 d d | |d
 d  ||}| |d d |d d  | |d
 d |d
 d  d S )Nc                   @   r  )z:TestStreamBlock.check_get_prep_value.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(    r  r(  is_lazyr   r   r!  r  rj  r  r   r  r"  r$   r  r  )r   rr   rS  r   r   r   ro  )r2   stream_datar  r(  r'   r$   r   jsonish_value_againr(   r(   r)   check_get_prep_value  s   


 z$TestStreamBlock.check_get_prep_valuec                 C   s   ddg}| j |dd d S )N)r!  r  rj  )r"  r  Fr  r  r2   r  r(   r(   r)   test_get_prep_value_not_lazy9  s   z,TestStreamBlock.test_get_prep_value_not_lazyc                 C   s(   dddddddg}| j |dd	 d S )
Nr!  r  rj  r  r"  r  r:  Tr  r  r  r(   r(   r)   test_get_prep_value_is_lazy@  s   
z+TestStreamBlock.test_get_prep_value_is_lazyc                    s   G dd dt j}|   fdd| D } |}| t|d | |d ddd	d
g | t|d d |d d }| |d d | |d d | |d  d S )Nc                   @   s4   e Zd Zede fgZede fgZdS )zPTestStreamBlock.check_get_prep_value_nested_streamblocks.<locals>.TwoColumnBlockr9   N)r5   r6   r7   r   rr   r8   leftrightr(   r(   r(   r)   TwoColumnBlockH  s    r  c                    s(   i | ]\}}|t j j| |d qS )r  )r   rS  r  )r&   kvr'   r  r(   r)   
<dictcomp>N  s    zLTestStreamBlock.check_get_prep_value_nested_streamblocks.<locals>.<dictcomp>r   r  r9   	some textrj  r  r  r   r   r  r$   some other textr  )r   rs   r"  r   r   r   ro  )r2   r  r  r  r$   r   right_blockr(   r  r)   (check_get_prep_value_nested_streamblocksG  s    
z8TestStreamBlock.check_get_prep_value_nested_streamblocksc                 C   s    dgdgd}| j |dd d S )N)r9   r  rj  )r9   r  r  r  Fr  r  r  r(   r(   r)   0test_get_prep_value_nested_streamblocks_not_lazyb  s   z@TestStreamBlock.test_get_prep_value_nested_streamblocks_not_lazyc                 C   s.   ddddgdddgd}| j |dd	 d S )
Nr9   r  rj  r  r  r:  r  Tr  r  r  r(   r(   r)   /test_get_prep_value_nested_streamblocks_is_lazyi  s   	z?TestStreamBlock.test_get_prep_value_nested_streamblocks_is_lazyc                 C   sn   G dd dt j}| }|ddddddd	dg}d
|d _||}| |ddddddd
dg d S )Nc                   @   r  )zUTestStreamBlock.test_modifications_to_stream_child_id_are_saved.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(  |  r  r(  r!  r  r  r  r"  rC  00020003r   )r   rr   r   r  r   r   r2   r(  r'   streamraw_datar(   r(   r)   /test_modifications_to_stream_child_id_are_saved{     





z?TestStreamBlock.test_modifications_to_stream_child_id_are_savedc                 C   sn   G dd dt j}| }|ddddddd	dg}d
|d _||}| |dddddd
d	dg d S )Nc                   @   r  )zXTestStreamBlock.test_modifications_to_stream_child_value_are_saved.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(    r  r(  r!  r  r  r  r"  rC  r  earthr   )r   rr   r   r$   r   r   r  r(   r(   r)   2test_modifications_to_stream_child_value_are_saved  r  zBTestStreamBlock.test_modifications_to_stream_child_value_are_savedc                 C   sl   G dd dt j}| }|ddddddd	dg}d
|d< ||}| |ddddddddg d S )Nc                   @   r  )z?TestStreamBlock.test_set_streamvalue_item.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(    r  r(  r!  r  r  r  r"  rC  r  )r!  r  r  r   r  r  r   rr   r   r   r   r  r(   r(   r)   test_set_streamvalue_item  s   




z)TestStreamBlock.test_set_streamvalue_itemc                 C   s`   G dd dt j}| }|ddddddd	dg}|d
= ||}| |ddd	dg d S )Nc                   @   r  )zBTestStreamBlock.test_delete_streamvalue_item.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(    r  r(  r!  r  r  r  r"  rC  r  r   r  r  r(   r(   r)   test_delete_streamvalue_item  s   



z,TestStreamBlock.test_delete_streamvalue_itemc              	   C   sz   G dd dt j}| }|ddddddd	dg}|d
d ||}| |ddddddddddd	dg d S )Nc                   @   r  )zBTestStreamBlock.test_insert_streamvalue_item.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(    r  r(  r!  r  r  r  r"  rC  r  r   )r"  mutabler  r  r  )r   rr   r   insertr   r   r  r(   r(   r)   test_insert_streamvalue_item  s    





z,TestStreamBlock.test_insert_streamvalue_itemc              	   C   sx   G dd dt j}| }|ddddddd	dg}|d
 ||}| |ddddddd	dddddg d S )Nc                   @   r  )zBTestStreamBlock.test_append_streamvalue_item.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(    r  r(  r!  r  r  r  r"  rC  r  )r"  of warcraftr  r  r  )r   rr   r   r)  r   r   r  r(   r(   r)   test_append_streamvalue_item  s    






z,TestStreamBlock.test_append_streamvalue_itemc                 C   s  G dd dt j}| }|ddddddd	dg}| |jd
 dddd d|jd
 d< | |jd
 dddd ||}| |ddddddd	dg | |d
 jd d|jd
 d< | |jd
 d d | |d
 jd ||}| |ddddddd	dg dddd|jd
< ||}| |ddddddd	dg | |d
 jd |jd= |jd
dddd ||}| |ddddddddg d S )Nc                   @   r  )z?TestStreamBlock.test_streamvalue_raw_data.<locals>.ArticleBlockNr'  r(   r(   r(   r)   r(    r  r(  r!  r  r  r  r"  rC  r  r   bonjourr$   z	guten tag
konnichiwar  r   zhello kitty says0004)r   rr   r   r   r  r   r$   r  r  r(   r(   r)   test_streamvalue_raw_data   sh   




	


	





z)TestStreamBlock.test_streamvalue_raw_datac                 C   sx   t jdt  fdt  fgdd}|d t |}| |d ddd	|j|jd
d
i ddddddddddd d
S )zXform_classname from kwargs to be used as an additional class when rendering stream blockr$  r%  zrocket-sectionr   rJ  r-  rM  r  r   NFTr  r  r  r  r  r  r  r   r   r   r   r   r  r  rN  r  r   r   r   )	r   rr   r8   r   r   r   r   rK   ru   r   r(   r(   r)   r  G  s<   


z3TestStreamBlock.test_adapt_with_classname_via_kwargc           	      C   s  G dd dt j}| }|dddddddddg}| }t|t jjs*J d	d
 | D }| |dgddgg d |jdd}| || d  | t	|d |D ]	}| |j
d qZ| |jddg  | |jddg  |jdd}| |j
d | |jd | |jddd  | |jddd  | }|d }| |j
d | |jd | |d d  | |d d  d S )Nc                   @   s$   e Zd Ze Ze Ze Z	dS )z6TestStreamBlock.test_block_names.<locals>.ArticleBlockN)
r5   r6   r7   r   r8   r!  r}  r"  	DateBlockdater(   r(   r(   r)   r(  o  s    r(  r!  rB  r:  r"  rD  rC  c                 S   s    i | ]\}}|d d |D qS )c                 S      g | ]}|j qS r(   r#   r%   r(   r(   r)   r        z?TestStreamBlock.test_block_names.<locals>.<dictcomp>.<listcomp>r(   )r&   
block_namer   r(   r(   r)   r    s    z4TestStreamBlock.test_block_names.<locals>.<dictcomp>)r!  r"  r  )r  r   r  invalid_type)r   rr   r   blocks_by_name
isinstancerS  BlockNameLookupr"  r   r   ry  first_block_by_namer$   rE   )	r2   r(  r'   r$   r  r  paragraph_blocksfirst_heading_blockfirst_blocks_by_namer(   r(   r)   test_block_namesn  sX   	z TestStreamBlock.test_block_namesc                 C   sn   G dd dt j}| }|d t |}| |d ddd|j|jddi d	d
ddddddddd dS )zVform_classname from meta to be used as an additional class when rendering stream blockc                   @   s"   e Zd Ze ZG dd dZdS )zNTestStreamBlock.test_adapt_with_classname_via_class_meta.<locals>.ProfileBlockc                   @   ru  )zSTestStreamBlock.test_adapt_with_classname_via_class_meta.<locals>.ProfileBlock.Metaprofile-block-largeNr  r(   r(   r(   r)   rx    ry  rx  N)r5   r6   r7   r   r8   usernamerx  r(   r(   r(   r)   ProfileBlock  s    r  rJ  r-  rM  r  r   NFTr  r  r  r  r  r  r  r  r  )r   rr   r   r   r   r   rK   ru   )r2   r  r'   r   r(   r(   r)   r    s4   
z8TestStreamBlock.test_adapt_with_classname_via_class_metaN)5r5   r6   r7   r  r&  r  r  r  r  r7  r9  r=  r>  r?  r@  r  r  rE  r  r  rH  rI  rg  rp  r\  r  r  ra  rb  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(   r(   r)   r    sf    
	

# 3!#"&'G'Cr  c                       s8   e Zd Ze fddZdd Zdd Zdd Z  ZS )	TestNormalizeStreamBlockc                    s   t    tdt fdt fg| _tdtdt fdt fdttjfgfdtdt	 fgfdttjfg| _
d S )Nnumberr9   rJ  
inner_liststructboolr  )r-   
setUpClassr   rr   r  r}  simple_blockrq   rs   r;  recursive_blockr^  r3   r(   r)   r    s"   




z#TestNormalizeStreamBlock.setUpClassc              	   C   sb   g dd g}|D ]'}| j |d | | j|t| jg  W d    n1 s)w   Y  qd S )Nr  r#   )rt   r   r  rG   r   rS  )r2   r  r$   r(   r(   r)   test_normalize_empty_stream  s   

z4TestNormalizeStreamBlock.test_normalize_empty_streamc                 C   sB   ddg}t | j|}| || j| | || j| dS )zS
        Test normalize when trivially recursive, or already a StreamValue
        r  r   )r9   ichibanN)r   rS  r  r   rG   )r2   r$   r  r(   r(   r)   r    s   z1TestNormalizeStreamBlock.test_normalize_base_casec                 C   s  dddifddddg dfgfd	g dfgdddid
dddd
ddd
dddddddddddddgd
gd
d	ddddddddddddgd
gf}|D ]}| j |dw | j|}| |d jtj | |d jd t | |d jtj | |d jd jt	 | |d jd jt
 | |d jd t	 | |d jtjj | |d jd jd t	 | |d jd jtjj W d   n1 sw   Y  qRdS )zX
        A stream block is normalized iff all of its sub-blocks are normalized.
        r  r  TrJ  r  )r9   r"  r  )r   r   r   r   r-  rO  r  r:  r  r   r9   r"  r  r   r  r   r-  r#   N)rt   r  rG   r   r$   r   r  r  rS  r  r=   rU  rV  )r2   r  r$   r  r(   r(   r)   test_normalize_recursive  s\   








.z1TestNormalizeStreamBlock.test_normalize_recursive)	r5   r6   r7   r   r  r  r  r  r:   r(   r(   r3   r)   r    s    		r  c                   @   "   e Zd ZdgZdd Zdd ZdS )TestStructBlockWithFixturesr~  c              	   C   s   t dt jddfdt jddfg}| d |dd	d
ddd
d dd
ddig}W d    n1 s7w   Y  dd |D }| |t jgd  dd |D }| |g d dd |D }| |tj	j
ddtj	j
ddd tj	j
ddg d S )Nr0  Fr   	link_textmissing titlerc   r   r   page twor0  r  r-  
page threeno pager   c                 S   r  r(   )r  r  r(   r(   r)   r  `  r  zCTestStructBlockWithFixtures.test_bulk_to_python.<locals>.<listcomp>c                 S      g | ]}|d  qS )r  r(   r  r(   r(   r)   r  c  r  )r  r  r  r  c                 S   r  )r0  r(   r  r(   r(   r)   r  h  r  r  )r   rs   r1  r8   r  r(  r   r  r   r  r  )r2   page_link_blockr  result_typesresult_titlesresult_pagesr(   r(   r)   r  N  s:   
z/TestStructBlockWithFixtures.test_bulk_to_pythonc                 C   sd   t dt jddfdt jddfg}tjjdd}| t|	|d	d
tt
|jddfg d S )Nr0  Fr   r  r  rc   r  r  	Christmasr  )r   rs   r1  r8   r   r  r  r  r  r  r=   r  r2   r'   r  r(   r(   r)   r  s  s   z3TestStructBlockWithFixtures.test_extract_referencesNr5   r6   r7   r  r  r  r(   r(   r(   r)   r  K  s    %r  c                   @   r  )TestStreamBlockWithFixturesr~  c              	   C   s\  t dt  fdt  fg}| d, |dddddddddgdddd	d
dgddddddgg}W d    n1 sCw   Y  | d dd |D }W d    n1 s_w   Y  | |g ddgddgg | d dd |D }W d    n1 sw   Y  | |dtjj	ddtjj	ddgdgdtjj	ddgg d S )Nr0  r!  r   zinteresting pagesr:  r   r-  zpages written by dogswoofz	woof woofzboring pagesr   r   c                 S      g | ]	}d d |D qS )c                 S   r  r(   )ry  r%   r(   r(   r)   r    r  NTestStreamBlockWithFixtures.test_bulk_to_python.<locals>.<listcomp>.<listcomp>r(   r&   r  r(   r(   r)   r        zCTestStreamBlockWithFixtures.test_bulk_to_python.<locals>.<listcomp>)r!  r0  r0  c                 S   r  )c                 S   r  r(   r#   r%   r(   r(   r)   r    r  r  r(   r  r(   r(   r)   r    r  r  )
r   rr   r1  r8   r  r(  r   r   r  r  )r2   r  resultsblock_typesblock_valuesr(   r(   r)   r    sP   

	z/TestStreamBlockWithFixtures.test_bulk_to_pythonc                 C   s   t dt  fdt  fg}tjjdd}tjjdd}| t|	|
ddddd	d|jdd
d|jdgtt|jdd	ftt|jdd
fg d S )Nr0  r!  r  r  r  r  zSome events that you might liker  r  block3)r   rr   r1  r8   r   r  r  r  r  r  r   r  r=   r  r(   r(   r)   r    s>   

z3TestStreamBlockWithFixtures.test_extract_referencesNr  r(   r(   r(   r)   r    s    Br  c                   @   s   e Zd Zdg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*d+ Zd,d- Zd.d/ Zd0S )1TestPageChooserBlockr~  c                 C   s>   t  }tjjdd}| |||j | |d dS )zIThe value of a PageChooserBlock (a Page object) should serialize to an IDr  r  N)	r   r1  r   r  r  r   r   r  rZ  r  r(   r(   r)   r\       z#TestPageChooserBlock.test_serializec                 C   s>   t  }tjjdd}| ||j| | |d dS )zVThe serialized value of a PageChooserBlock (an ID) should deserialize to a Page objectr  r  N)	r   r1  r   r  r  r   r   r  rZ  r  r(   r(   r)   r^    r   z%TestPageChooserBlock.test_deserializec                 C   s   ddl m} tjddd}|d t |}| |d d | |d | | |d j	t
g | |d j | |d d	dd
d|j|jddd
ddid
 d S )Nr   )AdminPageChooserpick a page, any pagezA featured page)r   r   test_pagechooserblockr   r   zTest pagechooserblockTzdoc-empty-inversez?w-field w-field--model_choice_field w-field--admin_page_chooserr   r   )
r   r   r   r   r   r   r   r   r   r   )wagtail.admin.widgets.chooserr  r   r1  r   r   r   r   r   target_modelsr   r  can_choose_rootrK   ru   )r2   r  r'   r   r(   r(   r)   rg    s0   
zTestPageChooserBlock.test_adaptc                 C   s<   t jddd}|d t |}| |d jtg d S )Nr  tests.SimplePager   	page_typer  r   )r   r1  r   r   r   r   r  r   r   r(   r(   r)   #test_adapt_with_target_model_string-     
z8TestPageChooserBlock.test_adapt_with_target_model_stringc                 C   s<   t jdtd}|d t |}| |d jtg d S Nr  r  r  r   )r   r1  r   r   r   r   r   r  r   r(   r(   r)   $test_adapt_with_target_model_literal7  r  z9TestPageChooserBlock.test_adapt_with_target_model_literalc                 C   sB   t jdddgd}|d t |}| |d jttg d S )Nr  r  tests.EventPager  r  r   )	r   r1  r   r   r   r   r  r   r   r   r(   r(   r)   -test_adapt_with_target_model_multiple_stringsA  s   
zBTestPageChooserBlock.test_adapt_with_target_model_multiple_stringsc                 C   sB   t jdttgd}|d t |}| |d jttg d S r  )	r   r1  r   r   r   r   r   r   r  r   r(   r(   r)   .test_adapt_with_target_model_multiple_literalsL  s   
zCTestPageChooserBlock.test_adapt_with_target_model_multiple_literalsc                 C   s8   t jddd}|d t |}| |d j d S )Nr  T)r   r  r  r   )r   r1  r   r   r   ro  r  r   r(   r(   r)   test_adapt_with_can_choose_rootV  s   
z4TestPageChooserBlock.test_adapt_with_can_choose_rootc                 C   sZ   t  }tjjdd}|dt|jii d}| || |ddii d}| 	| d S )Nr  r  r0  r  )
r   r1  r   r  r  r	  r=   r  r   rZ  )r2   r'   r  r$   empty_valuer(   r(   r)   rj  `  s   z'TestPageChooserBlock.test_form_responsec                 C   s   t  }t jdd}tjjdd}| ||| | t |d  W d    n1 s/w   Y  | ||| | 	|d  d S )NFr   r  r  )
r   r1  r   r  r  r   r.   r   r   rZ  )r2   required_blocknonrequired_blockr  r(   r(   r)   r/  j  s   zTestPageChooserBlock.test_cleanc                 C   s   t  }| |jt d S r<   r   r1  r   target_modelr   rL   r(   r(   r)   test_target_model_defaultv  s   z.TestPageChooserBlock.test_target_model_defaultc                 C   s   t jdd}| |jt d S )Nr  r	  )r   r1  r   r  r   rL   r(   r(   r)   test_target_model_stringz     z-TestPageChooserBlock.test_target_model_stringc                 C   s   t jtd}| |jt d S Nr  )r   r1  r   r   r  rL   r(   r(   r)   test_target_model_literal~  r  z.TestPageChooserBlock.test_target_model_literalc                 C   s"   t jddgd}| |jt d S )Nr  r  r  r  rL   r(   r(   r)   "test_target_model_multiple_strings  s   z7TestPageChooserBlock.test_target_model_multiple_stringsc                 C   s"   t jttgd}| |jt d S r  )r   r1  r   r   r   r  r   rL   r(   r(   r)   #test_target_model_multiple_literals  s   z8TestPageChooserBlock.test_target_model_multiple_literalsc                 C   s"   t  }| | ddi f d S )Nwagtail.blocks.PageChooserBlockr(   r   r1  r   r  rL   r(   r(   r)   %test_deconstruct_target_model_default     z:TestPageChooserBlock.test_deconstruct_target_model_defaultc                 C   s,   t jdd}| | ddddgif d S )Nr  r  r  r(   r	  r   rL   r(   r(   r)   $test_deconstruct_target_model_string     z9TestPageChooserBlock.test_deconstruct_target_model_stringc                 C   s,   t jtd}| | ddddgif d S )Nr  r  r(   r	  r  )r   r1  r   r   r  rL   r(   r(   r)   %test_deconstruct_target_model_literal  r$  z:TestPageChooserBlock.test_deconstruct_target_model_literalc                 C   s2   t jddgd}| | dddddgif d S )Nr  r  r  r  r(   r	  r   rL   r(   r(   r)   .test_deconstruct_target_model_multiple_strings  s   
zCTestPageChooserBlock.test_deconstruct_target_model_multiple_stringsc                 C   s2   t jttgd}| | dddddgif d S )Nr  r  r(   r	  r  r  )r   r1  r   r   r   r  rL   r(   r(   r)   /test_deconstruct_target_model_multiple_literals  s   
zDTestPageChooserBlock.test_deconstruct_target_model_multiple_literalsc                 C   sb   g d}t jj|d}t }| d ||}W d    n1 s$w   Y  | || d S r  )r   r  r  r   r1  r  r(  r  r  r(   r(   r)   r    s   z(TestPageChooserBlock.test_bulk_to_pythonc                 C   s\   ddg}t  }| d ||}W d    n1 sw   Y  | |d |d  d S )Nr   r   r   )r   r1  r  r(  rE  )r2   r  r'   r	  r(   r(   r)   &test_bulk_to_python_distinct_instances  s   z;TestPageChooserBlock.test_bulk_to_python_distinct_instancesc                 C   sV   t  }tjjdd}| t||tt|j	ddfg | t|d g  d S )Nr  r  r  )
r   r1  r   r  r  r  r  r  r=   r  r  r(   r(   r)   r    s   z,TestPageChooserBlock.test_extract_referencesN)r5   r6   r7   r  r\  r^  rg  r
  r  r  r  r  rj  r/  r  r  r  r  r  r!  r#  r%  r&  r'  r  r(  r  r(   r(   r(   r)   r    s2    








r  c                   @   sd   e Z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 )TestStaticBlockc              
   C   sZ   t jddd}|d t |}| |d d | |d dd|j|jdd	d
 d S )N[Latest posts - This block doesn't need to be configured, it will be displayed automatically$tests/blocks/posts_static_block.html
admin_textr   posts_static_blockr   r   r   Posts static blockr  r9   r   r   r   r   r   r   StaticBlockr   r   r   r   rK   ru   r   r(   r(   r)   test_adapt_with_constructor  s"   
z+TestStaticBlock.test_adapt_with_constructorc              
   C   d   G dd dt j}| }|d t |}| |d d | |d dd|j|jdd	d
 d S )Nc                   @   rt  )zBTestStaticBlock.test_adapt_with_subclass.<locals>.PostsStaticBlockc                   @   r  )zGTestStaticBlock.test_adapt_with_subclass.<locals>.PostsStaticBlock.Metar*  r+  N)r5   r6   r7   r-  r   r(   r(   r(   r)   rx    r  rx  Nrz  r(   r(   r(   r)   PostsStaticBlock  r|  r5  r.  r   r   r*  r   r/  r  r0  r1  )r2   r5  r'   r   r(   r(   r)   test_adapt_with_subclass  s   
z(TestStaticBlock.test_adapt_with_subclassc              
   C   r4  )Nc                   @   rt  )zmTestStaticBlock.test_adapt_with_subclass_displays_default_text_if_no_admin_text.<locals>.LabelOnlyStaticBlockc                   @   ru  )zrTestStaticBlock.test_adapt_with_subclass_displays_default_text_if_no_admin_text.<locals>.LabelOnlyStaticBlock.MetaLatest postsNr  r(   r(   r(   r)   rx    ry  rx  Nrz  r(   r(   r(   r)   LabelOnlyStaticBlock  r|  r8  r.  r   r   z(Latest posts: this block has no options.r   r7  r  r0  r1  )r2   r8  r'   r   r(   r(   r)   ?test_adapt_with_subclass_displays_default_text_if_no_admin_text  s   
zOTestStaticBlock.test_adapt_with_subclass_displays_default_text_if_no_admin_textc              
   C   r4  )Nc                   @   rn  )zwTestStaticBlock.test_adapt_with_subclass_displays_default_text_if_no_admin_text_and_no_label.<locals>.NoMetaStaticBlockNro  r(   r(   r(   r)   NoMetaStaticBlock*  rp  r:  r.  r   r   z.Posts static block: this block has no options.r   r/  r  r0  r1  )r2   r:  r'   r   r(   r(   r)   Ltest_adapt_with_subclass_displays_default_text_if_no_admin_text_and_no_label'  s   
z\TestStaticBlock.test_adapt_with_subclass_displays_default_text_if_no_admin_text_and_no_labelc              
   C   s^   t jtddd}|d t |}| |d d | |d dd|j|jdd	d
 d S )Nzb<b>Latest posts</b> - This block doesn't need to be configured, it will be displayed automaticallyr+  r,  r.  r   r   r   r/  r  )r   r   r   r   r   r   )	r   r2  r   r   r   r   r   rK   ru   r   r(   r(   r)   test_adapt_works_with_mark_safe?  s&   
z/TestStaticBlock.test_adapt_works_with_mark_safec                 C   s   t  }| }| | d S r<   )r   r2  r  rZ  )r2   r'   r  r(   r(   r)   r  W  s   z TestStaticBlock.test_get_defaultc                 C   s&   t jdd}|d }| |d d S )Nr+  r   z <p>PostsStaticBlock template</p>r   r2  r   r   r  r(   r(   r)   r  \  s   
zTestStaticBlock.test_renderc                 C   s"   t  }|d }| |d d S r  r=  r  r(   r(   r)   test_render_without_templatea  s   
z,TestStaticBlock.test_render_without_templatec                 C   rY  r<   )r   r2  r   rZ  r  r(   r(   r)   r\  f  r\  zTestStaticBlock.test_serializec                 C   rY  r<   )r   r2  r   rZ  r  r(   r(   r)   r^  k  r\  z TestStaticBlock.test_deserializec                 C   s   |  t d dS )zZ
        StaticBlock.normalize always returns None, as a StaticBlock has no value
           N)rZ  r   r2  rG   r]   r(   r(   r)   rI   p  s   zTestStaticBlock.test_normalizeN)r5   r6   r7   r3  r6  r9  r;  r<  r  r  r>  r\  r^  rI   r(   r(   r(   r)   r)    s    r)  c                   @   r=  )TestDateBlockc                 C      ddl m} t }|d t |}| |d d | |d | | |d j	d | |d ddd	d
|j
|jdd	ddid	 d S )Nr   )AdminDateInputtest_dateblockr   zY-m-dr   zTest dateblockr  Tr  z5w-field w-field--date_field w-field--admin_date_inputr   r   r   )wagtail.admin.widgets.datetimerB  r   r  r   r   r   r   r   	js_formatrK   ru   )r2   rB  r'   r   r(   r(   r)   rg  x  (   
zTestDateBlock.test_adaptc                 C   8   t jdd}|d t |}| |d jd d S )Nz%d.%m.%YformatrC  r   zd.m.Y)r   r  r   r   r   r   rE  r   r(   r(   r)   test_adapt_with_format     
z$TestDateBlock.test_adapt_with_formatNr5   r6   r7   rg  rJ  r(   r(   r(   r)   r@  w      r@  c                   @   r=  )TestTimeBlockc                 C   rA  )Nr   )AdminTimeInputtest_timeblockr   zH:ir   zTest timeblockr  Ttimez5w-field w-field--time_field w-field--admin_time_inputr   r   r   )rD  rO  r   	TimeBlockr   r   r   r   r   rE  rK   ru   )r2   rO  r'   r   r(   r(   r)   rg    rF  zTestTimeBlock.test_adaptc                 C   rG  )Nz%H:%M:%SrH  rP  r   zH:i:s)r   rR  r   r   r   r   rE  r   r(   r(   r)   rJ    rK  z$TestTimeBlock.test_adapt_with_formatNrL  r(   r(   r(   r)   rN    rM  rN  c                   @   r=  )TestDateTimeBlockc                 C   rA  )Nr   )AdminDateTimeInputtest_datetimeblockr   z	Y-m-d H:ir   zTest datetimeblockr  Tr  z?w-field w-field--date_time_field w-field--admin_date_time_inputr   r   r   )rD  rT  r   DateTimeBlockr   r   r   r   r   rE  rK   ru   )r2   rT  r'   r   r(   r(   r)   rg    rF  zTestDateTimeBlock.test_adaptc                 C   rG  )Nz%d.%m.%Y %H:%MrH  rU  r   z	d.m.Y H:i)r   rV  r   r   r   r   rE  r   r(   r(   r)   rJ    rK  z(TestDateTimeBlock.test_adapt_with_formatNrL  r(   r(   r(   r)   rS    rM  rS  c                   @   rX  )TestSystemCheckc                 C   v   t dt  fdt  fg}| }| t|d | |d jd | |d jd | |d j	|j
d  d S )Nr!  z	rich+textr   r   wagtailcore.E001zBlock names should follow standard Python conventions for variable names: alphanumeric and underscores, and cannot begin with a digitr   rr   r8   r  checkr   r   r  hintrH   r  r2   r'   errorsr(   r(   r)   )test_name_cannot_contain_non_alphanumeric  s   

z9TestSystemCheck.test_name_cannot_contain_non_alphanumericc                 C   rX  )Nr!  r  r   r   rY  zBlock name cannot be emptyrZ  r]  r(   r(   r)   test_name_must_be_nonempty     

z*TestSystemCheck.test_name_must_be_nonemptyc                 C   rX  )Nr!  	rich textr   r   rY  !Block names cannot contain spacesrZ  r]  r(   r(   r)   test_name_cannot_contain_spaces  ra  z/TestSystemCheck.test_name_cannot_contain_spacesc                 C   rX  )Nr!  z	rich-textr   r   rY  z!Block names cannot contain dashesrZ  r]  r(   r(   r)   test_name_cannot_contain_dashes  ra  z/TestSystemCheck.test_name_cannot_contain_dashesc                 C   rX  )Nr!  
99richtextr   r   rY  z%Block names cannot begin with a digitrZ  r]  r(   r(   r)   !test_name_cannot_begin_with_digit  ra  z1TestSystemCheck.test_name_cannot_begin_with_digitc              
   C   s   t  }t dt t dt  fd|fgfg}| }| t|d | |d j	d | |d j
d | |d j| d S )Nparagraph_listr!  rb  r   r   rY  rc  )r   r  rr   rq   rs   r8   r[  r   r   r  r\  rH   r2   failing_blockr'   r^  r(   r(   r)   %test_system_checks_recurse_into_lists-  s$   
z5TestSystemCheck.test_system_checks_recurse_into_listsc                 C   s   t  }t dt dt dt  fd|fgfgfg}| }| t|d | |d jd | |d j	d | |d j
| d S )	Ncarouselr9   r!  rb  r   r   rY  rc  r   r  rr   rs   r8   r[  r   r   r  r\  rH   ri  r(   r(   r)   'test_system_checks_recurse_into_streamsE  s*   
z7TestSystemCheck.test_system_checks_recurse_into_streamsc                 C   s   t  }t  }t dt dt dt  fd|fgfdt dt  fd|fgfgfg}| }| t|d | |d jd | |d j	d	 | |d j
| | |d
 jd | |d
 j	d	 | |d
 j
| d S )N
two_columnr  r!  rb  r  r   r   rY  rc  r   rm  )r2   failing_block_1failing_block_2r'   r^  r(   r(   r)   'test_system_checks_recurse_into_structsb  s@   


z7TestSystemCheck.test_system_checks_recurse_into_structsN)r5   r6   r7   r_  r`  rd  re  rg  rk  rn  rr  r(   r(   r(   r)   rW    s    rW  c                   @   s"   e Zd Zdd Zejdd ZdS )TestTemplateRenderingc                 C   s:   t  }|ddd}ddi}|||}| |d d S )Nr  http://torchbox.com/r  r  r   	importantz=<a href="http://torchbox.com/" class="important">Torchbox</a>)CustomLinkBlockr   r   r   )r2   r'   r$   rW   r  r(   r(   r)   test_render_with_custom_context  s   z5TestTemplateRendering.test_render_with_custom_contextc                 C   s@   t  }|ddd}|j|dd}| d| | d| d S )Nr  rt  ru  zmy-link-blockri  zdata-prefix="my-link-block"z#<p>Hello from get_form_context!</p>)rw  r   render_formr   r  r(   r(   r)   $test_render_with_custom_form_context  s
   z:TestTemplateRendering.test_render_with_custom_form_contextN)r5   r6   r7   rx  rv   expectedFailurerz  r(   r(   r(   r)   rs    s    
rs  c                   @   rX  )TestIncludeBlockTagc                 C   6   t jdd}|d}td|dd}| d| dS )	z
        The include_block tag should be able to render a BoundBlock's template
        while keeping the parent template's context
        r   r   r  $tests/blocks/include_block_test.htmlr   r   r   '<body><h1 lang="fr">bonjour</h1></body>Nr   r8   bindr   r   r2   r'   bound_blockr  r(   r(   r)   &test_include_block_tag_with_boundblock     
z:TestIncludeBlockTag.test_include_block_tag_with_boundblockc                 C   s6   t  }|ddd}td|dd}| d| dS )	z
        The include_block tag should be able to render a StructValue's template
        while keeping the parent template's context
        r;  r<  r  r~  r   r  z<<body><h1 lang="fr">Bonjour</h1>monde <i>italique</i></body>N)r   r   r   r   )r2   r'   r  r  r(   r(   r)   'test_include_block_tag_with_structvalue  s   z;TestIncludeBlockTag.test_include_block_tag_with_structvaluec                 C   sX   t jdt jddfdt  fgdd}|dddg}td|d	d
}| d| dS )z
        The include_block tag should be able to render a StreamValue's template
        while keeping the parent template's context
        r!  r   r   r"  z&tests/blocks/stream_with_language.htmlr;  r:  r~  r   r  z?<div class="heading" lang="fr"><h1 lang="fr">Bonjour</h1></div>N)r   rr   r8   r   r   r   )r2   r'   r  r  r(   r(   r)   'test_include_block_tag_with_streamvalue  s$   

z;TestIncludeBlockTag.test_include_block_tag_with_streamvaluec                 C   s   t dddi}| d| dS )z
        The include_block tag should be able to render a value without a render_as_block method
        by just rendering it as a string
        r~  r   rN  z<body>42</body>N)r   r   )r2   r  r(   r(   r)   'test_include_block_tag_with_plain_value  s   z;TestIncludeBlockTag.test_include_block_tag_with_plain_valuec                 C   sR   t jdd}|d}td|dd}| d| tdddd}| d	| dS )
z
        The block parameter on include_block tag should support complex values including filters,
        e.g. {% include_block foo|default:123 %}
        r   r   r  z0tests/blocks/include_block_test_with_filter.htmlr   r  r  Nz<body>999</body>r  r  r(   r(   r)   *test_include_block_tag_with_filtered_value  s    
z>TestIncludeBlockTag.test_include_block_tag_with_filtered_valuec                 C   r}  )	z
        Test that it's possible to pass extra context on an include_block tag using
        {% include_block foo with classname="bar" %}
        r   r   r  z)tests/blocks/include_block_with_test.htmlr   r  z9<body><h1 lang="fr" class="important">bonjour</h1></body>Nr  r  r(   r(   r)   )test_include_block_tag_with_extra_context  s   
z=TestIncludeBlockTag.test_include_block_tag_with_extra_contextc                 C   r}  )	z
        A tag such as {% include_block foo with classname="bar" only %}
        should not inherit the parent context
        r   r   r  z)tests/blocks/include_block_only_test.htmlr   r  z/<body><h1 class="important">bonjour</h1></body>Nr  r  r(   r(   r)   %test_include_block_tag_with_only_flag#  r  z9TestIncludeBlockTag.test_include_block_tag_with_only_flagc                 C   s   t  }||d}tdd|i}| d| tdd|i}| d| tdddi}| d| tdddi}| d| t  }||d}tdd|i}| d| tddtdi}| d| dS )z\
        Output of include_block should be escaped as per Django autoescaping rules
        zsome <em>evil</em> HTMLr~  r   z0<body>some &lt;em&gt;evil&lt;/em&gt; HTML</body>z3tests/blocks/include_block_autoescape_off_test.htmlz$<body>some <em>evil</em> HTML</body>N)r   r8   r  r   r   r   rT  r   r  r(   r(   r)    test_include_block_html_escaping4  sP   z4TestIncludeBlockTag.test_include_block_html_escapingN)r5   r6   r7   r  r  r  r  r  r  r  r  r(   r(   r(   r)   r|    s    r|  c                   @   r=  )!TestOverriddenGetTemplateBlockTagc                 C   sb   G dd dt j}|dd}| td |d}W d    n1 s$w   Y  | |d d S )Nc                   @   s   e Zd ZdZdddZdS )zfTestOverriddenGetTemplateBlockTag.test_get_template_old_signature.<locals>.BlockUsingGetTemplateMethodr   Nc                 S   s   | j S r<   )my_new_template)r2   rW   r(   r(   r)   get_template|  s   zsTestOverriddenGetTemplateBlockTag.test_get_template_old_signature.<locals>.BlockUsingGetTemplateMethod.get_templater<   )r5   r6   r7   r  r  r(   r(   r(   r)   BlockUsingGetTemplateMethody  s    r  z'tests/blocks/this_shouldnt_be_used.htmlr   z[BlockUsingGetTemplateMethod.get_template should accept a 'value' argument as first argumentHello Worldz<h1>Hello World</h1>)r   rF   assertWarnsMessager    r   r   )r2   r  r'   r   r(   r(   r)   test_get_template_old_signaturex  s   zATestOverriddenGetTemplateBlockTag.test_get_template_old_signaturec                 C   sH   G dd dt j}| }|d}| |d |d}| |d dS )z8verifies Block.render() passes the value to get_templatec                   @   rN   )zTestOverriddenGetTemplateBlockTag.test_block_render_passes_the_value_argument_to_get_template.<locals>.BlockChoosingTemplateBasedOnValueNc                 S   s   |dkrdS d S )NHEADINGr   r(   rV   r(   r(   r)   r    s   zTestOverriddenGetTemplateBlockTag.test_block_render_passes_the_value_argument_to_get_template.<locals>.BlockChoosingTemplateBasedOnValue.get_templaterZ   )r5   r6   r7   r  r(   r(   r(   r)   !BlockChoosingTemplateBasedOnValue  rS   r  r  r  z<h1>HEADING</h1>N)r   rF   r   r   )r2   r  r'   r   r(   r(   r)   ;test_block_render_passes_the_value_argument_to_get_template  s   

z]TestOverriddenGetTemplateBlockTag.test_block_render_passes_the_value_argument_to_get_templateN)r5   r6   r7   r  r  r(   r(   r(   r)   r  w  s    r  c                   @   sl   e Z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 )TestValidationErrorAsJsonDatac                 C   s"   t d}| t|ddgi d S )Neverything is brokenrp  r   r   r   r2   r0   r(   r(   r)   test_plain_validation_error  r"  z9TestValidationErrorAsJsonData.test_plain_validation_errorc                 C   s0   t t dt dg}| t|dddgi d S )Nr  zeven more broken than beforerp  r  r  r(   r(   r)   ,test_validation_error_with_multiple_messages  s   
zJTestValidationErrorAsJsonData.test_validation_error_with_multiple_messagesc                 C   sJ   t dttdgittdgd}| t|dddgiidgd d S )NrO  rm  3Either email or telephone number must be specified.block_errorsr,   rp  rZ  rp  )r   r   r   r   r   r  r(   r(   r)   !test_structblock_validation_error  s$   
z?TestValidationErrorAsJsonData.test_structblock_validation_errorc                 C   *   t tdgd}| t|ddgi d S )Nr  r+   rp  r   r   r   r   r  r(   r(   r)   6test_structblock_validation_error_with_no_block_errors     zTTestValidationErrorAsJsonData.test_structblock_validation_error_with_no_block_errorsc                 C   4   t dtdid}| t|ddddgiii d S )NrO  rm  r  rZ  rp  r  r  r(   r(   r)   :test_structblock_validation_error_with_no_non_block_errors  s   
zXTestValidationErrorAsJsonData.test_structblock_validation_error_with_no_non_block_errorsc              	   C   s   t ttttdgdgttdgttdttdgidgdttdtdgd	}| t|d
dgid
dgiddd
dgiiidddgd d S )Nr  r+   rm  rO  r  )r   r   rP  r   The maximum number of items is 5r  rp  rZ  r  )r   r   r   r   r   r   r  r(   r(   r)   !test_streamblock_validation_error  s`   #z?TestValidationErrorAsJsonData.test_streamblock_validation_errorc                 C   r  Nr  r+   rp  r   r   r   r   r  r(   r(   r)   6test_streamblock_validation_error_with_no_block_errors#  r  zTTestValidationErrorAsJsonData.test_streamblock_validation_error_with_no_block_errorsc                 C   sD   t tdgtddd}| t|dddgiddgidi d S )Nrm  )r   rP  r  rZ  rp  r  r  r(   r(   r)   :test_streamblock_validation_error_with_no_non_block_errors2  s   zXTestValidationErrorAsJsonData.test_streamblock_validation_error_with_no_non_block_errorsc              	   C   s   t d ttttdgdgttdttdgidggttdtdgd}| t|d	dgid
dd	dgiiidddgd d S )Nr  r+   rO  rm  r  r  r  r  rp  rZ  r   r   r  )r   r   r   r   r   r   r  r(   r(   r)   5test_listblock_validation_error_constructed_with_listC  s^   #zSTestValidationErrorAsJsonData.test_listblock_validation_error_constructed_with_listc                 C   s   t tttdgdgtdttdgiddttdtdgd	}| t|d
dgiddd
dgiiidddgd d S )Nr  r+   rO  rm  r  r  r  r  r  rp  rZ  r  )r   r   r   r   r   r   r  r(   r(   r)   5test_listblock_validation_error_constructed_with_dict  sN   zSTestValidationErrorAsJsonData.test_listblock_validation_error_constructed_with_dictc                 C   r  )Nr   rm  r  rZ  rp  r   r   r   r   r  r(   r(   r)   8test_listblock_validation_error_with_no_non_block_errors  s   

zVTestValidationErrorAsJsonData.test_listblock_validation_error_with_no_non_block_errorsc                 C   r  r  r  r  r(   r(   r)   4test_listblock_validation_error_with_no_block_errors  r  zRTestValidationErrorAsJsonData.test_listblock_validation_error_with_no_block_errorsN)r5   r6   r7   r  r  r  r  r  r  r  r  r  r  r  r  r(   r(   r(   r)   r    s    =?6r  c                   @   r0  )
TestBlockDefinitionLookupc                 C   s   t dg ddifdg i fd}|d}|d | |tj | |j |d}| |tj |d}|d	 | |tj | |j | 	|| | 
|jd | 
|jd	 d S )
Nwagtail.blocks.CharBlockr   Twagtail.blocks.RichTextBlockr   r   r   r  r   subtitle)r   	get_blockr   r   r   r8   ro  r   r  rE  r   rO  )r2   lookup
char_blockrich_text_blockchar_block_2r(   r(   r)   test_simple_lookup  s$   




z,TestBlockDefinitionLookup.test_simple_lookupc                 C      t dg ddifdg i fdddggi fd}|d	}| |tj |jd
 }| |tj | |j |jd }| |tj	 d S )Nr  r   Tr  zwagtail.blocks.StructBlock)r  r   )r   r   r   r   r   r   r  r   )
r   r  r   r   rs   r  r8   ro  r   r  )r2   r  struct_blocktitle_blockdescription_blockr(   r(   r)   test_structblock_lookup  &   


z1TestBlockDefinitionLookup.test_structblock_lookupc                 C   r  )Nr  r   Tr  zwagtail.blocks.StreamBlock)r!  r   )r"  r   r  r   r!  r"  )
r   r  r   r   rr   r  r8   ro  r   r  )r2   r  r  r  r  r(   r(   r)   test_streamblock_lookup  r  z1TestBlockDefinitionLookup.test_streamblock_lookupc                 C   s   t dg ddifddgi fd}|d}| |tj |j}| |tj | |j t ddtjgi fi}|d}| |tj |j}| |tj d S )Nr  r   Tzwagtail.blocks.ListBlockr   r  r   )	r   r  r   r   rq   r  r8   ro  r   )r2   r  rU  list_item_blockr(   r(   r)   test_listblock_lookup!  s$   


z/TestBlockDefinitionLookup.test_listblock_lookupN)r5   r6   r7   r  r  r  r  r(   r(   r(   r)   r    s
    r  )br   r  rD  r_  rv   unittest.mockdecimalr   djangor   django.core.exceptionsr   django.core.serializers.jsonr   django.forms.utilsr   django.template.loaderr   django.testr	   r
   django.utils.safestringr   r   django.utils.translationr   r,  r  r   wagtail.blocks.baser    wagtail.blocks.definition_lookupr   wagtail.blocks.field_blockr   wagtail.blocks.list_blockr   r   wagtail.blocks.static_blockr   wagtail.blocks.stream_blockr   r   wagtail.blocks.struct_blockr   r   wagtail.modelsr   wagtail.rich_textr   wagtail.test.testapp.blocksr   rw  r   wagtail.test.testapp.modelsr   r   wagtail.test.utilsr   wagtail.utils.deprecationr    rr   r!   r8   r;   rC   r|   r  r1  r:  r>  rB  rU  rf  r}  r  r?  rR  rs  r  rY  r  r  r  r  r  r  r  r)  r@  rN  rS  rW  rs  r|  r  r  r  r(   r(   r(   r)   <module>   s    e o*	)@< G      uJ      X    L=         Jr>o j $$$ + V%  ;