î
â^Q\ù”  ã               @   sà   d  d l  Z  d  d l m Z 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 Gd d „  d e ƒ Z Gd d	 „  d	 e e ƒ Z Gd
 d „  d e e ƒ Z Gd d „  d e ƒ Z d S)é    N)ÚskipIfÚSkipTest)Ú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 d0 d1 „  Z d2 d3 „  Z d4 d5 „  Z d6 d7 „  Z  d8 d9 „  Z! ‡  S);ÚInlineAdminTestCaseMixinc                s,   t  t |  ƒ j ƒ  |  j \ |  _ |  _ d  S)N)Úsuperr   Ú
setUpClassÚnested_modelsÚsection_clsÚitem_cls)Úcls)Ú	__class__© úT/var/www/dbchiro/venv/build/django-nested-admin/nested_admin/tests/two_deep/tests.pyr      s    z#InlineAdminTestCaseMixin.setUpClassc             C   s–   |  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ÚslugÚtestr   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 | d d ƒ } |  j | ƒ |  j j j j ƒ  } |  j	 d | ƒ  } | j
 ƒ  Wd  QX|  j	 d ƒ  } | j d ƒ Wd  QX|  j ƒ  | j j ƒ  } |  j t | ƒ d	 ƒ |  j | d j d ƒ |  j | d j d ƒ d  S)
Nr   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   Ú_metaÚverbose_nameÚtitleÚclickable_xpathÚclickÚ	send_keysr    Úitem_setr!   r"   r#   Únamer$   )r%   r&   ÚsectionÚ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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g d 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   Úbr   r0   zA 0r1   zA 1zA 2é   zB 0zB 1zB 2Úfrom_indexesÚ
to_indexesÚscreenshot_hackTz)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>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   )r<   r=   r   r   r   r>   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"   r1   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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g d d d g ƒ |  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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1zB 2r9   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   )r<   r=   r   r   r   r>   i   s   	 zSInlineAdminTestCaseMixin.test_drag_middle_item_between_sections.<locals>.<listcomp>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   )r<   r=   r   r   r   r>   o   s   	 zgroup/b[1]/B 0[0]zgroup/b[1]/B 2[1])r   r   r   r   r   r   r?   r    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   rC   Úitem_b_1r   r   r   Ú&test_drag_middle_item_between_sectionsT   s.    $$"""""""
(
(z?InlineAdminTestCaseMixin.test_drag_middle_item_between_sectionsc             C   s?  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d g d d ƒ |  j d d d g d 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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1zB 2ÚindexeszB 3r9   r:   r;   Tz)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   Š   s   	 ziInlineAdminTestCaseMixin.test_drag_middle_item_between_sections_after_adding_new_item.<locals>.<listcomp>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   )r<   r=   r   r   r   r>      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   r?   r    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   rC   rF   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   s?  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d g d d ƒ |  j d d d g d 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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1zB 2rH   zA 3r9   r:   r;   Tz)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   ¬   s   	 zzInlineAdminTestCaseMixin.test_drag_middle_item_between_sections_after_adding_new_item_to_other_section.<locals>.<listcomp>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   )r<   r=   r   r   r   r>   ³   s   	 zgroup/b[1]/B 0[0]zgroup/b[1]/B 2[1])r   r   r   r   r   r   r   r?   r    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   rC   rF   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   s'  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d g d d ƒ t j d ƒ |  j	 d d d g d 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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1rH   zB 2g{®Gáz„?r9   r:   r;   Tz)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   Ð   s   	 zPInlineAdminTestCaseMixin.test_drag_new_item_between_sections.<locals>.<listcomp>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   )r<   r=   r   r   r   r>   Ö   s   	 zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r   ÚtimeÚsleepr?   r    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   rC   rD   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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g ƒ |  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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1zB 2rH   c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   ë   s   	 z=InlineAdminTestCaseMixin.test_delete_item.<locals>.<listcomp>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   )r<   r=   r   r   r   r>   ð   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!   rA   )r%   r&   rB   rC   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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d g ƒ |  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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1zB 2rH   zSection was not deletedc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   	  s   	 z@InlineAdminTestCaseMixin.test_delete_section.<locals>.<listcomp>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   rN   r    r"   r#   Úfilterr@   r/   r!   rA   )r%   r&   rB   rC   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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g ƒ |  j d d g ƒ |  j d d g ƒ |  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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1zB 2rH   zSection should not be deletedc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   (  s   	 zNInlineAdminTestCaseMixin.test_delete_item_undelete_section.<locals>.<listcomp>zgroup/a[0]/A 0[0]zgroup/a[0]/A 2[1]c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   ,  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   rN   Úundelete_inliner    r"   r#   rP   r/   r!   rA   )r%   r&   rB   rC   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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d g d d ƒ |  j d d d g ƒ |  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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1rH   zB 2c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   B  s   	 z=InlineAdminTestCaseMixin.test_remove_item.<locals>.<listcomp>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   )r<   r=   r   r   r   r>   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!   rA   )r%   r&   rB   rC   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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g d d d g ƒ |  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&   r6   r$   r   r7   r   r0   zB 0r1   zB 1zB 2r8   r9   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   )r<   r=   r   r   r   r>   ]  s   	 zLInlineAdminTestCaseMixin.test_drag_item_to_empty_section.<locals>.<listcomp>zgroup/a[0]/B 2[0]c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   `  s   	 zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r?   r    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   rC   rD   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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g d 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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1zB 2r9   r:   r;   Tz)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   z  s   	 zMInlineAdminTestCaseMixin.test_drag_item_to_first_position.<locals>.<listcomp>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   )r<   r=   r   r   r   r>   €  s   	 zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r?   r    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   rC   rD   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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g d d d g ƒ |  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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zA 2r8   zB 0zB 1zB 2r9   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   )r<   r=   r   r   r   r>   ™  s   	 zLInlineAdminTestCaseMixin.test_drag_item_to_last_position.<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 2[3]c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   Ÿ  s   	 zgroup/b[1]/B 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r?   r    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   rC   rD   r   r   r   Útest_drag_item_to_last_position„  s.    $$"""""""
(
(z8InlineAdminTestCaseMixin.test_drag_item_to_last_positionNr8   r   é	   z#Skipping misbehaving test on travisc             C   s²  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ |  j j j d d	 d | d d
 ƒ |  j j j d d d | d d ƒ |  j | ƒ |  j d d ƒ |  j d d d g d d
 d g ƒ |  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&   r6   r$   r   r0   zA 0r1   zA 1r   zA 2r8   r7   r9   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   )r<   r=   r   r   r   r>   ¹  s   	 zPInlineAdminTestCaseMixin.test_drag_item_to_new_empty_section.<locals>.<listcomp>zgroup/a[0]/A 0[0]zgroup/a[0]/A 1[1]c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   ¼  s   	 zgroup/b[1]/A 2[0])r   r   r   r   r   r   r   r?   r    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   Zitem_a_2rC   r   r   r   Ú#test_drag_item_to_new_empty_section¥  s"    $""""
((z<InlineAdminTestCaseMixin.test_drag_item_to_new_empty_sectionc                s  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j | ƒ |  j d d g d d ƒ |  j d d g d d ƒ |  j d d g d d ƒ |  j d d d g d d d g ƒ |  j d d d g d d d g ƒ |  j d d d d g ƒ‰  ‡  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&   r6   r$   r   r7   r   r0   zB 0r1   rH   zA 0zA 1zA 2r9   r:   rX   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_correctÚmessagez7Timeout waiting for position to update to correct valuez)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   â  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   )r<   r=   r   r   r   r>   è  s   	 )r   r   r   r   r   r   r   r?   Zget_form_field_selectorZ
wait_untilr    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   rC   ra   Úitem_b_0r   )r`   r   Útest_position_update_bug¿  s2    $$"""
(
z1InlineAdminTestCaseMixin.test_position_update_bugc             C   s6  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d	 | d d ƒ |  j | ƒ |  j d d
 ƒ |  j d d d g d d d g ƒ |  j d d d g d d d g ƒ |  j ƒ  |  j	 t
 |  j j j ƒ  ƒ d d ƒ |  j j j d d ƒ } |  j	 | j | d ƒ |  j	 | j d d ƒ d  S)Nr   r   r6   r&   r$   r   r0   zA 0r1   r7   r9   r:   r   r8   zSave failedzItem is in the wrong sectionzItem has the wrong position)r   r   r   r   r   r   r   r?   r    r"   r#   r!   r@   r1   r$   )r%   r&   rB   Ú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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g d d d g ƒ |  j d d g ƒ |  j d d d d d g ƒ|  j	 ƒ  |  j d d d g d d d g d d ƒ |  j
 d d d g ƒ |  j d d d d d g ƒ|  j	 ƒ  |  j j j d
 | 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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zB 0zB 1r9   r:   rH   Ú1r;   TzA 0_changedzSave failedN)r   r   r   r   r   r   r?   r   Ú	set_fieldr    rT   r@   r"   r0   )r%   r&   rB   rC   re   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   s  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g d d d g d d ƒ |  j d d d g d 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&   r6   r$   r   r7   r   r0   zA 0r1   zA 1zB 0zB 1r9   r:   r;   Tz)item was not moved to the correct sectionz*item was not moved to the correct positionc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   C  s   	 zWInlineAdminTestCaseMixin.test_swap_first_two_items_between_sections.<locals>.<listcomp>zgroup/a[0]/B 0[0]zgroup/a[0]/A 1[1]c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   G  s   	 zgroup/b[1]/A 0[0]zgroup/b[1]/B 1[1])r   r   r   r   r   r   r?   r    r@   r"   r1   r$   r/   r!   rA   )r%   r&   rB   rC   rc   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 | d d ƒ } |  j j j d d d | d d ƒ |  j j j d d	 d | d d
 ƒ |  j | ƒ |  j d d ƒ |  j d d d g d d
 d g ƒ |  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&   r6   r$   r   r0   zA 0r1   zA 1r   r7   r9   r:   r8   zSave failedzItem is in the wrong sectionzItem has the wrong positionc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   d  s   	 zPInlineAdminTestCaseMixin.test_drag_first_item_to_new_section.<locals>.<listcomp>zgroup/a[0]/A 1[0]c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   g  s   	 zgroup/b[1]/A 0[0]N)r   r   r   r   r   r   r   r?   r    r"   r#   r!   r@   r1   r$   r/   rA   )r%   r&   rB   rC   re   r   r   r   Ú#test_drag_first_item_to_new_sectionK  s"    $"""
%(
(z<InlineAdminTestCaseMixin.test_drag_first_item_to_new_sectionc             C   sY  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ |  j j j d d	 d | d d
 ƒ |  j | ƒ |  j d d ƒ |  j d d
 g d d ƒ |  j d d
 g d d ƒ |  j d d
 d g ƒ |  j d d d g d d
 d g ƒ |  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&   r6   r$   r   r0   zA 0r1   zA 1r   r7   rH   zB 0zB 1r9   r:   r8   zSave failedz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   )r<   r=   r   r   r   r>   ‹  s   	 zdInlineAdminTestCaseMixin.test_drag_first_item_to_new_section_after_removing_item.<locals>.<listcomp>zgroup/a[0]/A 1[0]c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   Ž  s   	 zgroup/b[1]/A 0[0]zgroup/b[1]/B 1[1]N)r   r   r   r   r   r   r   rT   r?   r    r"   r#   r!   r@   ÚassertNotEqualr1   r$   r/   rA   )r%   r&   rB   rC   re   Zitem_a_1rF   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   s  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ |  j | ƒ |  j d d	 ƒ |  j d
 d g d d ƒ |  j d
 d g d d ƒ |  j d
 d g d d ƒ |  j d
 d d g ƒ |  j d d d g d d d g ƒ |  j d
 d d g ƒ |  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&   r6   r$   r   r0   zA 0r1   r7   rH   r   zB 0zB 1zB 2r9   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   )r<   r=   r   r   r   r>   ½  s   	 ziInlineAdminTestCaseMixin.test_add_remove_items_in_new_section_dragging_existing_items.<locals>.<listcomp>c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   ¾  s   	 zgroup/b[1]/A 0[0]zgroup/b[1]/B 2[1]N)r   r   r   r   r   r   r   rT   r?   r    r@   rl   r1   r"   r$   r/   r!   rA   )r%   r&   rB   rC   re   rD   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   sp  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g d d d g ƒ |  j d d g ƒ |  j ƒ  |  j	 t
 |  j j j ƒ  ƒ d d ƒ |  j d d „  | j j ƒ  j d ƒ Dƒ d d g ƒ d  S)Nr   r&   r6   r$   r   r7   r   r0   zA 0r1   zB 0zB 1r9   r:   rH   r8   zSave failedc             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   Õ  s   	 zYInlineAdminTestCaseMixin.test_delete_section_after_dragging_item_away.<locals>.<listcomp>zgroup/a[0]/B 0[0]zgroup/a[0]/A 0[1])r   r   r   r   r   r   r?   rN   r    rl   r#   r!   r"   r/   rA   )r%   r&   rB   rC   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 | d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d	 d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j j j d d d
 | d d ƒ |  j | ƒ |  j d d d g d d d g ƒ |  j d d g ƒ |  j d d g ƒ |  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&   r6   r$   r   r7   r   r0   zA 0r1   zB 0zB 1r9   r:   rH   r8   c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   í  s   	 zbInlineAdminTestCaseMixin.test_delete_undelete_section_after_dragging_item_away.<locals>.<listcomp>zgroup/a[0]/B 0[0]zgroup/a[0]/A 0[1]c             S   s   g  |  ] } d  | ‘ q S)z%sr   )r<   r=   r   r   r   r>   ï  s   	 zgroup/b[1]/B 1[0])r   r   r   r   r   r   r?   rN   rR   r    r"   r#   r!   r/   rA   )r%   r&   rB   rC   r   r   r   Ú5test_delete_undelete_section_after_dragging_item_awayØ  s     $$""""
"((zNInlineAdminTestCaseMixin.test_delete_undelete_section_after_dragging_item_awayc             C   s9  |  j  j j d d ƒ } |  j j j d d d | d d ƒ } |  j j j d d d | d d ƒ |  j | ƒ |  j d d	 ƒ |  j d d
 ƒ |  j d d g ƒ |  j d d d g d d d g ƒ |  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&   r6   r$   r   r0   zA 0r1   r7   ÚcrH   r   r9   r:   r8   z&Save failed (new section wasn't added)z!Item was not moved to new section)r   r   r   r   r   r   r   rT   r?   r    r"   r#   r!   r@   r1   )r%   r&   rB   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   rZ   )"Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r(   r5   rE   rG   rI   rJ   rM   rO   rQ   r   rS   rU   rV   rW   rY   r   ÚdjangoÚVERSIONr[   rd   rf   ri   rj   rk   rm   rn   ro   rp   rr   r   r   )r   r   r      s4   ""## !.+/'0r   c               @   s.   e  Z d  Z e Z e e f Z d d „  Z d S)ÚTestStackedInlineAdminc             C   su  t  j d k  r t d ƒ ‚ n  |  j r6 t d ƒ ‚ n  |  j rN t d ƒ ‚ n  |  j j j d d ƒ } |  j j j d d d | d	 d
 ƒ |  j	 | ƒ |  j
 j j j ƒ  } |  j d | ƒ  } | j ƒ  Wd  QX|  j d ƒ  } | j d ƒ Wd  QX|  j d | ƒ  } | j ƒ  Wd  QX|  j d ƒ  } | j d ƒ Wd  QX|  j d
 d g ƒ j d ƒ } |  j | j d ƒ d  S)Nr   rZ   z Test only applies to Django 1.9+z-Test does not apply if using django-grappelliz(Test does not apply if using django-suitr   r   r&   r$   r   z*//a[contains(string(.), "Add another %s")]z.//input[@name="section_set-0-item_set-0-name"]zTest 1zTest 2Úinline_labelz#2)r   rZ   )rw   rx   r   Zhas_grappelliZhas_suitr   r   r   r   r   r   r)   r*   r+   r,   r-   r.   Zget_itemZfind_element_by_class_namer"   Útext)r%   r&   r2   r3   rz   r   r   r   Ú!test_add_item_inline_label_update  s(    		"z8TestStackedInlineAdmin.test_add_item_inline_label_updateN)	rs   rt   ru   r   r   r   r	   r   r|   r   r   r   r   ry     s   ry   c               @   s"   e  Z d  Z e Z e e f Z d S)ÚTestTabularInlineAdminN)rs   rt   ru   r
   r   r   r   r   r   r   r   r   r}   &  s   r}   c               @   s7   e  Z d  Z e Z e f Z d d „  Z d d „  Z d S)ÚTestSortablesWithExtrac             C   sh   |  j  j j d d ƒ } |  j | ƒ |  j d d ƒ |  j ƒ  |  j j d ƒ } |  j | d d ƒ d  S)Nr   r6   r7   z"return $('ul.errorlist li').lengthr   z(Unexpected validation errors encountered)	r   r   r   r   rh   r    Úseleniumr]   r"   )r%   ÚrootÚvalidation_errorsr   r   r   Ú#test_blank_extra_inlines_validation1  s    
		z:TestSortablesWithExtra.test_blank_extra_inlines_validationc             C   s  |  j  j j d d ƒ } |  j | ƒ |  j d d ƒ |  j d d d d g ƒ|  j ƒ  |  j j d ƒ } |  j | d d ƒ |  j  j j	 d | j
 ƒ } |  j | j d d	 ƒ |  j d j j ƒ  } |  j t | ƒ d d
 ƒ |  j t | ƒ d d ƒ |  j | d j d d ƒ d  S)Nr   r6   r7   rH   r   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   rh   r    r   r]   r"   r@   rƒ   r   r   r!   rl   r#   )r%   r€   r   Úchildrenr   r   r   Ú/test_blank_extra_inlines_validation_with_change=  s    
		zFTestSortablesWithExtra.test_blank_extra_inlines_validation_with_changeN)	rs   rt   ru   r   r   r   r   r‚   r…   r   r   r   r   r~   ,  s   	r~   )rK   Zunittestr   r   rw   Znested_admin.tests.baser   r   Úmodelsr   r   r	   r
   r   r   r   r   Úobjectr   ry   r}   r~   r   r   r   r   Ú<module>   s   :ÿ ÿ ü