U
    }Ha*                      @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZ d d	lmZ d d
lmZmZmZ ddlmZ ddlmZ ddlmZmZ dd Zdd Zdd Zdd Z dd Z!edd Z"dd Z#dd Z$dS )     )forms)Template)Context)SimpleTestCase)
FormHelper)Layout)	optgroups)GroupedChoiceFormSampleForm5)contains_partial)list_differencelist_intersectionrender_field   )only_bootstrap4)
SampleForm)parse_expected
parse_formc                   C   s    t ddgddgdgkstd S )Nr         )r   AssertionError r   r   A/tmp/pip-unpacked-wheel-rp2i33ek/crispy_forms/tests/test_utils.pytest_list_intersection   s    r   c                   C   s&   t ddddgddgddgks"td S )Nr   r   r      )r   r   r   r   r   r   test_list_difference   s    r   c                  C   s    t d d d d d} | dkstd S )N)fieldformZ
form_stylecontext )r   r   )renderedr   r   r   !test_render_field_with_none_field   s    r!   c                     s   ddl m}  dG fddd|  G  fdddtjG fdd	d	tj}td
}|td|ddidi}|kstd S )Nr   )
BoundFieldZxyxyxyxyxyxc                       s   e Zd Ze fddZdS )z1test_custom_bound_field.<locals>.CustomBoundFieldc                    s    S Nr   )selfextrar   r   auto_id%   s    z9test_custom_bound_field.<locals>.CustomBoundField.auto_idN)__name__
__module____qualname__propertyr'   r   r%   r   r   CustomBoundField$   s   r,   c                       s   e Zd Z fddZdS )z,test_custom_bound_field.<locals>.MyCharFieldc                    s    || |S r#   r   )r$   r   
field_namer,   r   r   get_bound_field*   s    z<test_custom_bound_field.<locals>.MyCharField.get_bound_fieldN)r(   r)   r*   r/   r   r.   r   r   MyCharField)   s   r0   c                       s"   e Zd Z Z fddZ  ZS )z'test_custom_bound_field.<locals>.MyFormc                    s&   t  j|| t | _td| j_d S )Nf)super__init__r   helperr   layout)r$   argskwargs	__class__r   r   r3   0   s    z0test_custom_bound_field.<locals>.MyForm.__init__)r(   r)   r*   r1   r3   __classcell__r   )r0   r8   r   MyForm-   s   r;   z;{% load crispy_forms_tags %}
{% crispy form "bootstrap3" %}r   r1   Z	something)data)	Zdjango.forms.boundfieldr"   r   Z	CharFieldZFormr   renderr   r   )r"   r;   templater    r   )r,   r0   r&   r   test_custom_bound_field   s    r?   c                  C   s   t  } d}d}| t|| | d}| tt|| | d}| tt|| | d}d}| t|| | d}| t|| | d}d}d}| t|| | d	}d
}| tt|| | t||dd d S )Nz<span></span>z<form>%s</form>z<span></span><b></b>z<span>a</span>z<span id="e"></span>z+<form id="tt"><span id="f"></span>%s</form>z<script></script>z<span id="g"></span>z#<div id="r"><span>toto</span></div>z<form><div id="r"></div></form>T)Zignore_needle_children)r   
assertTruer   assertRaisesNotImplementedErrorZassertFalse)cneedlehtmlmissingr   r   r   test_contains_partial;   s*    rG   c                  C   s2   t  } t | _td| j_t| tdks.td S )NZ
is_companyzutils_test.html)r   r   r4   r   r5   r   r   r   )r   r   r   r   test_parse_expected_and_formZ   s    rH   c                  C   sH  t dddgi} |   t| d }|\}}}|\}}}|dksDt|ddddid	d
ddddd	dddddddddddd	gkst|dkst|\}}}|dkst|dddddddddddd	dddddidddddd	gkst|dkst|\}}}|d kst|dddddd id!dddd"	gks6t|d#ksDtd S )$Ncheckbox_select_multipleZcdZvhsZAudioZvinylcheckboxidZid_checkbox_select_multiple_0_0Z0_0ZVinyl)django/forms/widgets/checkbox_option.htmlFT)	valuetypeattrsindexlabeltemplate_namenameselected
wrap_labelZid_checkbox_select_multiple_0_1)checkedrK   Z0_1ZCDr   ZVideozVHS TapeZid_checkbox_select_multiple_1_0Z1_0)	rM   rR   rQ   rO   rP   rS   rT   rN   rU   ZdvdZDVDZid_checkbox_select_multiple_1_1Z1_1r   unknownUnknownZid_checkbox_select_multiple_22)	rM   rT   rR   rQ   rO   rP   rS   rN   rU   r   )r	   Zas_pr   r   )r   groupsaudiovideorW   rQ   optionsrP   r   r   r   test_optgroup_filter_nestedb   s    





r^   c                  C   s  t ddi} t| d }|d }|\}}}|d ks6t|ddddddddd	d
dd	gks^t|dksjtt ddi} t| d }|d }|\}}}|d kst|ddddddddd	d
dd	gkst|dkstt ddi} t| d }|d }|\}}}|d kst|dddddddid	d
dd	gks4t|dksBtt dd i} t| d }|d }|\}}}|d kszt|dddddddid	d
dd	gkst|dkstd S )NrI   1r   r   T0Zid_checkbox_select_multiple_0)rK   rV   rJ   rL   )	rS   rM   rQ   rT   rP   rO   rN   rR   rU   r   FrK   )r
   r   r   )r   rZ   grouprQ   optionrP   r   r   r   test_optgroup_filter   s    





rc   N)%Zdjangor   Zdjango.template.baser   Zdjango.template.contextr   Zdjango.testr   Zcrispy_forms.helperr   Zcrispy_forms.layoutr   Z.crispy_forms.templatetags.crispy_forms_filtersr   Zcrispy_forms.tests.formsr	   r
   Zcrispy_forms.tests.utilsr   Zcrispy_forms.utilsr   r   r   Zconftestr   r   utilsr   r   r   r   r!   r?   rG   rH   r^   rc   r   r   r   r   <module>   s*   
M