a
    DgW                    @   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 s2tjt| jgd|S )Nc                 s   s   | ]}|j d kV  qdS )fooNvalue.0block r(   X/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/tests/test_blocks.py	<genexpr>*       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textr1   r/   __classcell__r(   r(   r4   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   r9   get_contextr3   r$   Zparent_contextr4   r(   r)   r@   2   s    zContextCharBlock.get_context)N)r6   r7   r8   r@   r;   r(   r(   r4   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)r3   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   rE   rD   definition_registrydefinition_prefixr3   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 ]R\}}| j|dd, || D ]}| |j| qW d    q1 s0    Y  qtj	j
dddz g d}|D ]\\}}| j|dd2 || D ]}|`| |j| q8W d    n1 sh0    Y  qW d    n1 s0    Y  d S )Nc                   @   s   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(   rA   r(   r(   r)   get_preview_contextD   s    zSTestBlock.test_block_is_previewable.<locals>.CustomContextBlock.get_preview_context)N)r6   r7   r8   rN   r(   r(   r(   r)   CustomContextBlockC   s   rO   c                   @   s   e Zd ZdddZdS )z@TestBlock.test_block_is_previewable.<locals>.CustomTemplateBlockNc                 S   s   dS )Nfoo.htmlr(   r3   r$   contextr(   r(   r)   get_preview_templateH   s    zUTestBlock.test_block_is_previewable.<locals>.CustomTemplateBlock.get_preview_template)NN)r6   r7   r8   rS   r(   r(   r(   r)   CustomTemplateBlockG   s   rT   c                   @   s   e Zd Zdd ZdS )z=TestBlock.test_block_is_previewable.<locals>.CustomValueBlockc                 S   s   dS )Nr"   r(   r3   r(   r(   r)   get_preview_valueL   s    zOTestBlock.test_block_is_previewable.<locals>.CustomValueBlock.get_preview_valueN)r6   r7   r8   rV   r(   r(   r(   r)   CustomValueBlockK   s   rW   rP   )preview_templater"   )preview_valuerM   default)rX   rY   )	no_configspecific_templatecustom_value"specific_template_and_custom_valueunset_default_not_none)r\   Fr]   T)r^   Fr_   Tr`   FF)variantZcustom_global_templatez*wagtail.blocks.base.template_is_overriddenT)Zreturn_value)ra   rb   )r^   Trc   rd   )r   rE   	ListBlockStreamBlockStructBlocksubTestrD   is_previewableunittestZmockpatch)	r3   rO   rT   rW   variantsZcasesre   rj   r'   r(   r(   r)   test_block_is_previewableB   sF    


0z#TestBlock.test_block_is_previewableN)r6   r7   r8   rH   rL   rn   r(   r(   r(   r)   rB   7   s   rB   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   s"   t  }|d}| |d d S NHello world!r   r9   renderassertEqualr3   r'   htmlr(   r(   r)   test_charfield_render   s    
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   r9   rE   rI   rJ   assertIsInstancert   metary   rD   )r3   r'   Zregistered_blockr(   r(   r)   rL      s
    z-TestFieldBlock.test_block_definition_registryc                 C   s&   t jdd}|d}| |d d S )Ntests/blocks/heading_block.htmltemplaterq   <h1>Hello world!</h1>rr   ru   r(   r(   r)   #test_charfield_render_with_template   s    
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         rx   Tplaceholderz/w-field w-field--char_field w-field--text_inputADD_COMMENTAdd Comment)
ry   descriptionhelpTextrequiredicon
blockDefIdisPreviewable	classnameshowAddCommentButtonstrings)r   r9   set_namer   js_argsrt   rz   r   Z	TextInputrJ   rj   r3   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   r9   r   r   r   assertIn)r3   r'   r   Z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rR   z$<h1 lang="fr">BONJOUR LE MONDE!</h1>)r<   rs   rt   ru   r(   r(   r)   6test_charfield_render_with_template_with_extra_context   s    
zETestFieldBlock.test_charfield_render_with_template_with_extra_contextc                 C   s"   t  }|d}| |d d S rp   r   r9   get_form_statert   r3   r'   
form_stater(   r(   r)   test_charfield_get_form_state   s    
z,TestFieldBlock.test_charfield_get_form_statec                 C   s$   t  }|d}| |dg d S rp   r   r9   get_searchable_contentrt   r3   r'   contentr(   r(   r)   !test_charfield_searchable_content   s    
z0TestFieldBlock.test_charfield_searchable_contentc                 C   s&   t jdd}|d}| |g  d S )NFsearch_indexrq   r   r   r(   r(   r)   $test_search_index_searchable_content   s    
z3TestFieldBlock.test_search_index_searchable_contentc                 C   sN   dd }t j|gd}| t |d W d    n1 s@0    Y  d S )Nc                 S   s   | dkrt dd S Nr"   zValue must be 'foo'r   r#   r(   r(   r)   validate_is_foo   s    zETestFieldBlock.test_charfield_with_validator.<locals>.validate_is_foo
validatorsrM   )r   r9   assertRaisesr   r/   r3   r   r'   r(   r(   r)   test_charfield_with_validator   s    z,TestFieldBlock.test_charfield_with_validatorc                 C   s2   G dd dt j}| }|d}| |d d S )Nc                   @   s   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r6   r7   r8   r   ZChoiceFieldfieldr(   r(   r(   r)   ChoiceBlock  s   r   r   )r   
FieldBlockrs   rt   )r3   r   r'   rv   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                   @   s   e Zd ZejddZdS )zATestFieldBlock.test_adapt_custom_choicefield.<locals>.ChoiceBlockr   r   Nr   r(   r(   r(   r)   r     s   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   	ry   r   r   r   r   r   r   r   r   )r   r   r   r   r   rt   rz   r   Selectr   rJ   rj   )r3   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                   @   s   e Zd ZejddZdS )z;TestFieldBlock.test_searchable_content.<locals>.CustomBlockTr   N)r6   r7   r8   r   Z	CharFieldr   r(   r(   r(   r)   CustomBlock<  s   r   zfoo barN)r   r   rt   r   )r3   r   r'   r(   r(   r)   test_searchable_content5  s    z&TestFieldBlock.test_searchable_contentc                 C   s2   G dd dt j}| }|d}| |d d S )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   s
   t |S r=   )base64	b64decode)r3   jsonish_valuer(   r(   r)   	to_pythonH  s    zlTestFieldBlock.test_form_handling_is_independent_of_serialisation.<locals>.Base64EncodingCharBlock.to_pythonc                 S   s
   t |S r=   )r   	b64encode)r3   Znative_valuer(   r(   r)   get_prep_valueL  s    zqTestFieldBlock.test_form_handling_is_independent_of_serialisation.<locals>.Base64EncodingCharBlock.get_prep_valueN)r6   r7   r8   __doc__r   r   r(   r(   r(   r)   Base64EncodingCharBlockC  s   r   zhello worldr   )r3   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#   r2   r(   r(   r)   __init__`  s    zHTestFieldBlock.test_prepare_value_called.<locals>.PrefixWrapper.__init__c                 S   s   | j | j S r=   )prefixr$   rU   r(   r(   r)   with_prefixc  s    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#   )r3   otherr(   r(   r)   __eq__l  s    zFTestFieldBlock.test_prepare_value_called.<locals>.PrefixWrapper.__eq__N)	r6   r7   r8   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   r2   )r   r5   r(   r)   r/   p  s    zCTestFieldBlock.test_prepare_value_called.<locals>.PrefixField.cleanc                 S   s   |  S r=   )r   r2   r(   r(   r)   prepare_valuet  s    zKTestFieldBlock.test_prepare_value_called.<locals>.PrefixField.prepare_value)r6   r7   r8   r/   r   r;   r(   )r   r4   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f i |  ||d| _d S )N)r   r   )r.   r   r   )r3   r   r   kwargs)r   r5   r(   r)   r   x  s    zHTestFieldBlock.test_prepare_value_called.<locals>.PrefixedBlock.__init__)Tr   )r6   r7   r8   r   r;   r(   )r   r4   r)   PrefixedBlockw  s   r   r"   zhttp://example.com/foourlzhttp://example.com/barrM   N)r   ZFieldr   r   r   rt   r/   value_from_datadict)r3   r   r'   r$   r   data	new_valuer(   )r   r   r)   test_prepare_value_calledT  s    	
z(TestFieldBlock.test_prepare_value_calledN)r6   r7   r8   rw   rL   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r(   r(   r)   ro      s   
&ro   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestIntegerBlockc                 C   s&   t  }|d}| t|t d S Ni  )r   IntegerBlockvalue_from_formrt   typeintr3   r'   digitr(   r(   r)   	test_type  s    
zTestIntegerBlock.test_typec                 C   s"   t  }|d}| |d d S r   )r   r   r   rt   r   r(   r(   r)   test_render  s    
zTestIntegerBlock.test_renderc                 C   s@   t  }| t |d W d    n1 s20    Y  d S Nr   r   r   r   r   r/   rK   r(   r(   r)   test_render_required_error  s    z+TestIntegerBlock.test_render_required_errorc                 C   sD   t jdd}| t |d W d    n1 s60    Y  d S )N   Z	max_value   r   rK   r(   r(   r)    test_render_max_value_validation  s    z1TestIntegerBlock.test_render_max_value_validationc                 C   sD   t jdd}| t |d W d    n1 s60    Y  d S )Nr   Z	min_value
   r   rK   r(   r(   r)    test_render_min_value_validation  s    z1TestIntegerBlock.test_render_min_value_validationc                 C   sN   dd }t j|gd}| t |d W d    n1 s@0    Y  d S )Nc                 S   s   | d dkrt dd S Nr   r   zValue must be evenr   r#   r(   r(   r)   validate_is_even  s    zETestIntegerBlock.test_render_with_validator.<locals>.validate_is_evenr      r   r3   r   r'   r(   r(   r)   test_render_with_validator  s    z+TestIntegerBlock.test_render_with_validatorN)	r6   r7   r8   r   r   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	S )
TestEmailBlockc                 C   s"   t  }|d}| |d d S )Nzexample@email.com)r   
EmailBlockrs   rt   )r3   r'   emailr(   r(   r)   r     s    
zTestEmailBlock.test_renderc                 C   s@   t  }| t |d W d    n1 s20    Y  d S r   r   r  r   r   r/   rK   r(   r(   r)   r     s    z)TestEmailBlock.test_render_required_errorc                 C   s@   t  }| t |d W d    n1 s20    Y  d S )Nzexample.email.comr  rK   r(   r(   r)   test_format_validation  s    z%TestEmailBlock.test_format_validationc                 C   sN   dd }t j|gd}| t |d W d    n1 s@0    Y  d S )Nc                 S   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  s    
zMTestEmailBlock.test_render_with_validator.<locals>.validate_is_example_domainr   zfoo@example.netr  )r3   r	  r'   r(   r(   r)   r    s    z)TestEmailBlock.test_render_with_validatorN)r6   r7   r8   r   r   r  r  r(   r(   r(   r)   r    s   r  c                   @   s   e Zd Zdd ZdS )TestBooleanBlockc                 C   s<   t jdd}|d}| |d |d}| |d d S )NFr   T)r   BooleanBlockr   rD   r   r(   r(   r)   test_get_form_state  s
    

z$TestBooleanBlock.test_get_form_stateN)r6   r7   r8   r  r(   r(   r(   r)   r
    s   r
  c                   @   s   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   BlockQuoteBlockrs   rt   )r3   r'   quoter(   r(   r)   r     s    
zTestBlockQuoteBlock.test_renderc                 C   sN   dd }t j|gd}| t |d W d    n1 s@0    Y  d S )Nc                 S   s   |  dstdd S )NzOnce upon a timezValue must be a proper story)r   r   r#   r(   r(   r)   validate_is_proper_story  s    
zPTestBlockQuoteBlock.test_render_with_validator.<locals>.validate_is_proper_storyr   zA long, long time ago)r   r  r   r   r/   )r3   r  r'   r(   r(   r)   r    s    z.TestBlockQuoteBlock.test_render_with_validatorN)r6   r7   r8   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S )TestFloatBlockc                 C   s*   t  }|td}| t|t d S NGz?)r   
FloatBlockr   floatrt   r   r3   r'   	block_valr(   r(   r)   r     s    zTestFloatBlock.test_typec                 C   s*   t  }td}||}| || d S r  )r   r  r  r   rt   r3   r'   Ztest_valr  r(   r(   r)   r     s    
zTestFloatBlock.test_renderc                 C   s@   t  }| t |d W d    n1 s20    Y  d S r   r   r  r   r   r/   rK   r(   r(   r)   test_raises_required_error  s    z)TestFloatBlock.test_raises_required_errorc                 C   sD   t jdd}| t |d W d    n1 s60    Y  d S Nr   r   z20.01r  rK   r(   r(   r)   &test_raises_max_value_validation_error  s    z5TestFloatBlock.test_raises_max_value_validation_errorc                 C   sD   t jdd}| t |d W d    n1 s60    Y  d S Nr   r   z19.99r  rK   r(   r(   r)   &test_raises_min_value_validation_error  s    z5TestFloatBlock.test_raises_min_value_validation_errorc                 C   sN   dd }t j|gd}| t |d W d    n1 s@0    Y  d S )Nc                 S   s   | d dkrt dd S r   r   r#   r(   r(   r)   r     s    zCTestFloatBlock.test_render_with_validator.<locals>.validate_is_evenr   3.0r  r  r(   r(   r)   r    s    z)TestFloatBlock.test_render_with_validatorN)	r6   r7   r8   r   r   r  r  r  r  r(   r(   r(   r)   r    s   r  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   s*   t  }|td}| t|t d S Nz1.63)r   DecimalBlockr   r   rt   r   r  r(   r(   r)   r     s    zTestDecimalBlock.test_typec                 C   s&   t  }|d}| t|t d S r!  )r   r"  r   rt   r   r   r  r(   r(   r)   test_type_to_python  s
    z$TestDecimalBlock.test_type_to_pythonc                 C   s    t  }|d }| | d S r=   )r   r"  r   assertIsNoner  r(   r(   r)   &test_type_to_python_decimal_none_value#  s    
z7TestDecimalBlock.test_type_to_python_decimal_none_valuec                 C   s*   t  }td}||}| || d S r  )r   r"  r   r   rt   r  r(   r(   r)   r   (  s    
zTestDecimalBlock.test_renderc                 C   s@   t  }| t |d W d    n1 s20    Y  d S r   r   r"  r   r   r/   rK   r(   r(   r)   r  /  s    z+TestDecimalBlock.test_raises_required_errorc                 C   sD   t jdd}| t |d W d    n1 s60    Y  d S r  r&  rK   r(   r(   r)   r  5  s    z7TestDecimalBlock.test_raises_max_value_validation_errorc                 C   sD   t jdd}| t |d W d    n1 s60    Y  d S r  r&  rK   r(   r(   r)   r  ;  s    z7TestDecimalBlock.test_raises_min_value_validation_errorc                 C   sN   dd }t j|gd}| t |d W d    n1 s@0    Y  d S )Nc                 S   s   | d dkrt dd S r   r   r#   r(   r(   r)   r   B  s    zETestDecimalBlock.test_render_with_validator.<locals>.validate_is_evenr   r  r&  r  r(   r(   r)   r  A  s    z+TestDecimalBlock.test_render_with_validatorc                 C   sT   t  }td}tj||td}|t|}| 	t
|t | 	|| d S )Nr  r   )r   r"  r   jsondumpsr   r   r   loadsrt   r   )r3   r'   original_valueZdb_valueZrestored_valuer(   r(   r)   $test_round_trip_to_db_preserves_typeK  s    
z5TestDecimalBlock.test_round_trip_to_db_preserves_typeN)r6   r7   r8   r   r#  r%  r   r  r  r  r  r,  r(   r(   r(   r)   r     s   
r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestRegexBlockc                 C   s*   t jdd}d}||}| || d S )N
^[0-9]{3}$regexZ123)r   
RegexBlockr   rt   r  r(   r(   r)   r   W  s    
zTestRegexBlock.test_renderc                 C   sT   t jdd}| t}|d W d    n1 s60    Y  | d|jj d S )Nr.  r/  r   This field is required.r   r1  r   r   r/   r   	exceptionmessagesr3   r'   rR   r(   r(   r)   r  ^  s    (z)TestRegexBlock.test_raises_required_errorc                 C   s^   d}t jdd|id}| t}|d W d    n1 s@0    Y  | ||jj d S )NzOops, you missed a bit.r.  r   r0  Zerror_messagesr   r3  r3   Ztest_messager'   rR   r(   r(   r)   !test_raises_custom_required_errorf  s    (z0TestRegexBlock.test_raises_custom_required_errorc                 C   sT   t jdd}| t}|d W d    n1 s60    Y  | d|jj d S )Nr.  r/  [/]zEnter a valid value.r3  r6  r(   r(   r)   test_raises_validation_errort  s    (z+TestRegexBlock.test_raises_validation_errorc                 C   s^   d}t jdd|id}| t}|d W d    n1 s@0    Y  | ||jj d S )Nz Not a valid library card number.r.  invalidr7  r:  r3  r8  r(   r(   r)    test_raises_custom_error_message|  s    (z/TestRegexBlock.test_raises_custom_error_messagec                 C   sP   dd }t jd|gd}| t |d W d    n1 sB0    Y  d S )Nc                 S   s   | dkrt dd S r   r   r#   r(   r(   r)   r     s    zBTestRegexBlock.test_render_with_validator.<locals>.validate_is_fooz^.*$)r0  r   rM   )r   r1  r   r   r/   r   r(   r(   r)   r    s    z)TestRegexBlock.test_render_with_validatorN)	r6   r7   r8   r   r  r9  r;  r=  r  r(   r(   r(   r)   r-  V  s   r-  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_defaultrz   r   rt   sourcer3   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 NrZ   r   r@  rD  r(   r(   r)   "test_get_default_with_default_none  s    z4TestRichTextBlock.test_get_default_with_default_nonec                 C   s.   t jdd }| |t | |jd d S Nr   rZ   r@  rD  r(   r(   r)   "test_get_default_with_empty_string  s    z4TestRichTextBlock.test_get_default_with_empty_stringc                 C   s.   t jdd }| |t | |jd d S Nz
<p>foo</p>rZ   r@  rD  r(   r(   r)   %test_get_default_with_nonempty_string  s    z7TestRichTextBlock.test_get_default_with_nonempty_stringc                 C   s2   t jtdd }| |t | |jd d S rK  )r   rA  r   rB  rz   rt   rC  rD  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   rA  r   rs   rt   r3   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   )CustomRichTextAreaZcustom)Zeditortest_richtextblockr   r   z:w-field w-field--char_field w-field--custom_rich_text_areapilcrowTest richtextblockr   Tr   r   )	r   r   ry   r   r   r   r   r   r   )Zwagtail.test.testapp.rich_textrP  r   rA  r   r   r   rt   rz   rJ   rj   )r3   rP  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   DraftailRichTextArearQ  r   r   rS  r   TrR  <w-field w-field--char_field w-field--draftail_rich_text_areaFr   r   r   Zwagtail.admin.rich_textrV  r   rA  r   r   r   rt   rz   rJ   rj   r3   rV  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   rU  i  
max_lengthrQ  r   r   rS  r   TrR  rW  Fr   r   )
ry   r   r   r   r   r   r   r   r   Z	maxLengthrX  rY  r(   r(   r)   test_adapter_with_max_length  s(    
z.TestRichTextBlock.test_adapter_with_max_lengthc                 C   sD   t  }| t |td W d    n1 s60    Y  d S r   r   rA  r   r   r/   r   rK   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   rA  r/   r   rz   rt   rC  r3   r'   rO  r(   r(   r)   )test_validate_non_required_richtext_block
  s    z;TestRichTextBlock.test_validate_non_required_richtext_blockc                 C   sR   dd }t j|gd}| t |td W d    n1 sD0    Y  d S )Nc                 S   s   d| vrt dd S Nr"   zValue must contain 'foo'r   r#   r(   r(   r)   validate_contains_foo  s    zKTestRichTextBlock.test_render_with_validator.<locals>.validate_contains_foor   
<p>bar</p>r^  r3   rc  r'   r(   r(   r)   r    s    z,TestRichTextBlock.test_render_with_validatorc                 C   sd   t jdd}|td | t |td W d    n1 sH0    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   rA  r/   r   r   r   rK   r(   r(   r)   test_validate_max_length  s    ,z*TestRichTextBlock.test_validate_max_lengthc                 C   s,   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   rA  r   r   rt   rN  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   rg  rh  rN  r(   r(   r)   (test_search_index_get_searchable_content7  s    
z:TestRichTextBlock.test_search_index_get_searchable_contentc                 C   s,   t  }td}||}| |dg d S )Nz#<p>mashed</p><p>po<i>ta</i>toes</p>zmashed potatoesrh  rN  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   rA  r   rt   listextract_referencesr   r3   r'   r$   r(   r(   r)   test_extract_referencesI  s    z)TestRichTextBlock.test_extract_referencesc              	   C   sn   t  }dtdfD ]T}| j|d4 ||}| |t | |jd W d    q1 s^0    Y  qd S )NHello, worldr#   )r   rA  r   ri   rF   rz   rt   rC  r3   r'   r$   
normalizedr(   r(   r)   rH   O  s    
z TestRichTextBlock.test_normalizeN)r6   r7   r8   fixturesrF  rH  rJ  rL  rM  r   rT  rZ  r]  r_  ra  r  rf  ri  rj  rk  rp  rH   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/S )0TestChoiceBlockc                 C   s   ddl m} |d d | _d S Nr   )BLANK_CHOICE_DASHr   Zdjango.db.models.fieldsrw  Zblank_choice_dash_labelr3   rw  r(   r(   r)   setUpY  s    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teaZTeacoffeeZCoffeer   r   r   r   r   z	---------r{  r}  r   r   r   Tr   r   r   r   r   )r   r   r   r   r   rt   rz   r   r   rm  r   rJ   rj   r   r(   r(   r)   test_adapt_choice_block^  s,    
z'TestChoiceBlock.test_adapt_choice_blockc                 C   s&   t jddgdd}| | d d S Nr{  r}  r|  )r   r[   )r   r   rt   rB  rK   r(   r(   r)   test_choice_block_with_defaulty  s    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   s   ddgS Nr{  r}  r(   r(   r(   r(   r)   callable_choices  s    zWTestChoiceBlock.test_adapt_choice_block_with_callable_choices.<locals>.callable_choicesr   r   r   r  )r   r   r   r   r   rz   r   r   rt   rm  r   r3   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 sL0    Y  | t |d W d    n1 s0    Y  | t |d  W d    n1 s0    Y  d S Nr{  r}  r   r~  whiskyr   r   r   rt   r/   r   r   rK   r(   r(   r)   #test_validate_required_choice_block  s    ((z3TestChoiceBlock.test_validate_required_choice_blockc                 C   s>   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  s    
z4TestChoiceBlock.test_adapt_non_required_choice_blockc                 C   s   t jddgdd}| |dd | t |d W d    n1 sN0    Y  | |dd | |d d d S Nr{  r}  Fr  r~  r  r   r  rK   r(   r(   r)   'test_validate_non_required_choice_block  s    (z7TestChoiceBlock.test_validate_non_required_choice_blockc                 C   sF   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   rt   rm  r   r   r(   r(   r)   2test_adapt_choice_block_with_existing_blank_choice  s    
zBTestChoiceBlock.test_adapt_choice_block_with_existing_blank_choicec                 C   sJ   dd }t j|dd}|d t |}| t|d jg d d S )Nc                   S   s   g dS Nr  r(   r(   r(   r(   r)   r    s    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  s    
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ZginZGinr  Z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   sv   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                   @   s   e Zd ZddgZdS )z=TestChoiceBlock.test_subclassing.<locals>.BeverageChoiceBlockr{  r}  Nr6   r7   r8   r   r(   r(   r(   r)   BeverageChoiceBlock+  s   r  Fr   r   r   r  wagtail.blocks.ChoiceBlockr{  r}  r  	r   r   r   r   r   rt   rm  r   deconstruct)r3   r  r'   r   r(   r(   r)   test_subclassing*  s"    


z TestChoiceBlock.test_subclassingc                 C   s(   t jddgd}| |ddg d S Nr   r   r   r   r   r   r   rt   r   rK   r(   r(   r)   r   L  s    z'TestChoiceBlock.test_searchable_contentc                 C   s(   t jddgdd}| |dg  d S Nr   r   F)r   r   r   r  rK   r(   r(   r)   r   U  s    z4TestChoiceBlock.test_search_index_searchable_contentc                 C   s,   dd }t j|d}| |ddg d S )Nc                   S   s   ddgS Nr   r   r(   r(   r(   r(   r)   r  `  s    zWTestChoiceBlock.test_searchable_content_with_callable_choices.<locals>.callable_choicesr   r   r   r  r3   r  r'   r(   r(   r)   -test_searchable_content_with_callable_choices_  s    z=TestChoiceBlock.test_searchable_content_with_callable_choicesc                 C   s:   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  rK   r(   r(   r)    test_optgroup_searchable_contenti  s    z0TestChoiceBlock.test_optgroup_searchable_contentc                 C   s&   t jddgd}| |dg  d S N)oneZOne)ZtwoZTwor   Zthreer  rK   r(   r(   r)   test_invalid_searchable_content~  s    z/TestChoiceBlock.test_invalid_searchable_contentc                 C   sL   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(  r*  r)  rt   r`  r(   r(   r)   -test_searchable_content_with_lazy_translation  s    


z=TestChoiceBlock.test_searchable_content_with_lazy_translationc                 C   sv   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  s     




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   s   ddgS r  r(   r(   r(   r(   r)   r    s    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   sX   ddg}dd }t j||gd}| t |d W d    n1 sJ0    Y  d S )Nr{  r}  c                 S   s   t dd S NzYou must select 'tea'r   r#   r(   r(   r)   validate_tea_is_selected  s    zLTestChoiceBlock.test_render_with_validator.<locals>.validate_tea_is_selectedr   r   r~  )r   r   r   r   r/   r3   r   r  r'   r(   r(   r)   r    s    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   rt   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   Zwidgetr|  )r   r   r   ZRadioSelectr   rt   r   r(   r(   r)   %test_get_form_state_with_radio_widget  s
    

z5TestChoiceBlock.test_get_form_state_with_radio_widgetN)r6   r7   r8   rz  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)   ru  X  s.   
,/"	

	!ru  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/S )0TestMultipleChoiceBlockc                 C   s   ddl m} |d d | _d S rv  rx  ry  r(   r(   r)   rz    s    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   rt   rz   r   r   rm  r   rJ   rj   r   r(   r(   r)    test_adapt_multiple_choice_block  s.    
z8TestMultipleChoiceBlock.test_adapt_multiple_choice_blockc                 C   s&   t jddgdd}| | d d S r  )r   r  rt   rB  rK   r(   r(   r)   'test_multiple_choice_block_with_default  s    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   s   ddgS r  r(   r(   r(   r(   r)   r    s    zhTestMultipleChoiceBlock.test_adapt_multiple_choice_block_with_callable_choices.<locals>.callable_choicesr   r   r   r{  r}  )r   r  r   r   r   rz   r   r   rt   rm  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 sR0    Y  | t |d W d    n1 s0    Y  | t |d  W d    n1 s0    Y  d S r  r   r  rt   r/   r   r   rK   r(   r(   r)   ,test_validate_required_multiple_choice_block!  s    *(zDTestMultipleChoiceBlock.test_validate_required_multiple_choice_blockc                 C   s>   t jddgdd}|d t |}| |d d  d S r  )r   r  r   r   r   r  r   r(   r(   r)   -test_adapt_non_required_multiple_choice_block0  s    
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 sT0    Y  | |dg  | |d g  d S r  r  rK   r(   r(   r)   0test_validate_non_required_multiple_choice_block:  s    *zHTestMultipleChoiceBlock.test_validate_non_required_multiple_choice_blockc                 C   sF   t jg ddd}|d t |}| t|d jg d d S r  r   r  r   r   r   rt   rm  r   r   r(   r(   r)   ;test_adapt_multiple_choice_block_with_existing_blank_choiceF  s    
zSTestMultipleChoiceBlock.test_adapt_multiple_choice_block_with_existing_blank_choicec                 C   sJ   dd }t j|dd}|d t |}| t|d jg d d S )Nc                   S   s   g dS r  r(   r(   r(   r(   r)   r  W  s    zTestMultipleChoiceBlock.test_adapt_multiple_choice_block_with_existing_blank_choice_and_with_callable_choices.<locals>.callable_choicesFr  r   r   r  r  r  r(   r(   r)   Utest_adapt_multiple_choice_block_with_existing_blank_choice_and_with_callable_choicesT  s    
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   r  r   r(   r(   r)   r  d  s:    
z>TestMultipleChoiceBlock.test_named_groups_without_blank_optionc                 C   sv   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 r  r  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                   @   s   e Zd ZddgZdS )zMTestMultipleChoiceBlock.test_subclassing.<locals>.BeverageMultipleChoiceBlockr{  r}  Nr  r(   r(   r(   r)   BeverageMultipleChoiceBlock  s   r  Fr   r   r   r{  r}  "wagtail.blocks.MultipleChoiceBlockr  	r   r  r   r   r   rt   rm  r   r  )r3   r  r'   r   r(   r(   r)   r    s&    

	z(TestMultipleChoiceBlock.test_subclassingc                 C   s(   t jddgd}| |ddg d S r  r   r  rt   r   rK   r(   r(   r)   r     s    z/TestMultipleChoiceBlock.test_searchable_contentc                 C   s(   t jddgdd}| |dg  d S r  r  rK   r(   r(   r)   r     s    z<TestMultipleChoiceBlock.test_search_index_searchable_contentc                 C   s,   dd }t j|d}| |ddg d S )Nc                   S   s   ddgS r  r(   r(   r(   r(   r)   r    s    z_TestMultipleChoiceBlock.test_searchable_content_with_callable_choices.<locals>.callable_choicesr   r   r   r  r  r(   r(   r)   r    s    zETestMultipleChoiceBlock.test_searchable_content_with_callable_choicesc                 C   s:   t jdddgfdddgfgd}| |ddd	g d S r  r  rK   r(   r(   r)   r    s    z8TestMultipleChoiceBlock.test_optgroup_searchable_contentc                 C   s&   t jddgd}| |dg  d S r  r  rK   r(   r(   r)   r    s    z7TestMultipleChoiceBlock.test_invalid_searchable_contentc                 C   sL   t jdtdfdtdfgd}|d}tt|}| |dg d S r  r   r  r  r   r(  r*  r)  rt   r`  r(   r(   r)   r    s    


zETestMultipleChoiceBlock.test_searchable_content_with_lazy_translationc                 C   sv   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 r  r  r`  r(   r(   r)   r  &  s     




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   s   ddgS r  r(   r(   r(   r(   r)   r  @  s    zXTestMultipleChoiceBlock.test_deconstruct_with_callable_choices.<locals>.callable_choicesFr  r   r   r{  r}  r  r  r  r(   r(   r)   r  ?  s&    
z>TestMultipleChoiceBlock.test_deconstruct_with_callable_choicesc                 C   sX   ddg}dd }t j||gd}| t |d W d    n1 sJ0    Y  d S )Nr{  r}  c                 S   s   t dd S r  r   r#   r(   r(   r)   r  e  s    zTTestMultipleChoiceBlock.test_render_with_validator.<locals>.validate_tea_is_selectedr  r~  )r   r  r   r   r/   r  r(   r(   r)   r  _  s    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   rt   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   ZCheckboxSelectMultipler   rt   r   r(   r(   r)   (test_get_form_state_with_checkbox_widgetv  s    z@TestMultipleChoiceBlock.test_get_form_state_with_checkbox_widgetN)r6   r7   r8   rz  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    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S )TestRawHTMLBlockc                 C   s(   t   }| |d | |t d S r   r   RawHTMLBlockrB  rt   rz   r   rD  r(   r(   r)   rF    s    z5TestRawHTMLBlock.test_get_default_with_fallback_valuec                 C   s,   t jd d }| |d | |t d S rG  r  rD  r(   r(   r)   test_get_default_with_none  s    z+TestRawHTMLBlock.test_get_default_with_nonec                 C   s,   t jdd }| |d | |t d S rI  r  rD  r(   r(   r)   rJ    s    z3TestRawHTMLBlock.test_get_default_with_empty_stringc                 C   s,   t jdd }| |d | |t d S )N   <blink>BÖÖM</blink>rZ   r  rD  r(   r(   r)   rL    s    z6TestRawHTMLBlock.test_get_default_with_nonempty_stringc                 C   s2   t  }|td}| |d | |t d S Nr  )r   r  r   r   rt   ZassertNotIsInstancer   r`  r(   r(   r)   test_serialize  s    zTestRawHTMLBlock.test_serializec                 C   s.   t  }|d}| |d | |t d S r  )r   r  r   rt   rz   r   r`  r(   r(   r)   test_deserialize  s    
z!TestRawHTMLBlock.test_deserializec                 C   s2   t  }|td}| |d | |t d S r  )r   r  rs   r   rt   rz   r   r`  r(   r(   r)   r     s    zTestRawHTMLBlock.test_renderc                 C   s"   t  }|d}| |d d S r  )r   r  r   rt   r   r(   r(   r)   r    s    
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 )NZtest_rawhtmlblockr   r   Z4010)colsrowsr   zTest rawhtmlblockr   Tcodez-w-field w-field--char_field w-field--textarear   r   r   )r   r  r   r   r   rt   rz   r   ZTextareaattrsrJ   rj   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rawhtmlr  r   )r   r  r   rt   rz   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 )Nr  Zohair   nothing-herenope)r   r  r  value_omitted_from_data
assertTruerK   r(   r(   r)   test_value_omitted_from_data  s    z-TestRawHTMLBlock.test_value_omitted_from_datac                 C   sj   t  }|td}| |d | |t | t |td W d    n1 s\0    Y  d S )Nr  r   )	r   r  r/   r   rt   rz   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   r  r   )r   r  r/   r   rt   rz   r   r`  r(   r(   r)   test_clean_nonrequired_field  s    z-TestRawHTMLBlock.test_clean_nonrequired_fieldc                 C   sR   dd }t j|gd}| t |td W d    n1 sD0    Y  d S )Nc                 S   s   d| vrt dd S rb  r   r#   r(   r(   r)   rc    s    zJTestRawHTMLBlock.test_render_with_validator.<locals>.validate_contains_foor   rd  )r   r  r   r   r/   r   re  r(   r(   r)   r    s    z+TestRawHTMLBlock.test_render_with_validatorN)r6   r7   r8   rF  r  rJ  rL  r  r  r   r  r  r  r  r  r  r  r(   r(   r(   r)   r    s   
	
r  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                   @   s   e Zd ZG dd dZdS )z:TestMeta.test_set_template_with_meta.<locals>.HeadingBlockc                   @   s   e Zd ZdZdS )z?TestMeta.test_set_template_with_meta.<locals>.HeadingBlock.Metaheading.htmlNr6   r7   r8   r~   r(   r(   r(   r)   Meta  s   r  Nr6   r7   r8   r  r(   r(   r(   r)   HeadingBlock  s   r  r  r   r9   rt   r{   r~   r3   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 )Nr  r}   r  rK   r(   r(   r)   "test_set_template_with_constructor  s    z+TestMeta.test_set_template_with_constructorc                 C   s0   G dd dt j}|dd}| |jjd d S )Nc                   @   s   e Zd ZG dd dZdS )zPTestMeta.test_set_template_with_constructor_overrides_meta.<locals>.HeadingBlockc                   @   s   e Zd ZdZdS )zUTestMeta.test_set_template_with_constructor_overrides_meta.<locals>.HeadingBlock.Metar  Nr  r(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   r    s   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                   @   s   e Zd ZG dd dZdS )z;TestMeta.test_meta_nested_inheritance.<locals>.HeadingBlockc                   @   s   e Zd ZdZdZdS )z@TestMeta.test_meta_nested_inheritance.<locals>.HeadingBlock.Metar  FooN)r6   r7   r8   r~   testr(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   r    s   r  c                   @   s   e Zd ZG dd dZdS )z>TestMeta.test_meta_nested_inheritance.<locals>.SubHeadingBlockc                   @   s   e Zd ZdZdS )zCTestMeta.test_meta_nested_inheritance.<locals>.SubHeadingBlock.Metar  Nr  r(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   SubHeadingBlock  s   r  r  r  N)r   r9   rt   r{   r~   r  )r3   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                   @   s   e Zd ZG dd dZdS )z7TestMeta.test_meta_multi_inheritance.<locals>.LeftBlockc                   @   s   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)r6   r7   r8   r~   clashry   r(   r(   r(   r)   r  !  s   r  Nr  r(   r(   r(   r)   	LeftBlock   s   r  c                   @   s   e Zd ZG dd dZdS )z8TestMeta.test_meta_multi_inheritance.<locals>.RightBlockc                   @   s   e Zd ZdZdZdZdS )z=TestMeta.test_meta_multi_inheritance.<locals>.RightBlock.Metahelloz	the albumzRight blockN)r6   r7   r8   r[   r  ry   r(   r(   r(   r)   r  '  s   r  Nr  r(   r(   r(   r)   
RightBlock&  s   r  c                   @   s   e Zd ZG dd dZdS )z8TestMeta.test_meta_multi_inheritance.<locals>.ChildBlockc                   @   s   e Zd ZdZdS )z=TestMeta.test_meta_multi_inheritance.<locals>.ChildBlock.MetaChild blockNr6   r7   r8   ry   r(   r(   r(   r)   r  -  s   r  Nr  r(   r(   r(   r)   
ChildBlock,  s   r  r   r  r  r  N)r   r9   rt   r{   r~   r[   r  ry   )r3   r  r  r  r'   r(   r(   r)   test_meta_multi_inheritance  s    z$TestMeta.test_meta_multi_inheritanceN)r6   r7   r8   r  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"dAS )BTestStructBlockc                 C   s<   t dt  fdt  fg}| t|j ddg d S )Ntitlelink)r   rh   r9   URLBlockrt   rm  child_blockskeysrK   r(   r(   r)   test_initialisation?  s    

z#TestStructBlock.test_initialisationc                 C   s6   G dd dt j}| }| t|j ddg d S )Nc                   @   s   e Zd Ze Ze ZdS )zDTestStructBlock.test_initialisation_from_subclass.<locals>.LinkBlockNr6   r7   r8   r   r9   r  r  r  r(   r(   r(   r)   r   J  s   r   r  r  r   rh   rt   rm  r  r  r3   r   r'   r(   r(   r)   !test_initialisation_from_subclassI  s    z1TestStructBlock.test_initialisation_from_subclassc                 C   sB   G dd dt j}|dt  fg}| t|j g d d S )Nc                   @   s   e Zd Ze Ze ZdS )zOTestStructBlock.test_initialisation_from_subclass_with_extra.<locals>.LinkBlockNr  r(   r(   r(   r)   r   S  s   r   r   r  r  r   )r   rh   r9   rt   rm  r  r  r  r(   r(   r)   ,test_initialisation_from_subclass_with_extraR  s
    z<TestStructBlock.test_initialisation_from_subclass_with_extrac                 C   sF   G dd dt j}G dd d|}| }| t|j g d d S )Nc                   @   s   e Zd Ze Ze ZdS )zPTestStructBlock.test_initialisation_with_multiple_subclassses.<locals>.LinkBlockNr  r(   r(   r(   r)   r   ^  s   r   c                   @   s   e Zd Ze ZdS )zVTestStructBlock.test_initialisation_with_multiple_subclassses.<locals>.StyledLinkBlockNr6   r7   r8   r   r9   r   r(   r(   r(   r)   StyledLinkBlockb  s   r  r  r  )r3   r   r  r'   r(   r(   r)   -test_initialisation_with_multiple_subclassses]  s    z=TestStructBlock.test_initialisation_with_multiple_subclasssesc                 C   sZ   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                   @   s   e Zd Ze Ze ZdS )zBTestStructBlock.test_initialisation_with_mixins.<locals>.LinkBlockNr  r(   r(   r(   r)   r   y  s   r   c                   @   s   e Zd Ze ZdS )zETestStructBlock.test_initialisation_with_mixins.<locals>.StylingMixinNr  r(   r(   r(   r)   StylingMixin}  s   r  c                   @   s   e Zd Ze ZdS )zHTestStructBlock.test_initialisation_with_mixins.<locals>.StyledLinkBlockNr6   r7   r8   r   r9   rC  r(   r(   r(   r)   r    s   r  r  r  r   rC  Nr  )r3   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                   @   s   e Zd Ze Ze ZdS )z.TestStructBlock.test_render.<locals>.LinkBlockNr  r(   r(   r(   r)   r     s   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   rh   rs   r   joinZassertHTMLEqual)r3   r   r'   rv   Z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                   @   s   e Zd ZdddZdS )zjTestStructBlock.test_get_api_representation_calls_same_method_on_fields_with_context.<locals>.ContextBlockNc                 S   s   || S r=   r(   rQ   r(   r(   r)   get_api_representation  s    zTestStructBlock.test_get_api_representation_calls_same_method_on_fields_with_context.<locals>.ContextBlock.get_api_representation)Nr6   r7   r8   r'  r(   r(   r(   r)   ContextBlock  s   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)r6   r7   r8   r   authorr(   r)  r(   r)   AuthorBlock  s   r,  enwagtail)r   r*  EnglishWagtail!r-  r.  r   N)r   r9   rh   r'  ZassertDictEqual)r3   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                   @   s   e Zd Ze Ze ZdS )z<TestStructBlock.test_render_unknown_field.<locals>.LinkBlockNr  r(   r(   r(   r)   r     s   r   r  r  r   )r  r  imager"  r#  r$  r%  z<dt>image</dt>)r   rh   rs   r   r   assertNotIn)r3   r   r'   rv   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                   @   s   e Zd Ze Ze ZdS )z=TestStructBlock.test_render_bound_block.<locals>.SectionBlockN)r6   r7   r8   r   r9   r  rA  bodyr(   r(   r(   r)   r     s   r   r  <b>world</b>r  r7  r7  )r   rh   r   bound_blocksrt   r>   )r3   r   r'   struct_valueZ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                   @   s   e Zd Ze Ze ZdS )z8TestStructBlock.test_get_form_context.<locals>.LinkBlockNr  r(   r(   r(   r)   r     s   r   r  r  r   mylinkr  childrenr   r  r  Zblock_definitionr   )r   rh   Zget_form_contextr   rz   collectionsOrderedDictrt   r   Z
BoundBlockr$   )r3   r   r'   rR   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     s   r   test_structblockr   r   Test structblockr   Fr   struct-block)ry   r   r   r   r   r   r   r   r  r  )
r   rh   r   r   r   rt   rJ   rj   r   r  )r3   r   r'   r   Ztitle_fieldZ
link_fieldr(   r(   r)   r    s(    
zTestStructBlock.test_adaptc                 C   sX   G dd dt j}| }|d t |}| |d dddd|j|jd	d
d d S )Nc                   @   s2   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                   @   s   e Zd ZdZdS )zETestStructBlock.test_adapt_with_form_template.<locals>.LinkBlock.Metaz1tests/block_forms/struct_block_form_template.htmlNr6   r7   r8   Zform_templater(   r(   r(   r)   r  &  s   r  N	r6   r7   r8   r   r9   r  r  r  r  r(   r(   r(   r)   r   "  s   r   rC  r   rD  r   Fr   rE  <div>Hello</div>ry   r   r   r   r   r   r   ZformTemplater   rh   r   r   r   rt   rJ   rj   r3   r   r'   r   r(   r(   r)   test_adapt_with_form_template!  s     
z-TestStructBlock.test_adapt_with_form_templatec                 C   sX   G dd dt j}| }|d t |}| |d dddd|j|jd	d
d d S )Nc                   @   s2   e Zd ZejddZejddZG dd dZdS )zFTestStructBlock.test_adapt_with_form_template_jinja.<locals>.LinkBlockFr   c                   @   s   e Zd ZdZdS )zKTestStructBlock.test_adapt_with_form_template_jinja.<locals>.LinkBlock.Metaz,tests/jinja2/struct_block_form_template.htmlNrF  r(   r(   r(   r)   r  A  s   r  NrG  r(   r(   r(   r)   r   =  s   r   rC  r   rD  r   Fr   rE  rH  rI  rJ  rK  r(   r(   r)   #test_adapt_with_form_template_jinja<  s     
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TorchboxrZ   http://www.torchbox.comNr  r(   r(   r(   r)   r   X  s   r   r  rN  )r   rh   rB  rt   get)r3   r   r'   Z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                   @   s   e Zd ZdZdS )zITestStructBlock.test_adapt_with_help_text_on_meta.<locals>.LinkBlock.MetaSelf-promotion is encouragedN)r6   r7   r8   r   r(   r(   r(   r)   r  e  s   r  NrG  r(   r(   r(   r)   r   a  s   r   rC  r   rD  rR  Fr   rE  Z<svg class="icon icon-help default" aria-hidden="true"><use href="#icon-help"></use></svg>	ry   r   r   r   r   r   r   ZhelpIconr   rJ  rK  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                   @   s   e Zd Ze Ze ZdS )zHTestStructBlock.test_adapt_with_help_text_as_argument.<locals>.LinkBlockNr  r(   r(   r(   r)   r     s   r   rR  r   rC  r   rD  Fr   rE  rS  rT  rJ  rK  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                   @   s   e Zd Ze Ze ZdS )z:TestStructBlock.test_searchable_content.<locals>.LinkBlockNr  r(   r(   r(   r)   r     s   r   r  r  r   )r   rh   r   r   rt   r3   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  rN  rO  mylink-titlezmylink-linkr>  )
r   rh   r9   r  r   rt   rz   StructValuer:  r'   )r3   r'   Z
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  rY  rN  r>  r  r  )r   rh   r9   r  r  r  r  rK   r(   r(   r)   r    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                   @   s   e Zd Ze Ze ZdS )zLTestStructBlock.test_default_is_returned_as_structvalue.<locals>.PersonBlockNr6   r7   r8   r   r9   
first_namesurnamer(   r(   r(   r)   PersonBlock  s   r_  c                       s$   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^  rZ   Nr6   r7   r8   r   r9   r  guest_speakerr(   r_  r(   r)   
EventBlock  s   rf  r  Birthday partyrd  r]  r`  N)r   rh   r   rt   rz   rZ  )r3   rf  event_blockeventr(   re  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                   @   s   e Zd Ze Ze ZdS )zLTestStructBlock.test_default_value_is_distinct_instance.<locals>.PersonBlockNr\  r(   r(   r(   r)   r_    s   r_  c                       s$   e Zd Ze Z ddddZdS )zKTestStructBlock.test_default_value_is_distinct_instance.<locals>.EventBlockr`  ra  rb  rZ   Nrc  r(   re  r(   r)   rf    s   rf  r  rg  zChristmas partyZMilibandrd  r^  ra  N)r   rh   r   rt   )r3   rf  rh  Zevent1Zevent2r(   re  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                   @   s&   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	chocolaterZ   Nr6   r7   r8   r   r9   shoprf   itemsr(   r(   r(   r)   ShoppingListBlock	  s   rp  rn  TescoAsdar   ro  cakerl  r   N)r   rh   bulk_to_pythonappendrt   rm  )r3   rp  r'   Z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    n1 s0    Y  d S )Nr  r  rN  http://www.torchbox.com/r   	not a url)r   rh   r9   r  r   r/   rz   rZ  rt   r   r   )r3   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 sL0    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   )r3   r$   rO  r4   r(   r)   r/   7	  s    zHTestStructBlock.test_non_block_validation_error.<locals>.LinkBlock.clean)
r6   r7   r8   r   PageChooserBlockr{  r  r   r/   r;   r(   r(   r4   r)   r   3	  s   r   r   )r{  r   zhttps://wagtail.org/)r   rh   r   r   r/   rt   )r3   r   r'   Zbad_dataZ	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> worldr9  !<h1>Hello</h1><i>italic</i> worldNr   r   rs   rt   rN  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>r9  r   r   r   z/<h1 lang="fr">Bonjour</h1>monde <i>italique</i>r  rN  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
        r~  r  r9  r  N)r   r   Z__html__rt   render_as_blockrN  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
        r~  r  r9  z<h1>rZ  r  N)r   r   r>   r5  r   rN  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  rt   rN  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 )Nr~  worldr9  )
r   r   copyassertIsNotrz   r   rZ  rD   r'   rt   )r3   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   rh   r9   rt   rF   Z_to_struct_valuerK   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)r  rq  )r  *   )            )r  r  r   r   N)r   rh   rg   r9   r   rf   rF   rz   rZ  StreamValueZStreamChild
list_block	ListValuer   rr  r(   r(   r)   test_recursive_normalize	  s2    

	
z(TestStructBlock.test_recursive_normalizeN)#r6   r7   r8   r  r  r  r  r  r   r3  r6  r=  rB  r  rL  rM  rQ  rU  rV  r   r[  r  rj  rk  rv  rz  r}  r  r  r  r  r  r  r  r  r(   r(   r(   r)   r
  >  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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    n1 s0    Y  d S )Nc                   @   s   e Zd Zdd ZdS )zSTestStructBlockWithCustomStructValue.test_initialisation.<locals>.CustomStructValuec                 S   s   |  dd|  dd S )Nr  r   r  rP  rU   r(   r(   r)   joined	  s    zZTestStructBlockWithCustomStructValue.test_initialisation.<locals>.CustomStructValue.joinedN)r6   r7   r8   r  r(   r(   r(   r)   CustomStructValue	  s   r  r  r  )value_classrg  zhttps://myparty.co.ukr   rN  rO  rX  r>  rw  rx  )r   rZ  rh   r9   r  rt   rm  r  r  r   rz   rB  r   r/   r   r   )r3   r  r'   block_valuerE  r   r$   ry  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                   @   s   e Zd Zdd ZdS )z_TestStructBlockWithCustomStructValue.test_initialisation_from_subclass.<locals>.LinkStructValuec                 S   s   |  dp|  dS Nr{  r  r  rU   r(   r(   r)   r   	  s    zcTestStructBlockWithCustomStructValue.test_initialisation_from_subclass.<locals>.LinkStructValue.urlNr6   r7   r8   r   r(   r(   r(   r)   LinkStructValue	  s   r  c                       s>   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                       s   e Zd Z ZdS )z^TestStructBlockWithCustomStructValue.test_initialisation_from_subclass.<locals>.LinkBlock.MetaNr6   r7   r8   r  r(   r  r(   r)   r  	  s   r  Nr6   r7   r8   r   r9   r  r|  r{  r  r  r  r(   r  r(   r)   r   	  s   r   )r  r{  r  Websitehttps://website.comr   )
r   rZ  rh   rt   rm  r  r  r   rz   rB  )r3   r   r'   r  rE  r(   r  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                   @   s   e Zd Zdd ZdS )zkTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.LinkStructValuec                 S   s   |  dp|  dS r  r  rU   r(   r(   r)   r   
  s    zoTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.LinkStructValue.urlNr  r(   r(   r(   r)   r  
  s   r  c                       s>   e Zd Ze ZejddZejddZ	G  fdddZ
dS )zeTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.LinkBlockFr   c                       s   e Zd Z ZdS )zjTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.LinkBlock.MetaNr  r(   r  r(   r)   r  

  s   r  Nr  r(   r  r(   r)   r   
  s   r   c                   @   s   e Zd Ze ZdS )zkTestStructBlockWithCustomStructValue.test_initialisation_with_multiple_subclassses.<locals>.StyledLinkBlockNr  r(   r(   r(   r)   r  
  s   r  )r  r{  r  r   rN  rO  Zfullsize)zqueen-titlez
queen-linkzqueen-classnameZqueen)	r   rZ  rh   rt   rm  r  r  r   rz   )r3   r   r  r'   r   r(   r  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                   @   s   e Zd ZdS )z]TestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.LinkStructValueNr6   r7   r8   r(   r(   r(   r)   r  #
  s   r  c                       s.   e Zd Ze Ze ZG  fdddZdS )zWTestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.LinkBlockc                       s   e Zd Z ZdS )z\TestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.LinkBlock.MetaNr  r(   r  r(   r)   r  *
  s   r  NrG  r(   r  r(   r)   r   &
  s   r   c                   @   s   e Zd Ze ZdS )zZTestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.StylingMixinNr  r(   r(   r(   r)   r  -
  s   r  c                   @   s   e Zd Ze ZdS )z]TestStructBlockWithCustomStructValue.test_initialisation_with_mixins.<locals>.StyledLinkBlockNr  r(   r(   r(   r)   r  0
  s   r  r  r  r  Zgooglez	full-size)r  r  rC  r   )	r   rZ  rh   rt   rm  r  r  r   rz   )r3   r   r  r  r'   r  r(   r  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   r  rU   r(   r(   r)   r"   E
  s    zXTestStructBlockWithCustomStructValue.test_value_property.<locals>.SectionStructValue.fooN)r6   r7   r8   propertyr"   r(   r(   r(   r)   SectionStructValueD
  s   r  c                       s.   e Zd Ze Ze ZG  fdddZdS )zNTestStructBlockWithCustomStructValue.test_value_property.<locals>.SectionBlockc                       s   e Zd Z ZdS )zSTestStructBlockWithCustomStructValue.test_value_property.<locals>.SectionBlock.MetaNr  r(   r  r(   r)   r  M
  s   r  N)	r6   r7   r8   r   r9   r  rA  r7  r  r(   r  r(   r)   r   I
  s   r   r  r8  r9  z	bar hello)r   rZ  rh   r   r"   rt   )r3   r   r'   r;  r$   r(   r  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                   @   s   e Zd Zdd ZdS )zZTestStructBlockWithCustomStructValue.test_render_with_template.<locals>.SectionStructValuec                 S   s   |  d}|rd| S dS )Nr  z	SUFFIX %szEMPTY TITLEr  )r3   r  r(   r(   r)   title_with_suffixW
  s    
zlTestStructBlockWithCustomStructValue.test_render_with_template.<locals>.SectionStructValue.title_with_suffixN)r6   r7   r8   r  r(   r(   r(   r)   r  V
  s   r  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                       s   e Zd Z ZdS )zYTestStructBlockWithCustomStructValue.test_render_with_template.<locals>.SectionBlock.MetaNr  r(   r  r(   r)   r  `
  s   r  N)r6   r7   r8   r   r9   r  r  r(   r  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   rZ  rh   r   rs   rt   )r3   r   r'   r;  rv   r(   r  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                   @   s   e Zd ZdS )zNTestStructBlockWithCustomStructValue.test_normalize.<locals>.CustomStructValueNr  r(   r(   r(   r)   r  o
  s   r  c                       s&   e Zd Ze ZG  fdddZdS )zNTestStructBlockWithCustomStructValue.test_normalize.<locals>.CustomStructBlockc                       s   e Zd Z ZdS )zSTestStructBlockWithCustomStructValue.test_normalize.<locals>.CustomStructBlock.MetaNr  r(   r  r(   r)   r  u
  s   r  Nr6   r7   r8   r   	TextBlockr:   r  r(   r  r(   r)   CustomStructBlockr
  s   r  r:   zShe sells sea shellsNr   rZ  rh   rz   rF   )r3   r  r(   r  r)   rH   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                   @   s   e Zd ZdS )zdTestStructBlockWithCustomStructValue.test_normalize_incorrect_value_class.<locals>.CustomStructValueNr  r(   r(   r(   r)   r  
  s   r  c                       s&   e Zd Ze ZG  fdddZdS )zdTestStructBlockWithCustomStructValue.test_normalize_incorrect_value_class.<locals>.CustomStructBlockc                       s   e Zd Z ZdS )ziTestStructBlockWithCustomStructValue.test_normalize_incorrect_value_class.<locals>.CustomStructBlock.MetaNr  r(   r  r(   r)   r  
  s   r  Nr  r(   r  r(   r)   r  
  s   r  r:   zThe quick brown foxNr  )r3   r  r'   r$   r(   r  r)   $test_normalize_incorrect_value_class}
  s
    zITestStructBlockWithCustomStructValue.test_normalize_incorrect_value_classN)r6   r7   r8   r  r  r  r  r  r  rH   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"dAS )BTestListBlockc                 C   s   |  t|t| d S r=   )rt   rm  )r3   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   rf   r9   rz   child_blockrK   r(   r(   r)   test_initialise_with_class
  s    z(TestListBlock.test_initialise_with_classc                 C   s$   t  }t |}| |j| d S r=   )r   r9   rf   rt   r  )r3   r  r'   r(   r(   r)   test_initialise_with_instance
  s    
z+TestListBlock.test_initialise_with_instancec                 C   s8   G dd dt j}t | }|ddddddgS )Nc                   @   s   e Zd Ze Ze ZdS )z'TestListBlock.render.<locals>.LinkBlockNr  r(   r(   r(   r)   r   
  s   r   Wagtailr  r   Djangohttp://www.djangoproject.com)r   rh   rf   rs   r  r(   r(   r)   rs   
  s    zTestListBlock.renderc                 C   s$   |   }| d| | d| d S )Nz<ul>z</ul>rs   r   r3   rv   r(   r(   r)   test_render_uses_ul
  s    z!TestListBlock.test_render_uses_ulc                 C   s$   |   }| d| | d| d S )Nz<li>z</li>r  r  r(   r(   r)   test_render_uses_li
  s    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}   rq   zGoodbye world!r   z<h1>Goodbye world!</h1>Nr   rf   r9   rs   r   ru   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  ru   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                   @   s   e Zd ZdddZdS )zjTestListBlock.test_get_api_representation_calls_same_method_on_children_with_context.<locals>.ContextBlockNc                 S   s   || S r=   r(   rQ   r(   r(   r)   r'  
  s    zTestListBlock.test_get_api_representation_calls_same_method_on_children_with_context.<locals>.ContextBlock.get_api_representation)Nr(  r(   r(   r(   r)   r)  
  s   r)  r-  r   rq   r   )r-  r   r   N)r   r9   rf   r'  rt   r3   r)  r'   r2  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                   @   s   e Zd Ze Ze ZdS )z+TestListBlock.test_adapt.<locals>.LinkBlockNr  r(   r(   r(   r)   r   
  s   r   test_listblockr   r   r   r   r   Test listblockr   r   FDelete	Duplicate	Move downMove upDragAddDELETEZ	DUPLICATEZ	MOVE_DOWNZMOVE_UPZDRAGZADDry   r   r   r   r   r   	collapsedr   
r   rh   rf   r   r   r   rt   rz   rJ   rj   rK  r(   r(   r)   r  
  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                   @   s   e Zd Ze Ze ZdS )z@TestListBlock.test_adapt_with_min_num_max_num.<locals>.LinkBlockNr  r(   r(   r(   r)   r     s   r   r   r  )min_nummax_numr  r   r   r   r   r  r   r   Fr  r  r  r  r  r  r  )
ry   r   r   r   r   r   r  minNummaxNumr   r  rK  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                   @   s   e Zd Ze Ze ZdS )z8TestListBlock.test_searchable_content.<locals>.LinkBlockNr  r(   r(   r(   r)   r   ;  s   r   r  r  r   r  r  )r   rh   rf   r   rt   rW  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0Zmylistrl  r  r   )r  zmylist-0-valuezmylist-0-deletedzmylist-0-orderr  r  )r   rf   r9   r  r  r  rK   r(   r(   r)   r  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 1Z00000001)r   rf   r9   rangeupdater>   r   rt   r:  r$   idr3   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   rf   r9   r  r  r>   r   rt   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)ZpeasZbeansZcarrotsrZ   )r   rf   r9   rt   rm  rB  rK   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.
        rl  rZ   Ztest_shoppinglistblockr   N)	r   rf   r9   rt   rm  rB  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                   @   s&   e Zd Ze ZeejddZdS )zPTestListBlock.test_default_value_is_distinct_instance.<locals>.ShoppingListBlockrl  rZ   Nrm  r(   r(   r(   r)   rp    s   rp  rn  rq  rr  ro  rs  rl  N)r   rh   r   ru  rt   rm  )r3   rp  r'   Ztesco_shoppingZasda_shoppingr(   r(   r)   rk    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                   @   s   e Zd Ze Ze ZdS )zDTestListBlock.test_adapt_with_classname_via_kwarg.<locals>.LinkBlockNr  r(   r(   r(   r)   r     s   r   zspecial-list-classr   r  r   r  r   r   Fr  r  r  r  r  r  r  r  N	r   rh   rf   r   r   r   rt   rJ   rj   rK  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                   @   s   e Zd Ze Ze ZdS )zITestListBlock.test_adapt_with_classname_via_class_meta.<locals>.LinkBlockNr  r(   r(   r(   r)   r     s   r   c                   @   s   e Zd ZG dd dZdS )zOTestListBlock.test_adapt_with_classname_via_class_meta.<locals>.CustomListBlockc                   @   s   e Zd ZdZdS )zTTestListBlock.test_adapt_with_classname_via_class_meta.<locals>.CustomListBlock.Metacustom-list-classNr6   r7   r8   r   r(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   CustomListBlock  s   r  r  r   r  r   r   r  Fr  r  r  r  r  r  r  r  Nr  )r3   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  rM   $22222222-2222-2222-2222-222222222222r   )r   rf   r9   r   r/   rt   r:  r  )r3   r'   r  Z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 sH0    Y  | |j	 ddgi |ddg}| 
|| d S )Nr   r  r"   r5   The minimum number of items is 2rM   r   rf   r9   r   r   r   r/   rt   r4  as_json_datar  r3   r'   r  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 sJ0    Y  | |j	 ddgi |ddg}| 
|| d S )Nr   r  )r"   rM   bazr5  z The maximum number of items is 2r"   rM   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"   rM   r   r   
[0-9a-f-]+)
r   rf   r9   r   rt   r   r:  r$   assertRegexr  r3   r'   Z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"   rM   )xxxZyyyZzzzr   r   r   r  r  )
r   rf   r9   rt  rt   r   r:  r$   r  r  r3   r'   Zlist_1Z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  rM   r   r   r   )	r   rf   r9   r   rt   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  rM   r   r
  z$33333333-3333-3333-3333-333333333333r   r   r   )	r   rf   r9   rt  rt   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 )NZbullet_listr"   rM   r   r   r$   r   )
r   rg   rf   r9   r   ru  r/   r   rt   r   )r3   stream_blockstream_valueZclean_stream_valuerO  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   rf   r   rF   rz   r  r  r  r3   r'   rs  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 ]2}||}| |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   rf   r   r  r  rF   rz   r  )r3   Zinner_list_blockr'   valuesr$   rs  r(   r(   r)   r    s    

z&TestListBlock.test_recursive_normalizeN)#r6   r7   r8   r  r  r  rs   r  r  r  r  r  r  r  r   r  r  r  r  r  r  rk  r  r  r  r  r  r  r  r  r  r  r  r  r  r(   r(   r(   r)   r  
  s@   "$!%&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 sN0    Y  | || d S N)r   r      r  )Zpk__inr   )	r   objectsfilterr   rf   r|  assertNumQueriesr   assertSequenceEqualr3   page_idsZ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4 |ddgg dgg}dd |D }W d    n1 sR0    Y  | |tjjddtjjddgg tjjddgg d S )Nr   r  r  r   c                 S   s   g | ]}t |qS r(   rm  r&   valr(   r(   r)   
<listcomp>  r+   zATestListBlockWithFixtures.test_bulk_to_python.<locals>.<listcomp>r  )	r   rf   r|  r"  rt  rt   r   r   rP  )r3   r'   rO  Z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Zslugsaint-patrickblock1r  r  r   r$   block2)r   rf   r|  r   r   rP  assertListEqualrm  rn  r   r  r>   r3   r'   christmas_pageZsaint_patrick_pager(   r(   r)   rp    s.    z1TestListBlockWithFixtures.test_extract_referencesN)r6   r7   r8   rt  r'  r-  rp  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   s<   t dt  fdt  fg}| t|j ddg d S )Nheading	paragraphr   rg   r9   rt   rm  r  r  rK   r(   r(   r)   r    s    

z#TestStreamBlock.test_initialisationc                 C   s<   t dt  fdt  fg}| t|j ddg d S )N   heading	   paragraphr:  rK   r(   r(   r)   ,test_initialisation_with_binary_string_names#  s    

z<TestStreamBlock.test_initialisation_with_binary_string_namesc                 C   s6   G dd dt j}| }| t|j ddg d S )Nc                   @   s   e Zd Ze Ze ZdS )zGTestStreamBlock.test_initialisation_from_subclass.<locals>.ArticleBlockNr6   r7   r8   r   r9   r8  r9  r(   r(   r(   r)   ArticleBlock/  s   r?  r8  r9  r   rg   rt   rm  r  r  r3   r?  r'   r(   r(   r)   r  .  s    z1TestStreamBlock.test_initialisation_from_subclassc                 C   sB   G dd dt j}|dt  fg}| t|j g d d S )Nc                   @   s   e Zd Ze Ze ZdS )zRTestStreamBlock.test_initialisation_from_subclass_with_extra.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?  8  s   r?  intror8  r9  rB  r:  rA  r(   r(   r)   r  7  s
    z<TestStreamBlock.test_initialisation_from_subclass_with_extrac                 C   sF   G dd dt j}G dd d|}| }| t|j g d d S )Nc                   @   s   e Zd Ze Ze ZdS )zSTestStreamBlock.test_initialisation_with_multiple_subclassses.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?  C  s   r?  c                   @   s   e Zd Ze ZdS )z\TestStreamBlock.test_initialisation_with_multiple_subclassses.<locals>.ArticleWithIntroBlockNr6   r7   r8   r   r9   rB  r(   r(   r(   r)   ArticleWithIntroBlockG  s   rE  rC  r@  )r3   r?  rE  r'   r(   r(   r)   r  B  s    z=TestStreamBlock.test_initialisation_with_multiple_subclasssesc                 C   sZ   G dd dt j}G dd dt j}G dd d||}| }| t|j g d dS )	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                   @   s   e Zd Ze Ze ZdS )zETestStreamBlock.test_initialisation_with_mixins.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?  ^  s   r?  c                   @   s   e Zd Ze ZdS )zCTestStreamBlock.test_initialisation_with_mixins.<locals>.IntroMixinNrD  r(   r(   r(   r)   
IntroMixinb  s   rF  c                   @   s   e Zd Ze ZdS )zNTestStreamBlock.test_initialisation_with_mixins.<locals>.ArticleWithIntroBlockN)r6   r7   r8   r   r9   by_liner(   r(   r(   r)   rE  e  s   rE  )r8  r9  rB  rG  Nr@  )r3   r?  rF  rE  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 )Nr9  )r9  r  ar   )r9  z
not a test)	r   rg   r9   r  r  r  Z
BlockFieldZhas_changedr  )r3   r'   initial_valueZ
data_valueZ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    n1 sP0    Y  d S )Nr9  Tr   r   rg   r9   r  r   r   r/   ro  r(   r(   r)   *test_required_raises_an_exception_if_empty  s    z:TestStreamBlock.test_required_raises_an_exception_if_emptyc                 C   sb   t jdt  fgdd}|dddg}z|| W n$ t jy\   | dt j Y n0 d S )Nr9  Tr   r~  r   r$   %s was raised)r   rg   r9   r   r/   r   failureExceptionro  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   s\   t jdt  fgdd}t |g }z|| W n$ t jyV   | dt j Y n0 d S )Nr9  Fr   rN  )r   rg   r9   r  r/   r   rO  ro  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   sZ   t dt  fg}t |g }| t j || W d    n1 sL0    Y  d S )Nr9  rK  ro  r(   r(   r)   test_required_by_default  s    z(TestStreamBlock.test_required_by_defaultc                 C   s,   G dd dt j}| }||}||S )Nc                   @   s   e Zd Ze Ze ZdS )z4TestStreamBlock.render_article.<locals>.ArticleBlockN)r6   r7   r8   r   r9   r8  rA  r9  r(   r(   r(   r)   r?    s   r?  )r   rg   r   rs   )r3   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                   @   s   e Zd ZdddZdS )zlTestStreamBlock.test_get_api_representation_calls_same_method_on_children_with_context.<locals>.ContextBlockNc                 S   s   || S r=   r(   rQ   r(   r(   r)   r'    s    zTestStreamBlock.test_get_api_representation_calls_same_method_on_children_with_context.<locals>.ContextBlock.get_api_representation)Nr(  r(   r(   r(   r)   r)    s   r)  r   r*  r-  rM  r.  Z111111r  r/  r0  r1  r   N)r   r9   rg   r'  r   r4  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 )
Nr8  My titlerM  r9  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>)rS  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"   r~  rM  r9  My first paragraphz5<div class="block-paragraph">My first paragraph</div>)rS  r5  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.
        r8  r|   r}   r9  r~  rM  z/<div class="block-heading"><h1>Hello</h1></div>Nr   rg   r9   r   rs   r   r  r3   r'   r$   rv   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 )Nr8  r|   r}   r9  r  rM  r   r   r   z;<div class="block-heading"><h1 lang="fr">Bonjour</h1></div>rX  rY  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
        r8  r|   r}   r9  r~  rM  r   z<h1>Hello</h1>N)r   rg   r9   r   rs   rt   r>   r  rY  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 )Nr8  r|   r}   r9  r  rM  r   r   r   r   z<h1 lang="fr">Bonjour</h1>)r   rg   r9   r   rs   rt   r  rY  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                   @   s   e Zd Ze Ze ZdS )z0TestStreamBlock.test_adapt.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?  b  s   r?  test_streamblockr   c                 S   s   g | ]\}}|t |fqS r(   r(  )r&   
group_nameZ
group_iterr(   r(   r)   r+  n  s   z.TestStreamBlock.test_adapt.<locals>.<listcomp>r   r   r8  r9  r   )r8  r9  r   Test streamblockr   FTr  r  r  r  r  r  r  )ry   r   r   r   r   r   r  r  r  blockCountsr   r   )r   rg   r   r   r   rt   r   rm  rz   r9   namerJ   rj   )r3   r?  r'   r   Zgrouped_blocksr]  Z
block_iterZ
block_listr(   r(   r)   r  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 )Nr8  mystream-countr  Zmystreamrl  r  r   )ra  zmystream-0-typezmystream-0-valuezmystream-0-deletedzmystream-0-orderr  r  )r   rg   r9   r  r  r  rK   r(   r(   r)   r    s,    
z,TestStreamBlock.test_value_omitted_from_datac                 C   s   G dd dt j}| }t |g d}| t}|| W d    n1 sR0    Y  | |j dddgiddgidi d S )	Nc                   @   s   e Zd Ze Ze ZdS )z>TestStreamBlock.test_validation_errors.<locals>.ValidatedBlockNr6   r7   r8   r   r9   charr  r   r(   r(   r(   r)   ValidatedBlock  s   rd  ))rc  r   rc  r"   r   r   )r   rx  blockErrorsr5  r2  zEnter a valid URL.)r   r   )	r   rg   r  r   r   r/   rt   r4  r  r3   rd  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 sR0    Y  | |j ddgi t |dg}| 	|| d S )Nc                   @   s   e Zd Ze Ze ZdS )zFTestStreamBlock.test_min_num_validation_errors.<locals>.ValidatedBlockNrb  r(   r(   r(   r)   rd    s   rd  r   r  r5  z The minimum number of items is 1re  
r   rg   r  r   r   r/   rt   r4  r  r  rh  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 sV0    Y  | |j ddgi t |dg}| 	|| d S )	Nc                   @   s   e Zd Ze Ze ZdS )zFTestStreamBlock.test_max_num_validation_errors.<locals>.ValidatedBlockNrb  r(   r(   r(   r)   rd    s   rd  r   r	  re  re  rf  rf  r5  z The maximum number of items is 1re  rj  rh  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^0    Y  | |j dd	gi t |g d
}| 	|| d S )Nc                   @   s   e Zd Ze Ze ZdS )zOTestStreamBlock.test_block_counts_min_validation_errors.<locals>.ValidatedBlockNrb  r(   r(   r(   r)   rd    s   rd  rc  r  r   Zblock_countsrf  r5  z&Char: The minimum number of items is 1)rf  re  rf  rj  rh  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^0    Y  | |j dd	gi t |g d
}| 	|| d S )Nc                   @   s   e Zd Ze Ze ZdS )zOTestStreamBlock.test_block_counts_max_validation_errors.<locals>.ValidatedBlockNrb  r(   r(   r(   r)   rd    s   rd  rc  r  r   rl  rk  r5  z&Char: The maximum number of items is 1)re  rf  rf  rj  rh  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 ]F}|d| dd	| td
| d| dd| d| d| d| i q*||i d}| |d
 jd | |d
 jd d S )Nc                   @   s   e Zd Ze Ze ZdS )zWTestStreamBlock.test_ordering_in_form_submission_uses_order_field.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?  B  s   r?  article-countr  r   r   article-%d-deletedr   article-%d-orderr   article-%d-typer8  article-%d-value
heading %dzarticle-%d-idz000%darticlez	heading 00000)	r   rg   r  r  r>   r   rt   r$   r  r3   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 ]6}|d| dd	| t|d
| dd| d| i q*||i d}| |d jd d S )Nc                   @   s   e Zd Ze Ze ZdS )zQTestStreamBlock.test_ordering_in_form_submission_is_numeric.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?  Z  s   r?  ro  r  r   r  rp  r   rq  rr  r8  rs  rt  ru  r   z	heading 2)r   rg   r  r  r>   r   rt   r$   rw  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                   @   s   e Zd Ze Ze ZdS )z=TestStreamBlock.test_searchable_content.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?  p  s   r?  r8  rT  rM  r9  rV  rU  )rT  rV  rU  )r   rg   r   r   rt   )r3   r?  r'   r$   r   r(   r(   r)   r   o  s&    
z'TestStreamBlock.test_searchable_contentc                    s   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                   @   s*   e Zd Ze Ze ZG dd dZdS )z7TestStreamBlock.test_meta_default.<locals>.ArticleBlockc                   @   s   e Zd ZdgZdS )z<TestStreamBlock.test_meta_default.<locals>.ArticleBlock.Metar8  A default headingNr6   r7   r8   r[   r(   r(   r(   r)   r    s   r  Nr6   r7   r8   r   r9   r8  r9  r  r(   r(   r(   r)   r?    s   r?  c                       s   e Zd Ze Z  ZdS )z@TestStreamBlock.test_meta_default.<locals>.ArticleContainerBlockNr6   r7   r8   r   r9   r*  ru  r(   r?  r(   r)   ArticleContainerBlock  s   r~  r*  Bobru  r   r   r8  ry  N
r   rg   rh   r   rz   r  rt   r   
block_typer$   r3   r~  r'   r;  r  r(   r}  r)   test_meta_default  s    	z!TestStreamBlock.test_meta_defaultc                    s   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 )zLTest that we can specify a default value in the constructor of a StreamBlockc                   @   s*   e Zd Ze Ze ZG dd dZdS )z>TestStreamBlock.test_constructor_default.<locals>.ArticleBlockc                   @   s   e Zd ZdgZdS )zCTestStreamBlock.test_constructor_default.<locals>.ArticleBlock.Metarx  Nrz  r(   r(   r(   r)   r    s   r  Nr{  r(   r(   r(   r)   r?    s   r?  c                       s    e Zd Ze Z dgdZdS )zGTestStreamBlock.test_constructor_default.<locals>.ArticleContainerBlock)r8  A different default headingrZ   Nr|  r(   r}  r(   r)   r~    s   r~  r*  r  ru  r   r   r8  r  Nr  r  r(   r}  r)   test_constructor_default  s    	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 )Nr:   r  rM  goodbye)r   rg   r9   r   rt   ZassertNotEqual)r3   r'   Zvalue1Zvalue2Z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                   @   s   e Zd ZG dd dZdS )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group1Block1c                   @   s   e Zd ZdZdS )zOTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group1Block1.Metagroup1Nr6   r7   r8   groupr(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   Group1Block1  s   r  c                   @   s   e Zd ZG dd dZdS )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group1Block2c                   @   s   e Zd ZdZdS )zOTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group1Block2.Metar  Nr  r(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   Group1Block2  s   r  c                   @   s   e Zd ZG dd dZdS )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group2Block1c                   @   s   e Zd ZdZdS )zOTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group2Block1.Metagroup2Nr  r(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   Group2Block1  s   r  c                   @   s   e Zd ZG dd dZdS )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group2Block2c                   @   s   e Zd ZdZdS )zOTestStreamBlock.test_adapt_considers_group_attribute.<locals>.Group2Block2.Metar  Nr  r(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   Group2Block2  s   r  c                   @   s   e Zd ZdS )zJTestStreamBlock.test_adapt_considers_group_attribute.<locals>.NoGroupBlockNr  r(   r(   r(   r)   NoGroupBlock  s   r  b1b2Zb3Zb4Zngbr\  r   >   r   r  r  N)	r   r9   rg   r   r   r   dictrt   r  )	r3   r  r  r  r  r  r'   r   Z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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                   @   s   e Zd Ze Ze ZdS )z>TestStreamBlock.test_value_from_datadict.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?    s   r?  r  r   2r8  rv  this is my headingrl  0001za deleted headingr  r9  <p>this is a paragraph</p>)z	foo-countzfoo-0-deletedzfoo-0-orderz
foo-0-typezfoo-0-idzfoo-0-valuezfoo-1-deletedzfoo-1-orderz
foo-1-typezfoo-1-idzfoo-1-valuezfoo-2-deletedzfoo-2-orderz
foo-2-typezfoo-2-idzfoo-2-valuer"   r  r   r   r   )r   rg   r   rt   r   r  r  r$   )r3   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                   @   s   e Zd Ze Ze ZdS )z:TestStreamBlock.check_get_prep_value.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?    s   r?  is_lazyr   r   r8  r  rv  r  r   r   r9  r$   r  r  )r   rg   r  r   rt   r   r  )r3   stream_datar  r?  r'   r$   r   Z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)r8  r  rv  )r9  r  Fr  r  r3   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 )
Nr8  r  rv  r  r9  r  rM  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>.TwoColumnBlockr:   N)r6   r7   r8   r   rg   r9   leftrightr(   r(   r(   r)   TwoColumnBlockH  s   r  c                    s(   i | ] \}}|t j j| |d qS )r  )r   r  r  )r&   kvr'   r  r(   r)   
<dictcomp>N  s   zLTestStreamBlock.check_get_prep_value_nested_streamblocks.<locals>.<dictcomp>r   r  r:   	some textrv  r  r  r   r   r   r$   some other textr  )r   rh   ro  r   rt   r   r  )r3   r  r  r  r$   r   Z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)r:   r  rv  )r:   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 )
Nr:   r  rv  r  r  rM  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                   @   s   e Zd Ze Ze ZdS )zUTestStreamBlock.test_modifications_to_stream_child_id_are_saved.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?  |  s   r?  r8  r  r  r  r9  r  00020003r   )r   rg   r   r  r   rt   r3   r?  r'   streamraw_datar(   r(   r)   /test_modifications_to_stream_child_id_are_saved{  s    





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                   @   s   e Zd Ze Ze ZdS )zXTestStreamBlock.test_modifications_to_stream_child_value_are_saved.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?    s   r?  r8  r  r  r  r9  r  r  Zearthr   )r   rg   r   r$   r   rt   r  r(   r(   r)   2test_modifications_to_stream_child_value_are_saved  s    





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                   @   s   e Zd Ze Ze ZdS )z?TestStreamBlock.test_set_streamvalue_item.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?    s   r?  r8  r  r  r  r9  r  r  )r8  r  r  r   r  r  r   rg   r   r   rt   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                   @   s   e Zd Ze Ze ZdS )zBTestStreamBlock.test_delete_streamvalue_item.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?    s   r?  r8  r  r  r  r9  r  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                   @   s   e Zd Ze Ze ZdS )zBTestStreamBlock.test_insert_streamvalue_item.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?    s   r?  r8  r  r  r  r9  r  r  r   )r9  mutabler  r  r  )r   rg   r   insertr   rt   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                   @   s   e Zd Ze Ze ZdS )zBTestStreamBlock.test_append_streamvalue_item.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?    s   r?  r8  r  r  r  r9  r  r  )r9  of warcraftr  r  r  )r   rg   r   ru  r   rt   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                   @   s   e Zd Ze Ze ZdS )z?TestStreamBlock.test_streamvalue_raw_data.<locals>.ArticleBlockNr>  r(   r(   r(   r)   r?    s   r?  r8  r  r  r  r9  r  r  r   bonjourr$   z	guten tagZ
konnichiwar  r   zhello kitty saysZ0004)r   rg   r   rt   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   r\  r   r^  r   r   NFTr  r  r  r  r  r  r  ry   r   r   r   r   r  r  r_  r  r   r   r   )	r   rg   r9   r   r   r   rt   rJ   rj   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sTJ d	d
 | D }| |dgddgg d |jdd}| || d  | t	|d |D ]}| |j
d q| |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)
r6   r7   r8   r   r9   r8  r  r9  	DateBlockdater(   r(   r(   r)   r?  o  s   r?  r8  rT  rM  r9  rV  rU  c                 S   s    i | ]\}}|d d |D qS )c                 S   s   g | ]
}|j qS r(   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>)r8  r9  r  )r  r   r  Zinvalid_type)r   rg   r   blocks_by_name
isinstancer  ZBlockNameLookupro  rt   r   r  Zfirst_block_by_namer$   rD   )	r3   r?  r'   r$   r  rO  Zparagraph_blocksZfirst_heading_blockZ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                   @   s   e Zd ZdZdS )zSTestStreamBlock.test_adapt_with_classname_via_class_meta.<locals>.ProfileBlock.Metaprofile-block-largeNr  r(   r(   r(   r)   r    s   r  N)r6   r7   r8   r   r9   usernamer  r(   r(   r(   r)   ProfileBlock  s   r  r\  r   r^  r   r   NFTr  r  r  r  r  r  r  r  r  )r   rg   r   r   r   rt   rJ   rj   )r3   r  r'   r   r(   r(   r)   r    s4    
z8TestStreamBlock.test_adapt_with_classname_via_class_metaN)5r6   r7   r8   r  r=  r  r  r  r  rJ  rL  rP  rQ  rR  rS  r  r   rW  r  r  rZ  r[  r  r  ri  r  r  rm  rn  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)   r7    sd   
	

# 3!#"&'G'Cr7  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numberr:   r  
inner_liststructboolrm  )r.   
setUpClassr   rg   r   r  simple_blockrf   rh   r  recursive_blockr'  r4   r(   r)   r    s"    



z#TestNormalizeStreamBlock.setUpClassc              	   C   sb   g dd g}|D ]N}| j |d. | | j|t| jg  W d    q1 sR0    Y  qd S )Nr   r#   )ri   rt   r  rF   r   r  )r3   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   )r:   ZichibanN)r   r  r  rt   rF   )r3   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 | 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   q1 s0    Y  qdS )zX
        A stream block is normalized iff all of its sub-blocks are normalized.
        r  r  Tr  r  )r:   r  r  )r   r   r   r   r   r  rm  rM  r  r   r:   r  r  r   r  r   r   r#   N)ri   r  rF   rz   r$   r   rZ  r  r  r   r>   r  r  )r3   r  r$   rs  r(   r(   r)   test_normalize_recursive  sV    








.
z1TestNormalizeStreamBlock.test_normalize_recursive)	r6   r7   r8   r   r  r  r  r  r;   r(   r(   r4   r)   r    s
   		r  c                   @   s"   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8 |dd	d
ddd
d dd
ddig}W d    n1 sn0    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 )Nr{  Fr   	link_textmissing titlerZ   r   r   page twor{  r  r   
page threeno pager  c                 S   s   g | ]}t |qS r(   )r   r)  r(   r(   r)   r+  `  r+   zCTestStructBlockWithFixtures.test_bulk_to_python.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )r  r(   r)  r(   r(   r)   r+  c  r+   )r  r  r  r  c                 S   s   g | ]}|d  qS )r{  r(   r)  r(   r(   r)   r+  h  r+   r,  )r   rh   r|  r9   r"  rt  rt   rZ  r   r   rP  )r3   Zpage_link_blockrO  Zresult_typesZresult_titlesZresult_pagesr(   r(   r)   r-  N  s8    "	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 )Nr{  Fr   r  r  rZ   r.  r/  Z	Christmasr  )r   rh   r|  r9   r   r   rP  r4  rm  rn  r>   r  r3   r'   r6  r(   r(   r)   rp  s  s    z3TestStructBlockWithFixtures.test_extract_referencesNr6   r7   r8   rt  r-  rp  r(   r(   r(   r)   r  K  s   %r  c                   @   s"   e Zd ZdgZdd Zdd ZdS )TestStreamBlockWithFixturesr?  c              	   C   s^  t dt  fdt  fg}| dX |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 s0    Y  | d dd |D }W d    n1 s0    Y  | |g ddgddgg | d dd |D }W d    n1 s0    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 )Nr{  r8  r   zinteresting pagesrM  r   r   zpages written by dogsZwoofz	woof woofzboring pagesr  r   c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]
}|j qS r(   )r  r%   r(   r(   r)   r+    r+   NTestStreamBlockWithFixtures.test_bulk_to_python.<locals>.<listcomp>.<listcomp>r(   r&   r  r(   r(   r)   r+    r+   zCTestStreamBlockWithFixtures.test_bulk_to_python.<locals>.<listcomp>)r8  r{  r{  c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]
}|j qS r(   r#   r%   r(   r(   r)   r+    r+   r  r(   r  r(   r(   r)   r+    r+   r,  )
r   rg   r|  r9   r"  rt  rt   r   r   rP  )r3   r  resultsZblock_typesZblock_valuesr(   r(   r)   r-    sJ    

",	.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 )Nr{  r8  r.  r/  r0  r1  zSome events that you might liker2  r3  Zblock3)r   rg   r|  r9   r   r   rP  r4  rm  rn  r   r  r>   r5  r(   r(   r)   rp    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   r|  r   r   rP  rt   r   r  r$  r  r(   r(   r)   r    s    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   r|  r   r   rP  rt   r   r  r$  r  r(   r(   r)   r    s    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   )
ry   r   r   r   r   r   r   r   r   r   )Zwagtail.admin.widgets.chooserr  r   r|  r   r   r   rt   rz   target_modelsr   r  can_choose_rootrJ   rj   )r3   r  r'   r   r(   r(   r)   r    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   r|  r   r   r   rt   r  r   r   r(   r(   r)   #test_adapt_with_target_model_string-  s    
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   r|  r   r   r   r   rt   r  r   r(   r(   r)   $test_adapt_with_target_model_literal7  s    
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   r|  r   r   r   rt   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   r|  r   r   r   r   r   rt   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   r|  r   r   r   r  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/  r{  r   )
r   r|  r   r   rP  r   r>   r  rt   r$  )r3   r'   r6  r$   Zempty_valuer(   r(   r)   r  `  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^0    Y  | ||| | 	|d  d S )NFr   r.  r/  )
r   r|  r   r   rP  rt   r/   r   r   r$  )r3   Zrequired_blockZnonrequired_blockr6  r(   r(   r)   rz  j  s    (zTestPageChooserBlock.test_cleanc                 C   s   t  }| |jt d S r=   r   r|  rt   target_modelr   rK   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   r|  rt   r  r   rK   r(   r(   r)   test_target_model_stringz  s    z-TestPageChooserBlock.test_target_model_stringc                 C   s   t jtd}| |jt d S Nr  )r   r|  r   rt   r  rK   r(   r(   r)   test_target_model_literal~  s    z.TestPageChooserBlock.test_target_model_literalc                 C   s"   t jddgd}| |jt d S )Nr  r  r  r  rK   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   r|  r   r   rt   r  r   rK   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   r|  rt   r  rK   r(   r(   r)   %test_deconstruct_target_model_default  s    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  rK   r(   r(   r)   $test_deconstruct_target_model_string  s    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   r|  r   rt   r  rK   r(   r(   r)   %test_deconstruct_target_model_literal  s    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  rK   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   r|  r   r   rt   r  rK   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 sH0    Y  | || d S r  )r   r   r!  r   r|  r"  rt  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:0    Y  | |d |d  d S )Nr   r   r   )r   r|  r"  rt  r  )r3   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   r|  r   r   rP  r4  rm  rn  r>   r  r  r(   r(   r)   rp    s    z,TestPageChooserBlock.test_extract_referencesN)r6   r7   r8   rt  r  r  r  r  r  r  r  r  r  rz  r  r  r  r  r  r  r  r  r   r  r-  r  rp  r(   r(   r(   r)   r    s0   








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   r:   r   r   r   ry   r   r   StaticBlockr   r   r   rt   rJ   rj   r   r(   r(   r)   test_adapt_with_constructor  s"    
z+TestStaticBlock.test_adapt_with_constructorc              
   C   sd   G dd dt j}| }|d t |}| |d d | |d dd|j|jdd	d
 d S )Nc                   @   s   e Zd ZG dd dZdS )zBTestStaticBlock.test_adapt_with_subclass.<locals>.PostsStaticBlockc                   @   s   e Zd ZdZdZdS )zGTestStaticBlock.test_adapt_with_subclass.<locals>.PostsStaticBlock.Metar  r  N)r6   r7   r8   r  r~   r(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   PostsStaticBlock  s   r  r  r   r   r  r   r	  r   r
  r  )r3   r  r'   r   r(   r(   r)   test_adapt_with_subclass  s    
z(TestStaticBlock.test_adapt_with_subclassc              
   C   sd   G dd dt j}| }|d t |}| |d d | |d dd|j|jdd	d
 d S )Nc                   @   s   e Zd ZG dd dZdS )zmTestStaticBlock.test_adapt_with_subclass_displays_default_text_if_no_admin_text.<locals>.LabelOnlyStaticBlockc                   @   s   e Zd ZdZdS )zrTestStaticBlock.test_adapt_with_subclass_displays_default_text_if_no_admin_text.<locals>.LabelOnlyStaticBlock.MetaLatest postsNr  r(   r(   r(   r)   r    s   r  Nr  r(   r(   r(   r)   LabelOnlyStaticBlock  s   r  r  r   r   z(Latest posts: this block has no options.r   r  r   r
  r  )r3   r  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   sd   G dd dt j}| }|d t |}| |d d | |d dd|j|jdd	d
 d S )Nc                   @   s   e Zd ZdS )zwTestStaticBlock.test_adapt_with_subclass_displays_default_text_if_no_admin_text_and_no_label.<locals>.NoMetaStaticBlockNr  r(   r(   r(   r)   NoMetaStaticBlock*  s   r  r  r   r   z.Posts static block: this block has no options.r   r	  r   r
  r  )r3   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   )rv   r   r   r   ry   r   )	r   r  r   r   r   r   rt   rJ   rj   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   r  rB  r$  )r3   r'   rE  r(   r(   r)   rQ  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   r  rs   rt   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   s    t  }|d }| | d S r=   )r   r  r   r$  r`  r(   r(   r)   r  f  s    
zTestStaticBlock.test_serializec                 C   s    t  }|d }| | d S r=   )r   r  r   r$  r`  r(   r(   r)   r  k  s    
z TestStaticBlock.test_deserializec                 C   s   |  t d dS )zZ
        StaticBlock.normalize always returns None, as a StaticBlock has no value
           N)r$  r   r  rF   rU   r(   r(   r)   rH   p  s    zTestStaticBlock.test_normalizeN)r6   r7   r8   r  r  r  r  r  rQ  r   r  r  r  rH   r(   r(   r(   r)   r    s   r  c                   @   s   e Zd Zdd Zdd ZdS )TestDateBlockc                 C   s   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.datetimer  r   r  r   r   r   rt   rz   	js_formatrJ   rj   )r3   r  r'   r   r(   r(   r)   r  x  s(    
zTestDateBlock.test_adaptc                 C   s8   t jdd}|d t |}| |d jd d S )Nz%d.%m.%Yformatr  r   zd.m.Y)r   r  r   r   r   rt   r  r   r(   r(   r)   test_adapt_with_format  s    
z$TestDateBlock.test_adapt_with_formatNr6   r7   r8   r  r   r(   r(   r(   r)   r  w  s   r  c                   @   s   e Zd Zdd Zdd ZdS )TestTimeBlockc                 C   s   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   )AdminTimeInputtest_timeblockr   zH:ir   zTest timeblockr   Ttimez5w-field w-field--time_field w-field--admin_time_inputr   r   r   )r  r#  r   	TimeBlockr   r   r   rt   rz   r  rJ   rj   )r3   r#  r'   r   r(   r(   r)   r    s(    
zTestTimeBlock.test_adaptc                 C   s8   t jdd}|d t |}| |d jd d S )Nz%H:%M:%Sr  r$  r   zH:i:s)r   r&  r   r   r   rt   r  r   r(   r(   r)   r     s    
z$TestTimeBlock.test_adapt_with_formatNr!  r(   r(   r(   r)   r"    s   r"  c                   @   s   e Zd Zdd Zdd ZdS )TestDateTimeBlockc                 C   s   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   )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   )r  r(  r   DateTimeBlockr   r   r   rt   rz   r  rJ   rj   )r3   r(  r'   r   r(   r(   r)   r    s(    
zTestDateTimeBlock.test_adaptc                 C   s8   t jdd}|d t |}| |d jd d S )Nz%d.%m.%Y %H:%Mr  r)  r   z	d.m.Y H:i)r   r*  r   r   r   rt   r  r   r(   r(   r)   r     s    
z(TestDateTimeBlock.test_adapt_with_formatNr!  r(   r(   r(   r)   r'    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S )TestSystemCheckc                 C   sv   t dt  fdt  fg}| }| t|d | |d jd | |d jd | |d j	|j
d  d S )Nr8  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   rg   r9   rA  checkrt   r   r  hintrG   r  r3   r'   errorsr(   r(   r)   )test_name_cannot_contain_non_alphanumeric  s    

z9TestSystemCheck.test_name_cannot_contain_non_alphanumericc                 C   sv   t dt  fdt  fg}| }| t|d | |d jd | |d jd | |d j	|j
d  d S )Nr8  r   r   r   r,  zBlock name cannot be emptyr-  r0  r(   r(   r)   test_name_must_be_nonempty  s    

z*TestSystemCheck.test_name_must_be_nonemptyc                 C   sv   t dt  fdt  fg}| }| t|d | |d jd | |d jd | |d j	|j
d  d S )Nr8  	rich textr   r   r,  !Block names cannot contain spacesr-  r0  r(   r(   r)   test_name_cannot_contain_spaces  s    

z/TestSystemCheck.test_name_cannot_contain_spacesc                 C   sv   t dt  fdt  fg}| }| t|d | |d jd | |d jd | |d j	|j
d  d S )Nr8  z	rich-textr   r   r,  z!Block names cannot contain dashesr-  r0  r(   r(   r)   test_name_cannot_contain_dashes  s    

z/TestSystemCheck.test_name_cannot_contain_dashesc                 C   sv   t dt  fdt  fg}| }| t|d | |d jd | |d jd | |d j	|j
d  d S )Nr8  Z
99richtextr   r   r,  z%Block names cannot begin with a digitr-  r0  r(   r(   r)   !test_name_cannot_begin_with_digit  s    

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 )NZparagraph_listr8  r4  r   r   r,  r5  )r   rA  rg   rf   rh   r9   r.  rt   r   r  r/  rG   r3   Zfailing_blockr'   r1  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 )	NZcarouselr:   r8  r4  r   r   r,  r5  r   rA  rg   rh   r9   r.  rt   r   r  r/  rG   r9  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 )NZ
two_columnr  r8  r4  r  r   r   r,  r5  r   r;  )r3   Zfailing_block_1Zfailing_block_2r'   r1  r(   r(   r)   'test_system_checks_recurse_into_structsb  s@    


z7TestSystemCheck.test_system_checks_recurse_into_structsN)r6   r7   r8   r2  r3  r6  r7  r8  r:  r<  r=  r(   r(   r(   r)   r+    s   r+  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 )NrN  http://torchbox.com/r  r   r   Z	importantz=<a href="http://torchbox.com/" class="important">Torchbox</a>)CustomLinkBlockr   rs   rt   )r3   r'   r$   rR   rO  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 )NrN  r?  r@  zmy-link-blockr  zdata-prefix="my-link-block"z#<p>Hello from get_form_context!</p>)rA  r   Zrender_formr   rN  r(   r(   r)   $test_render_with_custom_form_context  s
    z:TestTemplateRendering.test_render_with_custom_form_contextN)r6   r7   r8   rB  rk   ZexpectedFailurerC  r(   r(   r(   r)   r>    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S )TestIncludeBlockTagc                 C   s6   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   r9   bindr   r   r3   r'   Zbound_blockrO  r(   r(   r)   &test_include_block_tag_with_boundblock  s    
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  r9  rE  r   rF  z<<body><h1 lang="fr">Bonjour</h1>monde <i>italique</i></body>N)r   r   r   r   )r3   r'   r;  rO  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
        r8  r|   r}   r9  z&tests/blocks/stream_with_language.htmlr  rM  rE  r   rF  z?<div class="heading" lang="fr"><h1 lang="fr">Bonjour</h1></div>N)r   rg   r9   r   r   r   )r3   r'   r  rO  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
        rE  r   r  z<body>42</body>N)r   r   )r3   rO  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   rF  rG  Nz<body>999</body>rH  rJ  r(   r(   r)   *test_include_block_tag_with_filtered_value  s     
z>TestIncludeBlockTag.test_include_block_tag_with_filtered_valuec                 C   s6   t jdd}|d}td|dd}| d| dS )	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   rF  z9<body><h1 lang="fr" class="important">bonjour</h1></body>NrH  rJ  r(   r(   r)   )test_include_block_tag_with_extra_context  s    
z=TestIncludeBlockTag.test_include_block_tag_with_extra_contextc                 C   s6   t jdd}|d}td|dd}| d| dS )	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   rF  z/<body><h1 class="important">bonjour</h1></body>NrH  rJ  r(   r(   r)   %test_include_block_tag_with_only_flag#  s    
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> HTMLrE  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   r9   rI  r   r   r   r  r   rJ  r(   r(   r)    test_include_block_html_escaping4  sP    z4TestIncludeBlockTag.test_include_block_html_escapingN)r6   r7   r8   rK  rL  rM  rN  rO  rP  rQ  rR  r(   r(   r(   r)   rD    s   rD  c                   @   s   e Zd Zdd Zdd ZdS )!TestOverriddenGetTemplateBlockTagc                 C   sb   G dd dt j}|dd}| td |d}W d    n1 sH0    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)r3   rR   r(   r(   r)   get_template|  s    zsTestOverriddenGetTemplateBlockTag.test_get_template_old_signature.<locals>.BlockUsingGetTemplateMethod.get_template)N)r6   r7   r8   rT  rU  r(   r(   r(   r)   BlockUsingGetTemplateMethody  s   rV  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   rE   ZassertWarnsMessager    rs   rt   )r3   rV  r'   rv   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                   @   s   e Zd ZdddZdS )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(   rQ   r(   r(   r)   rU    s    zTestOverriddenGetTemplateBlockTag.test_block_render_passes_the_value_argument_to_get_template.<locals>.BlockChoosingTemplateBasedOnValue.get_template)NN)r6   r7   r8   rU  r(   r(   r(   r)   !BlockChoosingTemplateBasedOnValue  s   rZ  rW  rY  z<h1>HEADING</h1>N)r   rE   rs   rt   )r3   rZ  r'   rv   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)r6   r7   r8   rX  r[  r(   r(   r(   r)   rS  w  s   rS  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 brokenr5  r   rt   r   r3   r1   r(   r(   r)   test_plain_validation_error  s    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 beforer5  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 )Nr`  r2  3Either email or telephone number must be specified.block_errorsr-   r5  rg  r5  )r   r   r   rt   r   r_  r(   r(   r)   !test_structblock_validation_error  s$    
z?TestValidationErrorAsJsonData.test_structblock_validation_errorc                 C   s*   t tdgd}| t|ddgi d S )Nrb  r,   r5  r   r   rt   r   r_  r(   r(   r)   6test_structblock_validation_error_with_no_block_errors  s    zTTestValidationErrorAsJsonData.test_structblock_validation_error_with_no_block_errorsc                 C   s4   t dtdid}| t|ddddgiii d S )Nr`  r2  rd  rg  r5  rg  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 )Nrb  r,   r2  r`  ri  )r   r  r  r   The maximum number of items is 5rc  r5  rg  re  )r   r   r   r   rt   r   r_  r(   r(   r)   !test_streamblock_validation_error  s`    #z?TestValidationErrorAsJsonData.test_streamblock_validation_errorc                 C   s*   t tdgd}| t|ddgi d S Nr  r,   r5  r   r   rt   r   r_  r(   r(   r)   6test_streamblock_validation_error_with_no_block_errors#  s    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 )Nr2  )r  r  ri  rg  r5  rn  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 )Nrb  r,   r`  r2  ri  r  rk  rc  r5  rg  r   r   re  )r   r   r   r   rt   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 )Nrb  r,   r`  r2  ri  rq  r  rk  rc  r5  rg  re  )r   r   r   r   rt   r   r_  r(   r(   r)   5test_listblock_validation_error_constructed_with_dict  sN    zSTestValidationErrorAsJsonData.test_listblock_validation_error_constructed_with_dictc                 C   s4   t dtdid}| t|ddddgiii d S )Nr   r2  ri  rg  r5  r   r   rt   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   s*   t tdgd}| t|ddgi d S rm  rt  r_  r(   r(   r)   4test_listblock_validation_error_with_no_block_errors  s    zRTestValidationErrorAsJsonData.test_listblock_validation_error_with_no_block_errorsN)r6   r7   r8   r`  ra  rf  rh  rj  rl  ro  rp  rr  rs  ru  rv  r(   r(   r(   r)   r\    s   =?6r\  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
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   Zsubtitle)r   	get_blockr   rz   r   r9   r  r   rA  r  rt   r`  )r3   lookupZ
char_blockZrich_text_blockZchar_block_2r(   r(   r)   test_simple_lookup  s$    




z,TestBlockDefinitionLookup.test_simple_lookupc                 C   s   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 )Nrx  r   Try  zwagtail.blocks.StructBlock)r  r   )r   r   r   r   r   r   r  r   )
r   r{  rz   r   rh   r  r9   r  r   rA  )r3   r|  Zstruct_blocktitle_blockdescription_blockr(   r(   r)   test_structblock_lookup  s&    


z1TestBlockDefinitionLookup.test_structblock_lookupc                 C   s   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 )Nrx  r   Try  zwagtail.blocks.StreamBlock)r8  r   )r9  r   r~  r   r8  r9  )
r   r{  rz   r   rg   r  r9   r  r   rA  )r3   r|  r  r  r  r(   r(   r)   test_streamblock_lookup  s&    


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 )Nrx  r   Tzwagtail.blocks.ListBlockr   rz  r   )	r   r{  rz   r   rf   r  r9   r  r   )r3   r|  r  Zlist_item_blockr(   r(   r)   test_listblock_lookup!  s$    


z/TestBlockDefinitionLookup.test_listblock_lookupN)r6   r7   r8   r}  r  r  r  r(   r(   r(   r)   rw    s   rw  )br   r@  r  r(  rk   Zunittest.mockdecimalr   Zdjangor   Zdjango.core.exceptionsr   Zdjango.core.serializers.jsonr   Zdjango.forms.utilsr   Zdjango.template.loaderr   Zdjango.testr	   r
   Zdjango.utils.safestringr   r   Zdjango.utils.translationr   r  r.  r   Zwagtail.blocks.baser   Z wagtail.blocks.definition_lookupr   Zwagtail.blocks.field_blockr   Zwagtail.blocks.list_blockr   r   Zwagtail.blocks.static_blockr   Zwagtail.blocks.stream_blockr   r   Zwagtail.blocks.struct_blockr   r   Zwagtail.modelsr   Zwagtail.rich_textr   Zwagtail.test.testapp.blocksr   rA  r   Zwagtail.test.testapp.modelsr   r   Zwagtail.test.utilsr   Zwagtail.utils.deprecationr    rg   r!   r9   r<   rB   ro   r   r  r
  r  r  r   r-  r>  ru  r  r  r  r
  r  r  r  r7  r  r  r  r  r  r  r"  r'  r+  r>  rD  rS  r\  rw  r(   r(   r(   r)   <module>   s   e o*	)@< G      uJ      X    L=         Jr>o j $$$ + V%  ;