U
    |h                     @   s,   d dl mZ d dlmZ G dd deZdS )    )SimpleTestCase)querydict_from_htmlc                   @   s   e Zd ZdZddgfddgfddgfgZdd	gfd
dgfdddgfgZddgfdddgfddgfgZdd Zdd Zdd Z	dd Z
dd Zd d! Zd"S )#TestQueryDictFromHTMLa3  
    <form id="personal-details">
        <input type="hidden" name="csrfmiddlewaretoken" value="Z783HTL5Bc2J54WhAtEeR3eefM1FBkq0EbTfNnYnepFGuJSOfvosFvwjeKYtMwFr">
        <input type="hidden" name="no_value_input">
        <input type="hidden" value="no name input">
        <div>
            <div>
                <label>
                    <span>Full name</span>
                    <input type="text" name="name" value="Jane Doe" placeholder="">
                </label>
                <label>
                    <span>Email address</span>
                    <input type="email" name="email" value="jane@example.com" placeholder="name@example.com">
                </label>
            </div>
        </div>
    </form>
    <form id="event-details">
        <div>
            <div>
                <label>
                    <span>When is your event?</span>
                    <input type="date" name="date" value="2023-01-01">
                </label>
                <label>
                    <span>What type of event is it?</span>
                    <select name="event_type">
                        <option value="corporate">Corporate event</option>
                        <option value="wedding">Wedding</option>
                        <option value="birthday">Birthday</option>
                        <option value="other" selected>Other</option>
                    </select>
                </label>
                <label>
                    <span>What age groups is it suitable for?</span>
                    <select name="ages" multiple>
                        <option>Infants</option>
                        <option>Children</option>
                        <option>Teenagers</option>
                        <option selected>18-30</option>
                        <option selected>30-50</option>
                        <option>50-70</option>
                        <option>70+</option>
                    </select>
                </label>
            </div>
        </div>
    </form>
    <form id="market-research">
        <div>
            <div>
                <fieldset>
                    <legend>How many pets do you have?</legend>
                    <div class="radio-list">
                        <div class="radio">
                            <label>
                                <input type="radio" name="pets" value="0" />
                                None
                            </label>
                        </div>
                        <div class="radio">
                            <label>
                                <input type="radio" name="pets" value="1" />
                                One
                            </label>
                        </div>
                        <div class="radio">
                            <label>
                                <input type="radio" name="pets" value="2" checked />
                                Two
                            </label>
                        </div>
                        <div class="radio">
                            <label>
                                <input type="radio" name="pets" value="3+" />
                                Three or more
                            </label>
                        </div>
                    </div>
                </fieldset>
                <fieldset>
                    <legend>Which two colours do you like best?</legend>
                    <div class="checkbox-list">
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" name="colours" value="cyan">
                                Cyan
                            </label>
                        </div>
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" name="colours" value="magenta" checked />
                                Magenta
                            </label>
                        </div>
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" name="colours" value="yellow" />
                                Yellow
                            </label>
                        </div>
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" name="colours" value="black" checked />
                                Black
                            </label>
                        </div>
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" name="colours" value="white" />
                                White
                            </label>
                        </div>
                    </div>
                </fieldset>
                <label>
                    <span>Tell us what you love</span>
                    <textarea name="love" rows="3">Comic books</textarea>
                </label>
            </div>
        </div>
    </form>
    Zno_value_input namezJane Doeemailzjane@example.comdatez
2023-01-01Z
event_typeotherZagesz18-30z30-50Zpets2ZcoloursmagentablackZlovezComic booksc                 C   s$   t | j}| t| | j d S )N)r   htmlassertEquallistlistspersonal_details)selfresult r   j/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/tests/test_form_data_utils.pytest_html_only   s    
z$TestQueryDictFromHTML.test_html_onlyc                 C   s8   t | jdd}ddgfg| j }| t| | d S )NF)Zexclude_csrfZcsrfmiddlewaretokenZ@Z783HTL5Bc2J54WhAtEeR3eefM1FBkq0EbTfNnYnepFGuJSOfvosFvwjeKYtMwFr)r   r   r   r   r   r   )r   r   Zexpected_resultr   r   r   test_include_csrf   s    z'TestQueryDictFromHTML.test_include_csrfc                 C   sL   d| j fd| jfd| jffD ]*\}}t| j|d}| t| | qd S )Nr   r
      Z
form_index)r   market_researchevent_detailsr   r   r   r   r   )r   indexexpected_datar   r   r   r   test_form_index   s    z%TestQueryDictFromHTML.test_form_indexc                 C   sL   d| j fd| jfd| jffD ]*\}}t| j|d}| t| | qd S )Nzevent-detailszpersonal-detailszmarket-researchZform_id)r   r   r   r   r   r   r   r   )r   idr   r   r   r   r   test_form_id   s    z"TestQueryDictFromHTML.test_form_idc              	   C   s(   |  t t| jdd W 5 Q R X d S )Nz
invalid-idr   ZassertRaises
ValueErrorr   r   r   r   r   r   test_invalid_form_id   s    z*TestQueryDictFromHTML.test_invalid_form_idc              	   C   s(   |  t t| jdd W 5 Q R X d S )N   r   r"   r$   r   r   r   test_invalid_index   s    z(TestQueryDictFromHTML.test_invalid_indexN)__name__
__module____qualname__r   r   r   r   r   r   r   r!   r%   r'   r   r   r   r   r      s&   ~


		r   N)Zdjango.testr   Zwagtail.test.utils.form_datar   r   r   r   r   r   <module>   s   