3
œ(ƒh  ã               @   sœ   d dl Z d dlmZ d dlZd dlmZmZ ddlmZm	Z	m
Z
mZmZmZmZmZ G dd„ deƒZG dd	„ d	eeƒZG d
d„ deeƒZG dd„ deƒZdS )é    N)ÚskipIf)ÚBaseNestedAdminTestCaseÚexpected_failure_if_suité   )ÚStackedGroupÚStackedSectionÚStackedItemÚTabularGroupÚTabularSectionÚTabularItemÚSortableWithExtraRootÚSortableWithExtraChildc                   s  e Zd Ze‡ fdd„ƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zeejdd … d:kd#ƒd$d%„ ƒZd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Z d8d9„ Z!‡  Z"S );ÚInlineAdminTestCaseMixinc                s    t t| ƒjƒ  | j\| _| _d S )N)Úsuperr   Ú
setUpClassÚnested_modelsÚsection_clsÚitem_cls)Úcls)Ú	__class__© úR/tmp/pip-install-q3hcpn_q/django-nested-admin/nested_admin/tests/two_deep/tests.pyr      s    z#InlineAdminTestCaseMixin.setUpClassc             C   sp   | j jjdd}| j|ƒ | jdd | jƒ  |jjƒ }| jt	|ƒdƒ | j|d j
dƒ | j|d jdƒ d S )NÚtest)Úslugr   r   )Ú
root_modelÚobjectsÚcreateÚ
load_adminÚ
add_inlineÚ	save_formZsection_setÚallÚassertEqualÚlenr   Úposition)ÚselfÚgroupÚsectionsr   r   r   Útest_add_section_to_empty   s    

z2InlineAdminTestCaseMixin.test_add_section_to_emptyc             C   sÈ   | j jjdd}| jjjd|dd}| j|ƒ | jjjjƒ }| j	d| ƒ}|j
ƒ  W d Q R X | j	dƒ}|jdƒ W d Q R X | jƒ  |jjƒ }| jt|ƒdƒ | j|d jdƒ | j|d jdƒ d S )	Nr   )r   r   )r   r%   r#   z*//a[contains(string(.), "Add another %s")]z.//input[@name="section_set-0-item_set-0-name"]ZTestr   )r   r   r   r   r   r   Z_metaZverbose_nameÚtitleZclickable_xpathZclickZ	send_keysr   Úitem_setr    r!   r"   Únamer#   )r$   r%   ÚsectionZitem_verbose_nameÚelÚitemsr   r   r   Útest_add_item_to_empty#   s    

z/InlineAdminTestCaseMixin.test_add_item_to_emptyc             C   s^  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jddgddgdd | jƒ  | jjjdd}| j	|j
|dƒ | j	|jddƒ | j	dd„ |jjƒ jdƒD ƒddddgƒ | j	dd„ |jjƒ jdƒD ƒddgƒ d S )Nr%   )r   Úar   )r   r%   r#   Úbr   zA 0)r*   r+   r#   zA 1zA 2é   zB 0zB 1zB 2T)Úfrom_indexesÚ
to_indexesÚscreenshot_hack)r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )Ú.0Úir   r   r   ú
<listcomp>J   s    zQInlineAdminTestCaseMixin.test_drag_last_item_between_sections.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/B 2[1]zgroup/a[0]/A 1[2]zgroup/a[0]/A 2[3]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   P   s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   Údrag_and_drop_itemr   Úgetr!   r+   r#   r)   r    Úorder_by)r$   r%   Ú	section_aÚ	section_bÚitem_b_2r   r   r   Ú$test_drag_last_item_between_sections6   s0    
z=InlineAdminTestCaseMixin.test_drag_last_item_between_sectionsc             C   s\  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jddgddgd | jƒ  | jjjdd}| j	|j
|dƒ | j	|jddƒ | j	dd„ |jjƒ jdƒD ƒddddgƒ | j	dd„ |jjƒ jdƒD ƒddgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2)r2   r3   )r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   i   s    zSInlineAdminTestCaseMixin.test_drag_middle_item_between_sections.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/B 1[1]zgroup/a[0]/A 1[2]zgroup/a[0]/A 2[3]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   o   s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 2[1])r   r   r   r   r   r   r8   r   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   r<   Úitem_b_1r   r   r   Ú&test_drag_middle_item_between_sectionsT   s.    
z?InlineAdminTestCaseMixin.test_drag_middle_item_between_sectionsc             C   sp  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jdgdd | jddgddgdd | jƒ  | jjj	dd}| j
|j|dƒ | j
|jddƒ | j
dd„ |jjƒ jdƒD ƒddddgƒ | j
dd„ |jjƒ jdƒD ƒdd d!gƒ d S )"Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2zB 3)Úindexesr*   T)r2   r3   r4   )r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   Š   s    ziInlineAdminTestCaseMixin.test_drag_middle_item_between_sections_after_adding_new_item.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/B 1[1]zgroup/a[0]/A 1[2]zgroup/a[0]/A 2[3]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7      s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 2[1]zgroup/b[1]/B 3[2])r   r   r   r   r   r   r   r8   r   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   r<   r?   r   r   r   Ú<test_drag_middle_item_between_sections_after_adding_new_items   s4    
zUInlineAdminTestCaseMixin.test_drag_middle_item_between_sections_after_adding_new_itemc             C   sp  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jdgdd | jddgddgdd | jƒ  | jjj	dd}| j
|j|dƒ | j
|jddƒ | j
dd„ |jjƒ jdƒD ƒdddddgƒ | j
dd„ |jjƒ jdƒD ƒd d!gƒ d S )"Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2zA 3)rA   r*   T)r2   r3   r4   )r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ¬   s    zzInlineAdminTestCaseMixin.test_drag_middle_item_between_sections_after_adding_new_item_to_other_section.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/B 1[1]zgroup/a[0]/A 1[2]zgroup/a[0]/A 2[3]zgroup/a[0]/A 3[4]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ³   s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 2[1])r   r   r   r   r   r   r   r8   r   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   r<   r?   r   r   r   ÚMtest_drag_middle_item_between_sections_after_adding_new_item_to_other_section•   s4    
zfInlineAdminTestCaseMixin.test_drag_middle_item_between_sections_after_adding_new_item_to_other_sectionc             C   sd  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jdgdd tjdƒ | j	ddgddgdd | j
ƒ  | jjjdd}| j|j|dƒ | j|jddƒ | jdd„ |jjƒ jdƒD ƒddddgƒ | jdd„ |jjƒ jdƒD ƒdd gƒ d S )!Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2)rA   r*   g{®Gáz„?T)r2   r3   r4   )r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   Ð   s    zPInlineAdminTestCaseMixin.test_drag_new_item_between_sections.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/B 2[1]zgroup/a[0]/A 1[2]zgroup/a[0]/A 2[3]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   Ö   s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r   ÚtimeÚsleepr8   r   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   r<   r=   r   r   r   Ú#test_drag_new_item_between_sections·   s2    

z<InlineAdminTestCaseMixin.test_drag_new_item_between_sectionsc             C   s$  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jddgd | jƒ  | jdd„ |j	j
ƒ jdƒD ƒdddgƒ | jdd„ |j	j
ƒ jdƒD ƒddgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2)rA   c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ë   s    z=InlineAdminTestCaseMixin.test_delete_item.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/A 1[1]zgroup/a[0]/A 2[2]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ð   s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 2[1])r   r   r   r   r   r   Údelete_inliner   r!   r)   r    r:   )r$   r%   r;   r<   r   r   r   Útest_delete_itemÚ   s&    
z)InlineAdminTestCaseMixin.test_delete_itemc             C   s*  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jdgd | jƒ  | jt	| jjj
ddƒddƒ | jjjdd}| jdd„ |jjƒ jdƒD ƒdddgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2)rA   zSection was not deletedc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   	  s    z@InlineAdminTestCaseMixin.test_delete_section.<locals>.<listcomp>r#   zgroup/b[0]/B 0[0]zgroup/b[0]/B 1[1]zgroup/b[0]/B 2[2])r   r   r   r   r   r   rG   r   r!   r"   Úfilterr9   r)   r    r:   )r$   r%   r;   r<   r   r   r   Útest_delete_sectionô   s$    
z,InlineAdminTestCaseMixin.test_delete_sectionc             C   s^  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jddgd | jdgd | jdgd | jƒ  | j	t
| jjjddƒddƒ | j	dd„ |jjƒ jdƒD ƒddgƒ | j	dd„ |jjƒ jdƒD ƒdddgƒ dS )z˜
        Test that, if an item is deleted, then the section is deleted, and
        then the section is undeleted, that the item stays deleted.
        r%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2)rA   zSection should not be deletedc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   (  s    zNInlineAdminTestCaseMixin.test_delete_item_undelete_section.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/A 2[1]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ,  s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1]zgroup/b[1]/B 2[2]N)r   r   r   r   r   r   rG   Úundelete_inliner   r!   r"   rI   r)   r    r:   )r$   r%   r;   r<   r   r   r   Ú!test_delete_item_undelete_section  s,    
z:InlineAdminTestCaseMixin.test_delete_item_undelete_sectionc             C   s   | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jdgdd | jddgd | jƒ  | j	dd„ |j
jƒ jdƒD ƒdddgƒ | j	dd„ |j
jƒ jdƒD ƒddgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2)rA   r*   )rA   c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   B  s    z=InlineAdminTestCaseMixin.test_remove_item.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/A 1[1]zgroup/a[0]/A 2[2]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   G  s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r   Úremove_inliner   r!   r)   r    r:   )r$   r%   r;   r<   r   r   r   Útest_remove_item1  s&    
z)InlineAdminTestCaseMixin.test_remove_itemc             C   s  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | j|ƒ | jddgddgd | jƒ  | jjjdd}| j	|j
|dƒ | j	|jddƒ | j	dd„ |jjƒ jdƒD ƒdgƒ | j	dd„ |jjƒ jdƒD ƒddgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zB 0)r*   r+   r#   zB 1zB 2r1   )r2   r3   )r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ]  s    zLInlineAdminTestCaseMixin.test_drag_item_to_empty_section.<locals>.<listcomp>r#   zgroup/a[0]/B 2[0]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   `  s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r8   r   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   r<   r=   r   r   r   Útest_drag_item_to_empty_sectionK  s"    
z8InlineAdminTestCaseMixin.test_drag_item_to_empty_sectionc             C   s^  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jddgddgdd | jƒ  | jjjdd}| j	|j
|dƒ | j	|jddƒ | j	dd„ |jjƒ jdƒD ƒddddgƒ | j	dd„ |jjƒ jdƒD ƒddgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2T)r2   r3   r4   )r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   z  s    zMInlineAdminTestCaseMixin.test_drag_item_to_first_position.<locals>.<listcomp>r#   zgroup/a[0]/B 2[0]zgroup/a[0]/A 0[1]zgroup/a[0]/A 1[2]zgroup/a[0]/A 2[3]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   €  s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r8   r   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   r<   r=   r   r   r   Ú test_drag_item_to_first_positiond  s0    
z9InlineAdminTestCaseMixin.test_drag_item_to_first_positionc             C   s\  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jddgddgd | jƒ  | jjjdd}| j	|j
|dƒ | j	|jddƒ | j	dd„ |jjƒ jdƒD ƒddddgƒ | j	dd„ |jjƒ jdƒD ƒddgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zA 2r1   zB 0zB 1zB 2é   )r2   r3   )r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ™  s    zLInlineAdminTestCaseMixin.test_drag_item_to_last_position.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/A 1[1]zgroup/a[0]/A 2[2]zgroup/a[0]/B 2[3]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   Ÿ  s    zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r8   r   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   r<   r=   r   r   r   Útest_drag_item_to_last_position„  s.    
z8InlineAdminTestCaseMixin.test_drag_item_to_last_positionNr1   r   é	   z#Skipping misbehaving test on travisc             C   s"  | j jjdd}| jjjd|dd}| jjjd|dd | jjjd|d	d | jjjd
|dd | j|ƒ | jdd | jddgd	dgd | jƒ  | jjj	d
d}| jjj	dd}| j
|j|dƒ | j
|jddƒ | j
dd„ |jjƒ jdƒD ƒddgƒ | j
dd„ |jjƒ jdƒD ƒdgƒ d S )Nr%   )r   r/   r   )r   r%   r#   zA 0)r*   r+   r#   zA 1r   zA 2r1   r0   )r2   r3   )r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ¹  s    zPInlineAdminTestCaseMixin.test_drag_item_to_new_empty_section.<locals>.<listcomp>r#   zgroup/a[0]/A 0[0]zgroup/a[0]/A 1[1]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ¼  s    zgroup/b[1]/A 2[0])r   r   r   r   r   r   r   r8   r   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   Zitem_a_2r<   r   r   r   Ú#test_drag_item_to_new_empty_section¥  s"    

z<InlineAdminTestCaseMixin.test_drag_item_to_new_empty_sectionc                sf  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | j|ƒ | jdgd
d | jdgdd | jdgdd | jddgddgd | jddgddgd | jdddgd‰ ‡ fdd„}| j	|dd | j
ƒ  | jjjdd}| j|j|dƒ | j|jddƒ | jdd„ |jjƒ jdƒD ƒddddgƒ | jdd„ |jjƒ jdƒD ƒg ƒ d S ) Nr%   )r   r/   r   )r   r%   r#   r0   r   zB 0)r*   r+   r#   zA 0)rA   r*   zA 1zA 2)r2   r3   rQ   r#   )rA   c                s   | j dˆ  ƒ}|dkS )Nzreturn $("%s").val()Ú3)Úexecute_script)ÚdÚval)Úposition_selectorr   r   Úcheck_position_is_correctÔ  s    zTInlineAdminTestCaseMixin.test_position_update_bug.<locals>.check_position_is_correctz7Timeout waiting for position to update to correct value)Úmessage)r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   â  s    zEInlineAdminTestCaseMixin.test_position_update_bug.<locals>.<listcomp>zgroup/a[0]/A 0[0]zgroup/a[0]/A 1[1]zgroup/a[0]/A 2[2]zgroup/a[0]/B 0[3]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   è  s    )r   r   r   r   r   r   r   r8   Zget_form_field_selectorZ
wait_untilr   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   r<   rZ   Úitem_b_0r   )rY   r   Útest_position_update_bug¿  s2    
z1InlineAdminTestCaseMixin.test_position_update_bugc             C   sÐ   | j jjdd}| jjjd|dd}| jjjd|dd | j|ƒ | jdd | jddgd	dgd
 | jd	dgddgd
 | jƒ  | j	t
| jjjƒ ƒddƒ | jjjdd}| j	|j|dƒ | j	|jddƒ d S )Nr   )r   r/   r   )r   r%   r#   zA 0)r*   r+   r#   r0   r   )r2   r3   r1   zSave failed)r*   zItem is in the wrong sectionzItem has the wrong position)r   r   r   r   r   r   r   r8   r   r!   r"   r    r9   r+   r#   )r$   r%   r;   Úitem_a_0r   r   r   Ú/test_drag_existing_item_to_new_section_and_backê  s    
zHInlineAdminTestCaseMixin.test_drag_existing_item_to_new_section_and_backc             C   s<  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jddgddgd | jdgd | jddddgd | j	ƒ  | jddgddgdd | j
ddgd | jddddgd | j	ƒ  | jjj|dd}| j|jddƒ dS )a  
        Tests regression of a scenario after encountering a validation error.

        Steps to reproduce:
            1. Begin with at least two items in each section
            2. Drag one of the items from the first section into the second
            3. Create an invalid item in the first section
            4. Save, encounter a validation error
            5. Drag the invalid item back to the first group
            6. Remove the invalid item
            7. Save, get a 500 Internal Server Error
        r%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zB 0zB 1)r2   r3   )rA   r#   Ú1T)r2   r3   r4   r*   zA 0_changed)r+   r#   zSave failedN)r   r   r   r   r   r   r8   r   Ú	set_fieldr   rM   r9   r!   r*   )r$   r%   r;   r<   r^   r   r   r   Úbtest_drag_item_create_invalid_new_item_then_drag_back_after_validation_error_removing_invalid_itemþ  s&    
z{InlineAdminTestCaseMixin.test_drag_item_create_invalid_new_item_then_drag_back_after_validation_error_removing_invalid_itemc             C   sJ  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | jjjd|dd	 | j|ƒ | jddgddgdd | jddgddgdd | jƒ  | jjjdd}| j	|j
|dƒ | j	|jddƒ | j	dd„ |jjƒ jdƒD ƒddgƒ | j	dd„ |jjƒ jdƒD ƒddgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zA 1zB 0zB 1T)r2   r3   r4   )r*   z)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   C  s    zWInlineAdminTestCaseMixin.test_swap_first_two_items_between_sections.<locals>.<listcomp>r#   zgroup/a[0]/B 0[0]zgroup/a[0]/A 1[1]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   G  s    zgroup/b[1]/A 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r8   r   r9   r!   r+   r#   r)   r    r:   )r$   r%   r;   r<   r\   r   r   r   Ú*test_swap_first_two_items_between_sections-  s,    
zCInlineAdminTestCaseMixin.test_swap_first_two_items_between_sectionsc             C   s&  | j jjdd}| jjjd|dd}| jjjd|dd | jjjd|d	d | j|ƒ | jd
d | jddgd	dgd | jƒ  | j	t
| jjjƒ ƒddƒ | jjjd
d}| jjjdd}| j	|j|dƒ | j	|jddƒ | j	dd„ |jjƒ jdƒD ƒdgƒ | j	dd„ |jjƒ jdƒD ƒdgƒ dS )zz
        Test dragging the first of several items in a pre-existing section into
        a newly created section.
        r%   )r   r/   r   )r   r%   r#   zA 0)r*   r+   r#   zA 1r   r0   )r2   r3   r1   zSave failed)r*   zItem is in the wrong sectionzItem has the wrong positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   d  s    zPInlineAdminTestCaseMixin.test_drag_first_item_to_new_section.<locals>.<listcomp>r#   zgroup/a[0]/A 1[0]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   g  s    zgroup/b[1]/A 0[0]N)r   r   r   r   r   r   r   r8   r   r!   r"   r    r9   r+   r#   r)   r:   )r$   r%   r;   r<   r^   r   r   r   Ú#test_drag_first_item_to_new_sectionK  s"    
z<InlineAdminTestCaseMixin.test_drag_first_item_to_new_sectionc             C   s˜  | j jjdd}| jjjd|dd}| jjjd|dd | jjjd|d	d | j|ƒ | jd
d | jd	gdd | jd	gdd | jd	dgd | jddgd	dgd | j	ƒ  | j
t| jjjƒ ƒddƒ | jjjd
d}| jjjdd}| jjjdd}| jjjdd}| j|j|dƒ | j
|jddƒ | j
|jddƒ | j
|jd	dƒ | j
dd„ |jjƒ jdƒD ƒdgƒ | j
dd„ |jjƒ jdƒD ƒddgƒ dS )zÄ
        Test dragging the first of several items in a pre-existing section into
        a newly created section after having added two items and then removing
        one of those items.
        r%   )r   r/   r   )r   r%   r#   zA 0)r*   r+   r#   zA 1r   r0   zB 0)rA   r*   zB 1)rA   )r2   r3   r1   zSave failed)r*   zA0 did not move to new sectionzA0 has the wrong positionzA1 has the wrong positionzB1 has the wrong positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ‹  s    zdInlineAdminTestCaseMixin.test_drag_first_item_to_new_section_after_removing_item.<locals>.<listcomp>r#   zgroup/a[0]/A 1[0]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   Ž  s    zgroup/b[1]/A 0[0]zgroup/b[1]/B 1[1]N)r   r   r   r   r   r   r   rM   r8   r   r!   r"   r    r9   ÚassertNotEqualr+   r#   r)   r:   )r$   r%   r;   r<   r^   Zitem_a_1r?   r   r   r   Ú7test_drag_first_item_to_new_section_after_removing_itemj  s0    
zPInlineAdminTestCaseMixin.test_drag_first_item_to_new_section_after_removing_itemc             C   sh  | j jjdd}| jjjd|dd}| jjjd|dd | j|ƒ | jdd | jd	gd
d | jd	gdd | jd	gdd | jd	dgd | jddgd	dgd | jd	d	gd | j	ƒ  | jjj
dd}| jjj
dd}| jjj
dd}| j|j|dƒ | j|jddƒ | j|jd	dƒ | jdd„ |jjƒ jdƒD ƒg ƒ | jdd„ |jjƒ jdƒD ƒddgƒ dS )a  
        Tests for a regression that could be reproduced with the following steps:

        1. Begin with one section, with at least one item in it.
        2. Create a new section
        3. Create three items in the new section
        4. Remove the first of the new items
        5. Drag the first of the existing items into the first position in the
           new section.
        6. Remove the second item in the new section
        8. Save

        Expected outcome:
            The dragged item from the existing section should have been moved
            to the new section.

        Outcome with bug:
            The item has not moved.
        r%   )r   r/   r   )r   r%   r#   zA 0)r*   r+   r#   r0   r   zB 0)rA   r*   zB 1zB 2)rA   )r2   r3   )r*   zA0 did not move to new sectionzA0 has the wrong positionzB2 has the wrong positionc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ½  s    ziInlineAdminTestCaseMixin.test_add_remove_items_in_new_section_dragging_existing_items.<locals>.<listcomp>r#   c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ¾  s    zgroup/b[1]/A 0[0]zgroup/b[1]/B 2[1]N)r   r   r   r   r   r   r   rM   r8   r   r9   re   r+   r!   r#   r)   r    r:   )r$   r%   r;   r<   r^   r=   r   r   r   Ú<test_add_remove_items_in_new_section_dragging_existing_items‘  s*    
"zUInlineAdminTestCaseMixin.test_add_remove_items_in_new_section_dragging_existing_itemsc             C   sî   | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | j|ƒ | jddgddgd | jdgd | jƒ  | j	t
| jjjƒ ƒddƒ | jdd„ |jjƒ jdƒD ƒddgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zB 0zB 1)r2   r3   )rA   r1   zSave failedc             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   Õ  s    zYInlineAdminTestCaseMixin.test_delete_section_after_dragging_item_away.<locals>.<listcomp>r#   zgroup/a[0]/B 0[0]zgroup/a[0]/A 0[1])r   r   r   r   r   r   r8   rG   r   re   r"   r    r!   r)   r:   )r$   r%   r;   r<   r   r   r   Ú,test_delete_section_after_dragging_item_awayÁ  s    
zEInlineAdminTestCaseMixin.test_delete_section_after_dragging_item_awayc             C   s  | j jjdd}| jjjd|dd}| jjjd|dd}| jjjd|dd	 | jjjd
|dd	 | jjjd|dd	 | j|ƒ | jddgddgd | jdgd | jdgd | j	ƒ  | j
t| jjjƒ ƒdƒ | j
dd„ |jjƒ jdƒD ƒddgƒ | j
dd„ |jjƒ jdƒD ƒdgƒ d S )Nr%   )r   r/   r   )r   r%   r#   r0   r   zA 0)r*   r+   r#   zB 0zB 1)r2   r3   )rA   r1   c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   í  s    zbInlineAdminTestCaseMixin.test_delete_undelete_section_after_dragging_item_away.<locals>.<listcomp>r#   zgroup/a[0]/B 0[0]zgroup/a[0]/A 0[1]c             S   s   g | ]}d | ‘qS )z%sr   )r5   r6   r   r   r   r7   ï  s    zgroup/b[1]/B 1[0])r   r   r   r   r   r   r8   rG   rK   r   r!   r"   r    r)   r:   )r$   r%   r;   r<   r   r   r   Ú5test_delete_undelete_section_after_dragging_item_awayØ  s     

zNInlineAdminTestCaseMixin.test_delete_undelete_section_after_dragging_item_awayc             C   sÔ   | j jjdd}| jjjd|dd}| jjjd|dd | j|ƒ | jdd | jd	d | jd
gd | jddgd
dgd | j	ƒ  | j
t| jjjƒ ƒddƒ | jjjdd}| jjjd	d}| j
|j|dƒ d S )Nr%   )r   r/   r   )r   r%   r#   zA 0)r*   r+   r#   r0   Úcr   )rA   )r2   r3   r1   z&Save failed (new section wasn't added))r*   z!Item was not moved to new section)r   r   r   r   r   r   r   rM   r8   r   r!   r"   r    r9   r+   )r$   r%   r;   Zitem_a0Z	section_cr   r   r   ÚFtest_drag_into_new_section_after_adding_and_removing_preceding_sectionò  s    
z_InlineAdminTestCaseMixin.test_drag_into_new_section_after_adding_and_removing_preceding_section)r   rS   )#Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r'   r.   r>   r@   rB   rC   rF   rH   rJ   r   rL   rN   rO   rP   rR   r   ÚdjangoÚVERSIONrT   r]   r_   rb   rc   rd   rf   rg   rh   ri   rk   Ú__classcell__r   r   )r   r   r      s4   ""## ! +/'0r   c               @   s   e Zd ZeZeefZdS )ÚTestStackedInlineAdminN)rl   rm   rn   r   r   r   r   r   r   r   r   r   rs     s   rs   c               @   s   e Zd ZeZeefZdS )ÚTestTabularInlineAdminN)rl   rm   rn   r	   r   r
   r   r   r   r   r   r   rt     s   rt   c               @   s&   e Zd ZeZefZdd„ Zdd„ ZdS )ÚTestSortablesWithExtrac             C   sL   | j jjdd}| j|ƒ | jddƒ | jƒ  | jjdƒ}| j|ddƒ d S )Nr/   )r   r   r0   z"return $('ul.errorlist li').lengthr   z(Unexpected validation errors encountered)	r   r   r   r   ra   r   ÚseleniumrV   r!   )r$   ÚrootÚvalidation_errorsr   r   r   Ú#test_blank_extra_inlines_validation  s    
z:TestSortablesWithExtra.test_blank_extra_inlines_validationc             C   sÈ   | j jjdd}| j|ƒ | jddƒ | jdddgd | jƒ  | jjdƒ}| j|ddƒ | j jj	|j
d	}| j|jdd
ƒ | jd jjƒ }| jt|ƒddƒ | jt|ƒddƒ | j|d jddƒ d S )Nr/   )r   r   r0   r   )rA   z"return $('ul.errorlist li').lengthz(Unexpected validation errors encountered)ÚpkzRoot slug did not changezChild object did not saver   z"Incorrect number of children savedzChild slug incorrect)r   r   r   r   ra   r   rv   rV   r!   r9   rz   r   r   r    re   r"   )r$   rw   rx   Úchildrenr   r   r   Ú/test_blank_extra_inlines_validation_with_change%  s    
zFTestSortablesWithExtra.test_blank_extra_inlines_validation_with_changeN)	rl   rm   rn   r   r   r   r   ry   r|   r   r   r   r   ru     s   ru   )rD   Zunittestr   rp   Znested_admin.tests.baser   r   Úmodelsr   r   r   r	   r
   r   r   r   Úobjectr   rs   rt   ru   r   r   r   r   Ú<module>   s   (       