o
    hˠ                    @   s  d Z ddlZddl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 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 ddlmZ ddlmZ ddlmZ ddl Z ddl!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z1 e1  dddiiddidddiidddiiddidddiigddddiigdddd iidd!iddd"iigdgZ2g d#Z3e j4d$e.j5e.j6 d%d&d' Z7e j4d$e.j5e.j6 d%d(d) Z8e j4d$e.j5d%d*d+ Z9e j4d$e.j:d%d,d- Z;e j4d$e.j<d%d.d/ Z=e j4d$e.j>d%d0d1 Z?e j4d$e.j@d%d2d3 ZAe j4d$e.jBd%d4d5 ZCe j4d$e.jDgd%d6d7 ZEe j4d$e.jFgd%d8d9 ZGe j4d$e.jHgd%d:d; ZIe j4d$e.jJgd%d<d= ZKe j4d$e.jLgd%d>d? ZMd@dA ZNG dBdC dCZOe jPjQG dDdE dEeOZRG dFdG dGeOZSe jPjQG dHdI dIeSZTe jPjQG dJdK dKeSZUe jPjQG dLdM dMeSZVe jPjQG dNdO dOeSZWe jPjQG dPdQ dQeOZXe jPjQG dRdS dSeSZYe jPjQG dTdU dUeOZZe jPjQG dVdW dWeSZ[e jPjQG dXdY dYeSZ\e jPjQG dZd[ d[eSZ]e jPjQG d\d] d]eSZ^e jPjQG d^d_ d_eOZ_e jPjQG d`da daeOZ`e jPjQG dbdc dceOZae jPjQG ddde deeOZbe jPjQG dfdg dgeOZce jPjQG dhdi dieOZde jPjQG djdk dkeOZee jPjQG dldm dmeOZfe jPjQG dndo doeOZge jPjQG dpdq dqeOZhe jPjQG drds dseSZie jPjQG dtdu dueSZje jPjQG dvdw dwe_Zke jPjQG dxdy dyeSZle jPjQG dzd{ d{eSZme jPjQG d|d} d}eSZne jPjQG d~d deSZoe jPjQG dd depZqe jPjQG dd deOZrdS )zUnit/Functional tests    N)	AdminSite)
ChangeList)UserAnonymousUser)FallbackStorage)Q)	post_save)receiver)TemplateContext)TestCase)RequestFactory)static)TO_FIELD_VAR)VERSION)numconv)admin_factory)InvalidPositionInvalidMoveToDescendantPathOverflowMissingNodeOrderByNodeAlreadySaved)movenodeform_factory)models)register_alldatadesc12212223231r   children243441
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   functionscopeparamsc                 C      | j t | j S Nparam	load_bulk	BASE_DATArequest rD   ^/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/treebeard/tests/test_treebeard.pymodelM      rF   c                 C      | j S r=   r?   rB   rD   rD   rE   model_without_dataS      rJ   c                 C   r<   r=   r>   rB   rD   rD   rE   model_without_proxyX   rG   rL   c                 C   rH   r=   rI   rB   rD   rD   rE   model_with_unicode^   rK   rM   c                 C   rH   r=   rI   rB   rD   rD   rE   sorted_modelc   rK   rN   c                 C   rH   r=   rI   rB   rD   rD   rE   related_modelh   rK   rO   c                 C   rH   r=   rI   rB   rD   rD   rE   inherited_modelm   rK   rP   c                 C   rH   r=   rI   rB   rD   rD   rE   mpshort_modelr   rK   rQ   c                 C   rH   r=   rI   rB   rD   rD   rE   mpshortnotsorted_modelw   rK   rR   c                 C   rH   r=   rI   rB   rD   rD   rE   mpalphabet_model|   rK   rS   c                 C   rH   r=   rI   rB   rD   rD   rE   mpsortedautonow_model   rK   rT   c                 C   rH   r=   rI   rB   rD   rD   rE   mpsmallstep_model   rK   rU   c                 C   rH   r=   rI   rB   rD   rD   rE   mpm2muser_model   rK   rV   c                  G   s   t | }tdkr|d |S )N)r-    )listDJANGO_VERSIONappend)argsnew_argsrD   rD   rE   get_changelist_args   s   
r]   c                   @   s   e Zd Zdd ZdddZdS )TestTreeBasec                 C   s   |t jt jfv rIi }|jdddD ]\}}}||g ||g q| D ]!\}}t|t	|ks5J t
tdt|d }t||ksHJ q'dd | D S )Ntree_idlftrgtr+   c                 S       g | ]}|j | | fqS rD   r   	get_depthget_children_count.0orD   rD   rE   
<listcomp>       z$TestTreeBase.got.<locals>.<listcomp>)r   NS_TestNodeNS_TestNode_Proxyobjectsvalues_list
setdefaultextenditemslenmaxrX   rangesortedget_tree)selfrF   dr_   r`   ra   	got_edges
good_edgesrD   rD   rE   got   s   zTestTreeBase.gotNc                    sB     |}dd |D }||ksJ t fdd|D sJ d S )Nc                 S   s6   g | ]}|d  j |d d |d d |d d fqS )r   r+   opencloselevelr   rg   objrD   rD   rE   ri      s    (z;TestTreeBase._assert_get_annotated_list.<locals>.<listcomp>c                    s   g | ]
}t |d   kqS r   typer   rF   rD   rE   ri          )get_annotated_listall)rw   rF   expectedparentresultsr{   rD   r   rE   _assert_get_annotated_list   s   
z'TestTreeBase._assert_get_annotated_listr=   )__name__
__module____qualname__r{   r   rD   rD   rD   rE   r^      s    r^   c                   @   T   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 )TestEmptyTreec                 C   sZ   | t}dd |jj|dD }dd tD }t|t|ks"J | |tks+J d S )Nc                 S      g | ]}|j qS rD   r   r   rD   rD   rE   ri          z6TestEmptyTree.test_load_bulk_empty.<locals>.<listcomp>pk__inc                 S      g | ]}|d  qS r   rD   )rg   xrD   rD   rE   ri          )r@   rA   rm   filter	UNCHANGEDru   r{   )rw   rJ   ids	got_descsexpected_descsrD   rD   rE   test_load_bulk_empty   s
   
z"TestEmptyTree.test_load_bulk_emptyc                 C   s   |  g ksJ d S r=   )	dump_bulk)rw   rJ   rD   rD   rE   test_dump_bulk_empty   s   z"TestEmptyTree.test_dump_bulk_emptyc                 C   s(   |j dd dg}| ||ksJ d S )Nr   r   r*   add_rootr{   rw   rJ   r   rD   rD   rE   test_add_root_empty   s   z!TestEmptyTree.test_add_root_emptyc                 C   s&   |  }g }dd |D |ksJ d S )Nc                 S   r   rD   r   rg   noderD   rD   rE   ri      r   z;TestEmptyTree.test_get_root_nodes_empty.<locals>.<listcomp>get_root_nodes)rw   rJ   r{   r   rD   rD   rE   test_get_root_nodes_empty   s   z'TestEmptyTree.test_get_root_nodes_emptyc                 C      |  }|d u s
J d S r=   )get_first_root_noderw   rJ   r{   rD   rD   rE   test_get_first_root_node_empty      z,TestEmptyTree.test_get_first_root_node_emptyc                 C   r   r=   )get_last_root_noder   rD   rD   rE   test_get_last_root_node_empty   r   z+TestEmptyTree.test_get_last_root_node_emptyc                 C   s   t | }|g ksJ d S r=   )rX   rv   r   rD   rD   rE   test_get_tree   s   zTestEmptyTree.test_get_treec                 C   s   g }|  || d S r=   r   r   rD   rD   rE   test_get_annotated_list   s   z%TestEmptyTree.test_get_annotated_listc                 C   sN   |j dd |j dd |j dd |j dd g d}| ||ks%J d S )Nr   r   r   r&   r'   )r*   )r   r+   r   r5   )r'   r+   r   r   r   rD   rD   rE   0test_add_multiple_root_nodes_adds_sibling_leaves   s   z>TestEmptyTree.test_add_multiple_root_nodes_adds_sibling_leavesN)r   r   r   r   r   r   r   r   r   r   r   r   rD   rD   rD   rE   r      s    r   c                   @   s   e Zd ZdS )TestNonEmptyTreeN)r   r   r   rD   rD   rD   rE   r      s    r   c                   @      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#S )$TestClassMethodsc                 C   sl   |j jdd}|t|}g d}g d}dd |j j|dD }t|t|ks+J | ||ks4J d S )Nr"   r   )r*   r,   r.   r0   r1   r"   r3   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   r   r4   r5   r6   r7   )
r   r   r   r    r!   r"   r%   r&   r'   r(   c                 S   r   rD   r   r   rD   rD   rE   ri     r   z<TestClassMethods.test_load_bulk_existing.<locals>.<listcomp>r   )rm   getr@   rA   r   ru   r{   )rw   rF   r   r   r   r   r   rD   rD   rE   test_load_bulk_existing   s   z(TestClassMethods.test_load_bulk_existingc                    s@      }dd |D }|tksJ t fdd|D sJ d S )Nc                 S   rb   rD   rc   rf   rD   rD   rE   ri   
       z6TestClassMethods.test_get_tree_all.<locals>.<listcomp>c                       g | ]}t | kqS rD   r   rf   r   rD   rE   ri         )rv   r   r   )rw   rF   nodesr{   rD   r   rE   test_get_tree_all  s   z"TestClassMethods.test_get_tree_allc                 C   s   |j ddtks
J d S )NFkeep_ids)r   rA   rw   rF   rD   rD   rE   test_dump_bulk_all     z#TestClassMethods.test_dump_bulk_allc                    st    j jdd} t|  j j|jd} |}dd |D }g d}||ks+J t fdd|D s8J d S )Nr"   r   pkc                 S   rb   rD   rc   rf   rD   rD   rE   ri     r   z7TestClassMethods.test_get_tree_node.<locals>.<listcomp>)r   r   r   r   r   r   r   r   r   r   r   c                    r   rD   r   rf   r   rD   rE   ri   (  r   )rm   r   r@   rA   r   rv   r   rw   rF   r   r   r{   r   rD   r   rE   test_get_tree_node  s   
z#TestClassMethods.test_get_tree_nodec                    sf    j jdd}d| ksJ  |}dd |D }dg}||ks$J t fdd|D s1J d S )Nr   r   r   c                 S   rb   rD   rc   rf   rD   rD   rE   ri   /  r   z7TestClassMethods.test_get_tree_leaf.<locals>.<listcomp>r*   c                    r   rD   r   rf   r   rD   rE   ri   2  r   )rm   r   re   rv   r   r   rD   r   rE   test_get_tree_leaf*  s   
z#TestClassMethods.test_get_tree_leafc                 C   s   ddg dfddg dfddg dfddg dfd	dg dfd
ddgdfdddgdfddg dfddg dfddddgdfg
}|  || d S )Nr   Tr   r   Fr   r+   r    r!   r"   r/   r%   r&   r'   r(   r   rw   rF   r   rD   rD   rE   test_get_annotated_list_all4  s   






z,TestClassMethods.test_get_annotated_list_allc              	   C   sf   |j jdd}ddg dfddg dfddg dfd	dg dfd
ddgdfddddgdfg}| ||| d S )Nr   r   Tr   r   r+   r    Fr!   r"   r/   r%   rm   r   r   rw   rF   r   r   rD   rD   rE   test_get_annotated_list_nodeC  s   



z-TestClassMethods.test_get_annotated_list_nodec                 C   s0   |j jdd}dddgdfg}| ||| d S )Nr   r   Tr   r   r   rD   rD   rE   test_get_annotated_list_leafO  s   z-TestClassMethods.test_get_annotated_list_leafc                 C   sV   |j jdd}|t| |j j|jd}||d}dditdg}||ks)J d S )Nr"   r   r   Fr   r#   )rm   r   r@   rA   r   r   )rw   rF   r   r{   r   rD   rD   rE   test_dump_bulk_nodeT  s   z$TestClassMethods.test_dump_bulk_nodec                 C   sb   |j dd}|j   ||d d |j dd}||ks J dd | D }|tks/J d S )NTr   c                 S   rb   rD   rc   rf   rD   rD   rE   ri   f  rj   zHTestClassMethods.test_load_and_dump_bulk_keeping_ids.<locals>.<listcomp>)r   rm   r   deleter@   rv   r   )rw   rF   expr{   rD   rD   rE   #test_load_and_dump_bulk_keeping_ids_  s   z4TestClassMethods.test_load_and_dump_bulk_keeping_idsc              	   C   s   |j    tjj jd|j d\}}dd|jdid|jddd|jdidd|jdid	|jddd
|jdigddd|jdigddd|jdid|jddd|jdigdg}|| |j	dd}||kspJ d S )NzTest %sr   r   r   )r   relatedr   r   r    r!   r"   r#   r%   r&   r'   r(   Fr   )
rm   r   r   r   RelatedModelget_or_creater   r   r@   r   )rw   rO   r   createdrelated_datar{   rD   rD   rE   test_load_and_dump_bulk_with_fkk  s0   




z0TestClassMethods.test_load_and_dump_bulk_with_fkc                    sD      }g d}dd |D |ksJ t fdd|D s J d S )Nr   r   r&   r'   c                 S   r   rD   r   r   rD   rD   rE   ri     r   z8TestClassMethods.test_get_root_nodes.<locals>.<listcomp>c                    r   rD   r   r   r   rD   rE   ri     r   )r   r   )rw   rF   r{   r   rD   r   rE   test_get_root_nodes  s   z$TestClassMethods.test_get_root_nodesc                 C   *   |  }|jdksJ t||ksJ d S Nr   )r   r   r   rw   rF   r{   rD   rD   rE   test_get_first_root_node     z)TestClassMethods.test_get_first_root_nodec                 C   r   )Nr'   )r   r   r   r   rD   rD   rE   test_get_last_root_node  r   z(TestClassMethods.test_get_last_root_nodec                 C   sF   |j dd}| dksJ | }|jdksJ t||ks!J d S )N5r   r+   )r   rd   r   r   r   )rw   rF   r   r{   rD   rD   rE   test_add_root  s
   zTestClassMethods.test_add_rootc                 C   sL   |dd}|j |d}||ksJ | }|jdksJ t||ks$J d S )Nr   r   instance)r   r   r   r   )rw   rF   r   resultr{   rD   rD   rE   "test_add_root_with_passed_instance  s   
z3TestClassMethods.test_add_root_with_passed_instancec                 C   sJ   |j jdd}tt |j|d W d    d S 1 sw   Y  d S )Nr'   r   r   )rm   r   pytestraisesr   r   )rw   rF   r   rD   rD   rE   )test_add_root_with_already_saved_instance     "z:TestClassMethods.test_add_root_with_already_saved_instanceN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rD   rD   rD   rE   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'S )(TestSimpleNodeMethodsc                 C   8   g d}|D ]\}}|j j|d }||ksJ qd S )N))r   T)r   T)r'   T)r   F)r%   F)r    F)r"   Fr   rm   r   is_rootrw   rF   r   r   r   r{   rD   rD   rE   test_is_root  s
   	z"TestSimpleNodeMethods.test_is_rootc                 C   r   )N))r   F)r!   F)r"   Tr   rm   r   is_leafr   rD   rD   rE   test_is_leaf  
   z"TestSimpleNodeMethods.test_is_leafc                 C   J   g d}|D ]\}}|j j|d }|j|ksJ t||ks"J qd S )N)r   r   r   r   r'   r'   r   r   r%   r   r    r   )r"   r   r   )rm   r   get_rootr   r   rw   rF   r   r   r   r   rD   rD   rE   test_get_root     	z#TestSimpleNodeMethods.test_get_rootc                 C   s   g d}t |}i }| D ].\}}|jj|d}| }|r/|j|ks&J t||ks.J n|d u s5J |||< d|_q| D ]%\}}|| }|d}|r`|j|ksWJ t||ks_J qA|d u sfJ qAd S )N))r   Nr   Nr'   Nr  r  r  )r"   r!   r   zCORRUPTED!!!T)dictrq   rm   r   
get_parentr   r   _parent_obj)rw   rF   r   objsr   r   r   r   rD   rD   rE   test_get_parent  s(   	
z%TestSimpleNodeMethods.test_get_parentc                    sp   dg dfddgfdg fg}|D ]%\}} j j|d }dd |D |ks(J t fdd|D s5J qd S )	Nr   r   r    r!   r%   r!   r"   r   c                 S   r   rD   r   r   rD   rD   rE   ri     r   z;TestSimpleNodeMethods.test_get_children.<locals>.<listcomp>c                    r   rD   r   r   r   rD   rE   ri     r   )rm   r   get_childrenr   )rw   rF   r   r   r   r$   rD   r   rE   test_get_children  s   
z'TestSimpleNodeMethods.test_get_childrenc                 C   r   )N))r   r-   r!   r+   r"   r   r   rm   r   re   r   rD   rD   rE   test_get_children_count
  r  z-TestSimpleNodeMethods.test_get_children_countc                    st   dg dfdg dfddgfg}|D ]%\}} j j|d }dd |D |ks*J t fd	d|D s7J qd S )
Nr   r   r   r  r"   r   c                 S   r   rD   r   r   rD   rD   rE   ri     r   z;TestSimpleNodeMethods.test_get_siblings.<locals>.<listcomp>c                    r   rD   r   r   r   rD   rE   ri     r   )rm   r   get_siblingsr   )rw   rF   r   r   r   siblingsrD   r   rE   test_get_siblings  s   

z'TestSimpleNodeMethods.test_get_siblingsc                 C   r  )N)r   r   r  )r'   r   )r   r   )r%   r   r    r   r"   r"   r   )rm   r   get_first_siblingr   r   r
  rD   rD   rE   test_get_first_sibling  r  z,TestSimpleNodeMethods.test_get_first_siblingc                 C   `   g d}|D ]'\}}|j j|d }|d u r|d u sJ q|j|ks%J t||ks-J qd S )N)r  r  )r'   r&   r   N)r%   r!   r  r"   Nr   )rm   r   get_prev_siblingr   r   r
  rD   rD   rE   test_get_prev_sibling.     	z+TestSimpleNodeMethods.test_get_prev_siblingc                 C   r#  )N)r   r&   )r   r   r  )r   r    )r%   N)r    r!   r%  r   )rm   r   get_next_siblingr   r   r
  rD   rD   rE   test_get_next_sibling@  r(  z+TestSimpleNodeMethods.test_get_next_siblingc                 C   r  )N))r   r'   )r   r'   r  )r   r%   )r%   r%   )r    r%   r   r   )rm   r   get_last_siblingr   r   r
  rD   rD   rE   test_get_last_siblingR  r  z+TestSimpleNodeMethods.test_get_last_siblingc                 C   r#  )N))r   r   r$  r!   r"   r%  r   )rm   r   get_first_childr   r   r
  rD   rD   rE   test_get_first_childa     z*TestSimpleNodeMethods.test_get_first_childc                 C   r#  )N))r   r%   r$  r.  r%  r   )rm   r   get_last_childr   r   r
  rD   rD   rE   test_get_last_childp  r1  z)TestSimpleNodeMethods.test_get_last_childc                    sp   dg fddgfdddgfg}|D ]%\}} j j|d }dd |D |ks(J t fdd|D s5J qd S )	Nr   r   r"   r!   r   c                 S   r   rD   r   r   rD   rD   rE   ri     r   z<TestSimpleNodeMethods.test_get_ancestors.<locals>.<listcomp>c                    r   rD   r   r   r   rD   rE   ri     r   )rm   r   get_ancestorsr   rw   rF   r   r   r   r   rD   r   rE   test_get_ancestors  s   
z(TestSimpleNodeMethods.test_get_ancestorsc                    s~   dg dfddgfdg fdg fddgfg}|D ]%\}} j j|d }d	d
 |D |ks/J t fdd
|D s<J qd S )Nr   )r   r    r!   r"   r%   r!   r"   r   r'   r(   r   c                 S   r   rD   r   r   rD   rD   rE   ri     r   z>TestSimpleNodeMethods.test_get_descendants.<locals>.<listcomp>c                    r   rD   r   r   r   rD   rE   ri     r   )rm   r   get_descendantsr   r5  rD   r   rE   test_get_descendants  s   
z*TestSimpleNodeMethods.test_get_descendantsc                 C   r   )N))r   r   r  r  r   r   r'   r+   r   rm   r   get_descendant_countr   rD   rD   rE   test_get_descendant_count  s
   z/TestSimpleNodeMethods.test_get_descendant_countc                 C   J   g d}|D ]\}}}|j j|d}|j j|d}|||ks"J qd S )N))r   r   T)r   r   T)r   r   Fr"   r   F)r    r!   T)r"   r!   F)r"   r"   Tr   )rm   r   is_sibling_ofrw   rF   r   desc1desc2r   node1node2rD   rD   rE   test_is_sibling_of  s   	z(TestSimpleNodeMethods.test_is_sibling_ofc                 C   r>  )N)r   r   Fr   r   Fr   r   Tr?  r"   r!   Tr"   r"   Fr   )rm   r   is_child_ofrA  rD   rD   rE   test_is_child_of     z&TestSimpleNodeMethods.test_is_child_ofc                 C   r>  )N)rG  rH  rI  )r"   r   TrJ  rK  r   )rm   r   is_descendant_ofrA  rD   rD   rE   test_is_descendant_of  rN  z+TestSimpleNodeMethods.test_is_descendant_ofN)r   r   r   r   r   r  r  r  r  r  r"  r'  r+  r-  r0  r3  r6  r8  r=  rF  rM  rP  rD   rD   rD   rE   r     s(    
#
r   c                   @   <   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestAddChildc                 C   4   |j jddjdd g d}| ||ksJ d S )Nr"   r   2311r*   r,   r.   r0   r1   )r"   r3   r+   )rT  r-   r   r4   r5   r6   r7   rm   r   	add_childr{   r   rD   rD   rE   test_add_child_to_leaf     z#TestAddChild.test_add_child_to_leafc                 C   rS  )Nr   r   25)r*   r   r+   r   r.   r0   r1   r2   r4   )rZ  r/   r   r5   r6   r7   rV  r   rD   rD   rE   test_add_child_to_node  rY  z#TestAddChild.test_add_child_to_nodec                 C   sJ   |dd}|j jddj|d}||ksJ g d}| ||ks#J d S )NrT  r   r"   r   rU  rV  )rw   rF   childr   r   rD   rD   rE   #test_add_child_with_passed_instance  s
   
z0TestAddChild.test_add_child_with_passed_instancec                 C   sT   |j jdd}tt |j jddj|d W d    d S 1 s#w   Y  d S )Nr   r   r   r   )rm   r   r   r   r   rW  )rw   rF   r]  rD   rD   rE   *test_add_child_with_already_saved_instance  s   "z7TestAddChild.test_add_child_with_already_saved_instancec                 C   2   |ddd}|j jddj|d}||ksJ dS 
        If the model is using a natural primary key then it will be
        already set when the instance is inserted.
        ?B znatural key)r   r   r   r   r   Nrm   r   rW  rw   rF   r]  r   rD   rD   rE   test_add_child_with_pk_set     z'TestAddChild.test_add_child_with_pk_setc              	   C   s\   z&t tdddd }|jjdd}| sJ |jdd W tjdd d S tjdd w )Ntest_add_child_post_save)dispatch_uidc                 [   s$   |   }|  | dksJ d S Nr+   )r  refresh_from_dbr<  )r   kwargsr   rD   rD   rE   on_post_save  s   z;TestAddChild.test_add_child_post_save.<locals>.on_post_saver"   r   rT  )r	   r   rm   r   r   rW  
disconnect)rw   rF   rm  r   rD   rD   rE   rh    s   

z%TestAddChild.test_add_child_post_saveN)	r   r   r   rX  r\  r^  r_  rf  rh  rD   rD   rD   rE   rR    s    	rR  c                   @   r   )$TestAddSiblingc                 C   sD   t t |jjddd W d    d S 1 sw   Y  d S Nr"   r   invalid_pos)r   r   r   rm   r   add_siblingr   rD   rD   rE   test_add_sibling_invalid_pos(  s   "z+TestAddSibling.test_add_sibling_invalid_posc                 C   sL   |j jdd}tt |jddd W d    d S 1 sw   Y  d S )Nr   r   sorted-siblingaaa)rm   r   r   r   r   rr  )rw   rF   node_wchildrenrD   rD   rE   $test_add_sibling_missing_nodeorderby,  s   "z3TestAddSibling.test_add_sibling_missing_nodeorderbyc                 C   B   |j jdd}|jddd}| dksJ | jdksJ d S )Nr   r   last-siblingr   r+   rm   r   rr  rd   r,  r   )rw   rF   rv  r   rD   rD   rE   test_add_sibling_last_root1     z)TestAddSibling.test_add_sibling_last_rootc                 C   rx  )Nr"   r   ry  232r3   rz  )rw   rF   r   r   rD   rD   rE   test_add_sibling_last7  r|  z$TestAddSibling.test_add_sibling_lastc                 C   J   |j jdd}|jddd}| dksJ g d}| ||ks#J d S )Nr   r   first-siblingnewr+   r  r+   r   r*   r,   r.   r0   r1   r2   r4   r5   r6   r7   rm   r   rr  rd   r{   rw   rF   rv  r   r   rD   rD   rE   test_add_sibling_first_root=  
   z*TestAddSibling.test_add_sibling_first_rootc                 C   r  )Nr!   r   r  r  r/   )r*   r[  r  r/   r   r.   r0   r1   r2   r4   r5   r6   r7   r  r  rD   rD   rE   test_add_sibling_firstP  r  z%TestAddSibling.test_add_sibling_firstc                 C   r  )Nr   r   leftr  r+   )r*   r  r,   r.   r0   r1   r2   r4   r5   r6   r7   r  r  rD   rD   rE   test_add_sibling_left_rootc  r  z)TestAddSibling.test_add_sibling_left_rootc                 C   r  )Nr!   r   r  r  r/   )r*   r[  r.   r0   r  r1   r2   r4   r5   r6   r7   r  r  rD   rD   rE   test_add_sibling_leftv  r  z$TestAddSibling.test_add_sibling_leftc                 C   r  )Nr   r   r  r  r+   r  r  rw   rF   r   r   r   rD   rD   rE   !test_add_sibling_left_noleft_root  r  z0TestAddSibling.test_add_sibling_left_noleft_rootc                 C   r  )Nr"   r   r  r  r3   )r*   r,   r.   r0   r!   r/   r/   r  r3   r   r2   r4   r5   r6   r7   r  r  rD   rD   rE   test_add_sibling_left_noleft  r  z+TestAddSibling.test_add_sibling_left_noleftc                 C   r  )Nr   r   rightr  r+   )r*   r,   r.   r0   r1   r2   r4   r  r5   r6   r7   r  r  rD   rD   rE   test_add_sibling_right_root  r  z*TestAddSibling.test_add_sibling_right_rootc                 C   r  )Nr!   r   r  r  r/   )r*   r[  r.   r0   r1   r2   r  r4   r5   r6   r7   r  r  rD   rD   rE   test_add_sibling_right  r  z%TestAddSibling.test_add_sibling_rightc                 C   r  )Nr'   r   r  r  r+   )r*   r,   r.   r0   r1   r2   r4   r5   r6   r7   r  r  r  rD   rD   rE   #test_add_sibling_right_noright_root  r  z2TestAddSibling.test_add_sibling_right_noright_rootc                 C   r  )Nr"   r   r  r  r3   )r*   r,   r.   r0   r  r2   r  r4   r5   r6   r7   r  r  rD   rD   rE   test_add_sibling_right_noright  r  z-TestAddSibling.test_add_sibling_right_norightc                 C   sX   |j jdd}|dd}|jd|d}||ksJ | dks!J | jdks*J d S )Nr   r   r   ry  r   r+   rz  )rw   rF   rv  r   r   rD   rD   rE   %test_add_sibling_with_passed_instance  s   
z4TestAddSibling.test_add_sibling_with_passed_instancec                 C   sZ   |j jdd}|j jdd}tt |jd|d W d    d S 1 s&w   Y  d S )Nr   r   r'   ry  r   )rm   r   r   r   r   rr  )rw   rF   rv  existing_noderD   rD   rE   'test_add_sibling_already_saved_instance  s
   "z6TestAddSibling.test_add_sibling_already_saved_instancec                 C   r`  ra  rd  re  rD   rD   rE   rf  	  rg  z)TestAddSibling.test_add_child_with_pk_setN)r   r   r   rs  rw  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  rf  rD   rD   rD   rE   ro  &  s$    ro  c                   @   s~   e Zd Zeejdeejej	dd d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 )
TestDeleter8   c                 C      d| d j  d| d j  S )Nbase=r   z dep=r+   r   fvrD   rD   rE   <lambda>  r   zTestDelete.<lambda>r:   r;   r   c                 C   s:   | j \}}|t |j D ]	}||d  q||fS )N)r   )r?   r@   rA   rm   r   save)rC   
base_model	dep_modelr   rD   rD   rE   delete_dep_model_pair  s
   

z TestDelete.delete_dep_model_pairc                 C   X   |\}}|j jdd }g d}| ||ksJ |d|jjd|jjdifks*J d S )Nr"   r   )	r*   r,   r.   r0   r!   r/   r   r4   r5   r6   r7   r/   r+   rm   r   r   r{   _metalabelrw   r  delete_modelr  r   r   rD   rD   rE   test_delete_leaf"  s
   $zTestDelete.test_delete_leafc                 C   r  )Nr!   r   )r*   )r   r+   r3   r.   r0   r4   r5   r6   r7   r-   r/   r  r  rD   rD   rE   test_delete_node3  s
   
$zTestDelete.test_delete_nodec                 C   r  )Nr   r   r*   r5   r6   r7      r   r  r  rD   rD   rE   test_delete_rootC  
   $zTestDelete.test_delete_rootc                 C   r  )Nr)  desc__in)r*   r6   r7         rm   r   r   r{   r  r  r  rD   rD   rE   test_delete_filter_root_nodesJ  r  z(TestDelete.test_delete_filter_root_nodesc                 C   r  )N)r   r!   r"   r  r  r  r   r  r  rD   rD   rE   test_delete_filter_childrenQ  r  z&TestDelete.test_delete_filter_childrenc                 C   s@   |\}}|j jdd }| |tksJ |di fksJ d S )N)ZZZXXXr  r   )rm   r   r   r{   r   rw   r  r  r  r   rD   rD   rE   test_delete_nonexistant_nodesX  s   z(TestDelete.test_delete_nonexistant_nodesc                 C   r  )Nr  r  r  r  r   r  r  rD   rD   rE   test_delete_same_node_twice^  r  z&TestDelete.test_delete_same_node_twicec                 C   sJ   |\}}|   }|d|jjd|jjdifksJ |j dks#J d S N   
   r   )r   r   r  r  rm   countr  rD   rD   rE   test_delete_all_root_nodese  s    z%TestDelete.test_delete_all_root_nodesc                 C   sL   |\}}|j   }|d|jjd|jjdifksJ |j  dks$J d S r  )rm   r   r   r  r  r  r  rD   rD   rE   test_delete_all_nodesk  s    z TestDelete.test_delete_all_nodesN)r   r   r   staticmethodr   fixturezipr   BASE_MODELS
DEP_MODELSr  r  r  r  r  r  r  r  r  r  rD   rD   rD   rE   r    s"    r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestMoveErrorsc                 C   sJ   |j jdd}tt ||d W d    d S 1 sw   Y  d S rp  )rm   r   r   r   r   moverw   rF   r   rD   rD   rE   test_move_invalid_post  r   z$TestMoveErrors.test_move_invalid_posc                 C   sX   |j jdd}|j jdd}tt ||d W d    d S 1 s%w   Y  d S )Nr   r   r"   r  )rm   r   r   r   r   r  )rw   rF   r   targetrD   rD   rE   test_move_to_descendanty  s
   "z&TestMoveErrors.test_move_to_descendantc                 C   s   |j jdd}tt ||d W d    n1 sw   Y  tt ||d W d    d S 1 s9w   Y  d S )Nr"   r   sorted-childrt  )rm   r   r   r   r   r  r  rD   rD   rE   test_move_missing_nodeorderby  s   "z,TestMoveErrors.test_move_missing_nodeorderbyN)r   r   r   r  r  r  rD   rD   rD   rE   r  r  s    r  c                   @      e Zd Zdd ZdS )TestMoveSortedErrorsc                 C   sL   |j dddd}tt ||d W d    d S 1 sw   Y  d S )Nr3   zxyval1val2r   r  )r   r   r   r   r  )rw   rN   r   rD   rD   rE   test_nonsorted_move_in_sorted  s   "z2TestMoveSortedErrors.test_nonsorted_move_in_sortedN)r   r   r   r  rD   rD   rD   rE   r        r  c                   @   rQ  )TestMoveLeafRootc                 C   B   |j jdd}|j jdd|d g d}| ||ksJ d S )Nr   r   r"   ry  )
r*   r,   r.   r0   r  r4   r5   r6   r7   r"   r+   r   rm   r   r  r{   rw   rF   r  r   rD   rD   rE    test_move_leaf_last_sibling_root     z1TestMoveLeafRoot.test_move_leaf_last_sibling_rootc                 C   r  )Nr   r   r"   r  )
r  r*   r,   r.   r0   r  r4   r5   r6   r7   r  r  rD   rD   rE   !test_move_leaf_first_sibling_root  r  z2TestMoveLeafRoot.test_move_leaf_first_sibling_rootc                 C   r  )Nr   r   r"   r  
r*   r  r,   r.   r0   r  r4   r5   r6   r7   r  r  rD   rD   rE    test_move_leaf_left_sibling_root  r  z1TestMoveLeafRoot.test_move_leaf_left_sibling_rootc                 C   r  )Nr   r   r"   r  )
r*   r,   r.   r0   r  r4   r  r5   r6   r7   r  r  rD   rD   rE   !test_move_leaf_right_sibling_root  r  z2TestMoveLeafRoot.test_move_leaf_right_sibling_rootc                 C   r  )Nr   r   r"   
last-child
r*   r[  r.   r0   r  r4   r"   r/   r   r5   r6   r7   r  r  rD   rD   rE   test_move_leaf_last_child_root  r  z/TestMoveLeafRoot.test_move_leaf_last_child_rootc                 C   r  )Nr   r   r"   first-child
r*   r[  r  r.   r0   r  r4   r5   r6   r7   r  r  rD   rD   rE   test_move_leaf_first_child_root  r  z0TestMoveLeafRoot.test_move_leaf_first_child_rootN)	r   r   r   r  r  r  r  r  r  rD   rD   rD   rE   r    s    r  c                   @   D   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S )TestMoveLeafc                 C   r  )Nr    r   r"   ry  r  r  r  rD   rD   rE   test_move_leaf_last_sibling  r  z(TestMoveLeaf.test_move_leaf_last_siblingc                 C   r  )Nr    r   r"   r  r  r  r  rD   rD   rE   test_move_leaf_first_sibling  r  z)TestMoveLeaf.test_move_leaf_first_siblingc                 C   r  )Nr    r   r"   r  )
r*   r[  r.   r  r0   r  r4   r5   r6   r7   r  r  rD   rD   rE   test_move_leaf_left_sibling  r  z(TestMoveLeaf.test_move_leaf_left_siblingc                 C   r  )Nr    r   r"   r  )
r*   r[  r.   r0   r  r  r4   r5   r6   r7   r  r  rD   rD   rE   test_move_leaf_right_sibling-  r  z)TestMoveLeaf.test_move_leaf_right_siblingc                 C   :   |j jdd}|j jdd|d | |tksJ d S )Nr"   r   r  rm   r   r  r{   r   rw   rF   r  rD   rD   rE   "test_move_leaf_left_sibling_itself>     z/TestMoveLeaf.test_move_leaf_left_sibling_itselfc                 C   r  )Nr    r   r"   r  
r*   r,   r.   )r    r/   r+   r2   r  r4   r5   r6   r7   r  r  rD   rD   rE   test_move_leaf_last_childC  r  z&TestMoveLeaf.test_move_leaf_last_childc                 C   r  )Nr    r   r"   r  r  r  r  rD   rD   rE   test_move_leaf_first_childT  r  z'TestMoveLeaf.test_move_leaf_first_childN)
r   r   r   r  r  r  r  r  r  r  rD   rD   rD   rE   r    s    r  c                   @   L   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 )TestMoveBranchRootc                 C   r  )Nr   r   r'   r  
r6   r7   r*   r,   r.   r0   r1   r2   r4   r5   r  r  rD   rD   rE   #test_move_branch_first_sibling_rooth  r  z6TestMoveBranchRoot.test_move_branch_first_sibling_rootc                 C   r  )Nr   r   r'   ry  r)   r  r  rD   rD   rE   "test_move_branch_last_sibling_rooty  r  z5TestMoveBranchRoot.test_move_branch_last_sibling_rootc                 C   r  )Nr   r   r'   r  )
r*   r6   r7   r,   r.   r0   r1   r2   r4   r5   r  r  rD   rD   rE   "test_move_branch_left_sibling_root  r  z5TestMoveBranchRoot.test_move_branch_left_sibling_rootc                 C   r  )Nr   r   r'   r  )
r*   r,   r.   r0   r1   r2   r4   r6   r7   r5   r  r  rD   rD   rE   #test_move_branch_right_sibling_root  r  z6TestMoveBranchRoot.test_move_branch_right_sibling_rootc                 C   F   |j jdd }|j jdd|d g d}| ||ks!J d S )Nr   r   r'   r  r  rm   r   r!  r  r{   r  rD   rD   rE   )test_move_branch_left_noleft_sibling_root     z<TestMoveBranchRoot.test_move_branch_left_noleft_sibling_rootc                 C   r  )Nr   r   r'   r  r)   rm   r   r,  r  r{   r  rD   rD   rE   +test_move_branch_right_noright_sibling_root  r  z>TestMoveBranchRoot.test_move_branch_right_noright_sibling_rootc                 C   r  )Nr   r   r'   r  
r*   r[  r'   r/   r+   r(   r3   r   r.   r0   r1   r2   r4   r5   r  r  rD   rD   rE   !test_move_branch_first_child_root  r  z4TestMoveBranchRoot.test_move_branch_first_child_rootc                 C   r  )Nr   r   r'   r  
r*   r[  r.   r0   r1   r2   r4   r  r	  r5   r  r  rD   rD   rE    test_move_branch_last_child_root  r  z3TestMoveBranchRoot.test_move_branch_last_child_rootN)r   r   r   r  r  r  r   r  r  r
  r  rD   rD   rD   rE   r  f  s    r  c                   @   r   )TestMoveBranchc                 C   r  )Nr!   r   r'   r  r  r  r  rD   rD   rE   test_move_branch_first_sibling  r  z-TestMoveBranch.test_move_branch_first_siblingc                 C   r  )Nr!   r   r'   ry  r  r  r  rD   rD   rE   test_move_branch_last_sibling  r  z,TestMoveBranch.test_move_branch_last_siblingc                 C   r  )Nr!   r   r'   r  )
r*   r[  r.   r0   r  r	  r1   r2   r4   r5   r  r  rD   rD   rE   test_move_branch_left_sibling  r  z,TestMoveBranch.test_move_branch_left_siblingc                 C   r  )Nr!   r   r'   r  )
r*   r[  r.   r0   r1   r2   r  r	  r4   r5   r  r  rD   rD   rE   test_move_branch_right_sibling&  r  z-TestMoveBranch.test_move_branch_right_siblingc                 C   r  )Nr!   r   r'   r  r  r  r  rD   rD   rE   $test_move_branch_left_noleft_sibling7  r  z3TestMoveBranch.test_move_branch_left_noleft_siblingc                 C   r  )Nr!   r   r'   r  r  r  r  rD   rD   rE   &test_move_branch_right_noright_siblingH  r  z5TestMoveBranch.test_move_branch_right_noright_siblingc                 C   r  )Nr'   r   r  r  r  rD   rD   rE   $test_move_branch_left_itself_siblingY  r  z3TestMoveBranch.test_move_branch_left_itself_siblingc                 C   r  )Nr!   r   r'   r  )
r*   r,   r.   r0   r  r'   r3   r+   r(   r-   r   r2   r4   r5   r  r  rD   rD   rE   test_move_branch_first_child^  r  z+TestMoveBranch.test_move_branch_first_childc                 C   r  )Nr!   r   r'   r  )
r*   r,   r.   r0   r  r2   r  r  r4   r5   r  r  rD   rD   rE   test_move_branch_last_childo  r  z*TestMoveBranch.test_move_branch_last_childN)r   r   r   r  r  r  r  r  r  r  r  r  rD   rD   rD   rE   r    s    r  c                   @   rQ  )TestTreeSortedc                 C      dd |  D S )Nc                 S   s(   g | ]}|j |j|j| | fqS rD   )r  r  r   rd   re   rf   rD   rD   rE   ri     s    z&TestTreeSorted.got.<locals>.<listcomp>rv   )rw   rN   rD   rD   rE   r{        zTestTreeSorted.gotc                 C   s   |j dddd |j dddd |j dddd |j ddd	d |j ddd
d |j ddd	d |j dddd |j dddd g d}| ||ksMJ d S )Nr3   r  r  r+   r-   bcdr/   r   abcfghqwevcx)r+   r-   r  r+   r   )r/   r/   r   r+   r   )r/   r   r  r+   r   )r3   r/   r!  r+   r   r3   r3   r  r+   r   r#  )r3   r3   r  r+   r   )r-   r+   r  r+   r   r   )rw   rN   r   rD   rD   rE   test_add_root_sorted  s   
z#TestTreeSorted.test_add_root_sortedc                 C   s   |j dddd}|jdddd |jdddd |jd	d
dd |jdddd |jdddd |jdddd |jd	d	dd |jdd	dd g d}| ||ksUJ d S )Nr   ru  r  r3   r  r+   r-   r  r/   r   r  r  r   r!  )	)r   r   ru  r+      )r+   r-   r  r/   r   r/   r/   r   r/   r   r/   r   r  r/   r   r3   r/   r!  r/   r   r3   r3   r  r/   r   r)  r3   r3   r  r/   r   r-   r+   r  r/   r   )r   rW  r{   )rw   rN   rootr   rD   rD   rE   test_add_child_root_sorted  s   z)TestTreeSorted.test_add_child_root_sortedc                    s    fdd} j ddddj}||jddddj}||jdddd ||jdddd ||jddd	d ||jddd
d ||jdddd g d}|  |ksYJ d S )Nc                    s    j j| dS )Nr   )rm   r   )node_idrN   rD   rE   r    s    z>TestTreeSorted.test_add_child_nonroot_sorted.<locals>.<lambda>r   ar  acaaavacaaccacb))r   r   r0  r+   r3   )r   r   r2  r/   r   )r   r   r1  r/   r3   )r   r   r4  r3   r   )r   r   r6  r3   r   )r   r   r5  r3   r   )r   r   r3  r/   r   )r   r   rW  r{   )rw   rN   get_noderoot_idr.  r   rD   r/  rE   test_add_child_nonroot_sorted  s   	z,TestTreeSorted.test_add_child_nonroot_sortedc                 C   s   |j dddd |j dddd |j dddd |j ddd	d |j ddd
d |j ddd	d |j dddd |j dddd | }|d }|dd  D ]}|jj|jd}|jj|jd}||d qNg d}| ||kstJ d S )Nr3   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   rm   r   r   r  r{   rw   rN   
root_nodesr  r   r   rD   rD   rE   test_move_sorted  s    
zTestTreeSorted.test_move_sortedc                 C   s  |j dddd |j dddd |j dddd |j ddd	d |j ddd
d |j ddd	d |j dddd |j dddd | }|d }|dd  D ]#}|jj|jd}|jj|jd}| jd8  _|  ||d qNg d}| ||ksJ d S )Nr3   r  r  r+   r-   r  r/   r   r  r  r   r!  r   r   rt  ))r   r/   r   r+   r   )r   r   r  r+   r   )r+   r/   r!  r+   r   r+   r3   r  r+   r   r=  )r+   r3   r  r+   r   r"  )r/   r+   r  r+   r   )	r   r   rm   r   r   r  r  r  r{   r:  rD   rD   rE   test_move_sortedsibling  s$   
z&TestTreeSorted.test_move_sortedsiblingN)	r   r   r   r{   r$  r-  r9  r<  r>  rD   rD   rD   rE   r    s    r  c                   @   s   e Zd Zeejdeejej	dd d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 d3S )4TestInheritedModelsr8   c                 C   r  )Nr  r   z inherited=r+   r  r  rD   rD   rE   r    r   zTestInheritedModels.<lambda>r  c                 C   s   | j \}}|jdd |jdd |dd}|jjddj|d |jjddjdd |jjddjdd |jjddjdd |d	d}|j|d |S )
Nr   r   r   r   r   211212r    r&   )r?   r   rm   r   rW  )rC   r  rP   node21node3rD   rD   rE   rP   	  s   


z#TestInheritedModels.inherited_modelc                 C   s*   dd |  D }g d}||ksJ d S )Nc                 S   rb   rD   rc   rf   rD   rD   rE   ri          z9TestInheritedModels.test_get_tree_all.<locals>.<listcomp>)r*   )r   r+   r/   r   r/   r/   r@  r3   r   rA  r3   r   r0   r5   r  rw   rP   r{   r   rD   rD   rE   r     s
   	z%TestInheritedModels.test_get_tree_allc                 C   s:   |j jdd}dd ||D }g d}||ksJ d S )Nr   r   c                 S   rb   rD   rc   rf   rD   rD   rE   ri   2  rD  z:TestInheritedModels.test_get_tree_node.<locals>.<listcomp>)rE  rF  rG  )rm   r   rv   )rw   rP   r   r{   r   rD   rD   rE   r   /  s   z&TestInheritedModels.test_get_tree_nodec                 C   s*   |  }g d}dd |D |ksJ d S )Nr   r   r&   c                 S   r   rD   r   r   rD   rD   rE   ri   @  r   z;TestInheritedModels.test_get_root_nodes.<locals>.<listcomp>r   rH  rD   rD   rE   r   =  s   z'TestInheritedModels.test_get_root_nodesc                 C      |  }|jdksJ d S r   )r   r   rw   rP   r{   rD   rD   rE   r   B     z,TestInheritedModels.test_get_first_root_nodec                 C   rJ  )Nr&   )r   r   rK  rD   rD   rE   r   F  rL  z+TestInheritedModels.test_get_last_root_nodec                 C   @   |j jdd}|j jdd}| du sJ | du sJ d S Nr   r   r&   FTr   rw   rP   rB  rC  rD   rD   rE   r   J     z TestInheritedModels.test_is_rootc                 C   rM  rN  r   rO  rD   rD   rE   r   P  rP  z TestInheritedModels.test_is_leafc                 C   D   |j jdd}|j jdd}| jdksJ | jdks J d S Nr   r   r&   r   )rm   r   r	  r   rO  rD   rD   rE   r  V     z!TestInheritedModels.test_get_rootc                 C   B   |j jdd}|j jdd}| jdksJ | d u sJ d S rR  )rm   r   r  r   rO  rD   rD   rE   r  \     z#TestInheritedModels.test_get_parentc                 C   X   |j jdd}|j jdd}dd | D ddgksJ dd | D g ks*J d S )	Nr   r   r&   c                 S   r   rD   r   r   rD   rD   rE   ri   e  r   z9TestInheritedModels.test_get_children.<locals>.<listcomp>r@  rA  c                 S   r   rD   r   r   rD   rD   rE   ri   f  r   )rm   r   r  rO  rD   rD   rE   r  b     z%TestInheritedModels.test_get_childrenc                 C   @   |j jdd}|j jdd}| dksJ | dksJ d S Nr   r   r&   r/   r   r  rO  rD   rD   rE   r  h  rP  z+TestInheritedModels.test_get_children_countc                 C   s\   |j jdd}|j jdd}dd | D ddgksJ dd | D g dks,J d S )	Nr   r   r&   c                 S   r   rD   r   r   rD   rD   rE   ri   q  r   z9TestInheritedModels.test_get_siblings.<locals>.<listcomp>r    c                 S   r   rD   r   r   rD   rD   rE   ri   r  r   rI  )rm   r   r  rO  rD   rD   rE   r  n  s   "z%TestInheritedModels.test_get_siblingsc                 C   sD   |j jdd}|j jdd}| jdksJ | jdks J d S )Nr   r   r&   r   )rm   r   r!  r   rO  rD   rD   rE   r"  t  rS  z*TestInheritedModels.test_get_first_siblingc                 C   sB   |j jdd}|j jdd}| d u sJ | jdksJ d S rR  )rm   r   r&  r   rO  rD   rD   rE   r'  z  r|  z)TestInheritedModels.test_get_prev_siblingc                 C   rT  Nr   r   r&   r    )rm   r   r*  r   rO  rD   rD   rE   r+    rU  z)TestInheritedModels.test_get_next_siblingc                 C   rQ  rZ  )rm   r   r,  r   rO  rD   rD   rE   r-    rS  z)TestInheritedModels.test_get_last_siblingc                 C   rT  )Nr   r   r&   r@  )rm   r   r/  r   rO  rD   rD   rE   r0    rU  z(TestInheritedModels.test_get_first_childc                 C   rT  )Nr   r   r&   rA  )rm   r   r2  r   rO  rD   rD   rE   r3    rU  z'TestInheritedModels.test_get_last_childc                 C   sV   |j jdd}|j jdd}dd | D dgksJ dd | D g ks)J d S )Nr   r   r&   c                 S   r   rD   r   r   rD   rD   rE   ri     r   z:TestInheritedModels.test_get_ancestors.<locals>.<listcomp>r   c                 S   r   rD   r   r   rD   rD   rE   ri     r   )rm   r   r4  rO  rD   rD   rE   r6    s   z&TestInheritedModels.test_get_ancestorsc                 C   rV  )	Nr   r   r&   c                 S   r   rD   r   r   rD   rD   rE   ri     r   z<TestInheritedModels.test_get_descendants.<locals>.<listcomp>r@  rA  c                 S   r   rD   r   r   rD   rD   rE   ri     r   )rm   r   r7  rO  rD   rD   rE   r8    rW  z(TestInheritedModels.test_get_descendantsc                 C   rX  rY  r;  rO  rD   rD   rE   r=    rP  z-TestInheritedModels.test_get_descendant_countc                 C   sn   |j d }|jjdd}|  |jjdd}dD ]}|jj|d r&J qdd | D dgks5J d S )	Nr   r   r   r   )r   r@  rA  c                 S   r   rD   r   r   rD   rD   rE   ri     r   z?TestInheritedModels.test_cascading_deletion.<locals>.<listcomp>r    )	__bases__rm   r   r   r   existsr7  )rw   rP   r  rB  rE  r   rD   rD   rE   test_cascading_deletion  s   
 z+TestInheritedModels.test_cascading_deletionN)!r   r   r   r  r   r  r  r   r  INHERITED_MODELSrP   r   r   r   r   r   r   r   r  r  r  r  r  r"  r'  r+  r-  r0  r3  r6  r8  r=  r]  rD   rD   rD   rE   r?    s<    r?  c                   @   s.   e Zd Zejjedd dddd ZdS )TestMP_TreeAlphabetTREEBEARD_TEST_ALPHABETFz-TREEBEARD_TEST_ALPHABET env variable not set.)reasonc           	         s  t j}d}d}tdt|d D ]q}|d|  t dks J  fdd dd D }| fdd D  | d	  d   |j    |_	d|_
tt d	 D ]}z|j|d
 W qY   d}Y  |ro ndd |j D }||kr n }qJ d|t|)z:This isn't actually a test, it's an informational routine.FNr3   r+   r   c                       g | ]} d  | qS r   rD   rg   charalphabetrD   rE   ri     r   z5TestMP_TreeAlphabet.test_alphabet.<locals>.<listcomp>c                    rb  )r+   rD   rc  re  rD   rE   ri     r   r/   )numvalTc                 S   r   rD   pathr   rD   rD   rE   ri     r   z7Best BASE85 based alphabet for your setup: {} (base {}))r   BASE85rt   rr   rp   rZ   rm   r   r   rf  numconv_obj_r   format)	rw   rS   	basealphagot_err	last_goodalphabetlenr   posr{   rD   re  rE   test_alphabet  s6   z!TestMP_TreeAlphabet.test_alphabetN)	r   r   r   r   markskipifosgetenvrr  rD   rD   rD   rE   r_    s    r_  c                   @   s>   e Zd Zeejdejej ddd Z	dd Z
dd Zd	S )
TestHelpersr8   r9   c                 C   s:   | j }|t | D ]}|t| q|jdd |S )Nr   r   )r?   r@   rA   r   r   )rC   rF   r   rD   rD   rE   helpers_model  s   
zTestHelpers.helpers_modelc                 C   s4   dd |  D }dd | D }||ksJ d S )Nc                 S      g | ]	}|j | fqS rD   r   r<  rf   rD   rD   rE   ri     s    zATestHelpers.test_descendants_group_count_root.<locals>.<listcomp>c                 S      g | ]}|j |jfqS rD   r   descendants_countrf   rD   rD   rE   ri         
)r   get_descendants_group_count)rw   rx  r   r{   rD   rD   rE   !test_descendants_group_count_root  s   z-TestHelpers.test_descendants_group_count_rootc                 C   sF   |  jdd}dd | D }dd ||D }||ks!J d S )Nr   r   c                 S   ry  rD   rz  rf   rD   rD   rE   ri     s    zATestHelpers.test_descendants_group_count_node.<locals>.<listcomp>c                 S   r{  rD   r|  rf   rD   rD   rE   ri     r~  )r   r   r  r  )rw   rx  r   r   r{   rD   rD   rE   !test_descendants_group_count_node  s   z-TestHelpers.test_descendants_group_count_nodeN)r   r   r   r  r   r  r   r  PROXY_MODELSrx  r  r  rD   rD   rD   rE   rw    s    
rw  c                   @   s    e Zd ZdZdd Zdd ZdS )TestMP_TreeSortedAutoNowz~
    The sorting mechanism used by treebeard when adding a node can fail if the
    ordering is using an "auto_now" field
    c                 C   s.   t ddD ]}|jd|f tj d qd S )Nr+   r   znode%d)r   r   )rt   r   datetimenow)rw   rT   irD   rD   rE   !test_sorted_by_autonow_workaround
  s
   z:TestMP_TreeSortedAutoNow.test_sorted_by_autonow_workaroundc                 C   sH   |j dd tt |j dd W d   dS 1 sw   Y  dS )zU
        This test asserts that we have a problem.
        fix this, somehow
        rD  r   rE  N)r   r   r   
ValueError)rw   rT   rD   rD   rE   test_sorted_by_autonow_FAIL  s   "z4TestMP_TreeSortedAutoNow.test_sorted_by_autonow_FAILN)r   r   r   __doc__r  r  rD   rD   rD   rE   r    s    r  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestMP_TreeStepOverflowc                 C   sR   |j }tddD ]}|  qtt |  W d    d S 1 s"w   Y  d S Nr+   r  )r   rt   r   r   r   )rw   rU   methodr  rD   rD   rE   r     s   "z%TestMP_TreeStepOverflow.test_add_rootc                 C   sZ   |  }|j}tddD ]}|  qtt |  W d    d S 1 s&w   Y  d S r  )r   rW  rt   r   r   r   )rw   rU   r,  r  r  rD   rD   rE   test_add_child$  s   "z&TestMP_TreeStepOverflow.test_add_childc              	   C   sj   |  }tddD ]}|  q	d}|D ]}tt | | W d    n1 s-w   Y  qd S )Nr+   r  r  r  r  ry  )r   rt   rW  r   r   r   r2  rr  )rw   rU   r,  r  	positionsrq  rD   rD   rE   test_add_sibling,  s   
z(TestMP_TreeStepOverflow.test_add_siblingc           	   
   C   s   |  }tddD ]}|  q	|  }|ddgf| g dfg}|D ]$\}}|D ]}tt ||| W d    n1 sBw   Y  q*q$d S )Nr+   r  r  r  r  )r   rt   rW  r/  r   r   r   r  )	rw   rU   r,  r  newroottargetsr  r  rq  rD   rD   rE   	test_move5  s"   

z!TestMP_TreeStepOverflow.test_moveN)r   r   r   r   r  r  r  rD   rD   rD   rE   r    s
    	r  c                   @   s   e Zd ZdZdd ZdS )TestMP_TreeShortPathzSTest a tree with a very small path field (max_length=4) and a
    steplen of 1
    c                 C   sP   |  }|   }tt |  W d    d S 1 s!w   Y  d S r=   )r   rW  r   r   r   )rw   rR   r   rD   rD   rE   test_short_pathM  s
   
"z$TestMP_TreeShortPath.test_short_pathN)r   r   r   r  r  rD   rD   rD   rE   r  G  s    r  c                   @   r  )TestMP_TreeFindProblemsc                    s|  d _  ddddd   ddddd   ddddd   ddddd   d	dddd   d
dddd   ddddd   ddddd   ddddd   ddddd   ddddd   ddddd   fdd}  \}}}}}dd	g||ksJ ddg||ksJ d
dg||ksJ g d||ksJ ddg||ksJ d S )N0123401r+   r   )ri  depthnumchildrg  r   111abcdzqa#$%!0201r/   020201r3   030301030102r  040401r  c                    s   dd  j j| dD S )Nc                 S   r   rD   rh  rf   rD   rD   rE   ri   f  r   zKTestMP_TreeFindProblems.test_find_problems.<locals>.got.<locals>.<listcomp>r   )rm   r   )r   rS   rD   rE   r{   e  r   z7TestMP_TreeFindProblems.test_find_problems.<locals>.got)r  r  r  )rf  r  find_problems)rw   rS   r{   
evil_charsbad_steplenorphanswrong_depthwrong_numchildrD   r  rE   test_find_problemsV  s4   	z*TestMP_TreeFindProblems.test_find_problemsN)r   r   r   r  rD   rD   rD   rE   r  T  r  r  c                   @   sd   e Zd Zejg dejg diZejg dejg diZdd Zdd Z	dd	 Z
d
d Zdd ZdS )TestMP_TreeFix)r   br+   r/   )11ur/   r+   )r  r  r3   r+   )1111er-   r   )12rh   r/   r   r   rx   r+   r   r&   gr+   r   r'   r0  r+   r-   r(   r0  r/   r   42r0  r/   r   43r  r/   r+   )431r  r3   r+   )4311r  r-   r   44rh   r/   r   ))r   r0  r+   r-   )r  r0  r/   r   )r  r0  r/   r   )13rh   r/   r   )14r  r/   r+   )141r  r3   r+   )1411r  r-   r   )r   r  r+   r/   )r   rh   r/   r   )r    r  r/   r+   )221r  r3   r+   )2211r  r-   r   )r&   rx   r+   r   )r'   r  r+   r   )r  )r  r  r/   r+   )134r  r3   r+   )1343r  r-   r   )r  rh   r/   r   r  r  r  r  r  r  )434r  r3   r+   )4343r  r-   r   r  c                 C   r  )Nc                 S   s$   g | ]}|j |j| | fqS rD   )ri  r   rd   re   rf   rD   rD   rE   ri     s    z&TestMP_TreeFix.got.<locals>.<listcomp>r  r   rD   rD   rE   r{     r  zTestMP_TreeFix.gotc                 C   s  |ddddd   |ddddd   |d	d
ddd   |ddddd   |ddddd   |ddddd   |ddddd   |dd
ddd   |ddddd   |ddddd   |ddddd   |ddddd   |ddd d!d   |d"dd d#d   d S )$Nr'   r/   r0  )ri  r  r  r   r  i  r   r  r  r-   i  rh   r  iA  i  r  r  r  r  r+   r  r  r  r  r(   r&      iB  r  r   r  r3   r  r   rx   )r  r   rD   rD   rE   add_broken_test_data  s   z#TestMP_TreeFix.add_broken_test_datac                 C   B   |  | |jdd | |}| j| }||ksJ |  d S )NFdestructive)r  fix_treer{   expected_with_holesr  rw   rQ   r{   r   rD   rD   rE   test_fix_tree_non_destructive     


z,TestMP_TreeFix.test_fix_tree_non_destructivec                 C   r  )NTr  r  r  r{   expected_no_holesr  r  rD   rD   rE   test_fix_tree_destructive  r  z(TestMP_TreeFix.test_fix_tree_destructivec                 C   r  )NT)	fix_pathsr  r  rD   rD   rE   test_fix_tree_with_fix_paths  r  z+TestMP_TreeFix.test_fix_tree_with_fix_pathsN)r   r   r   r   MP_TestNodeShortPathMP_TestSortedNodeShortPathr  r  r{   r  r  r  r  rD   rD   rD   rE   r  v  s    


#
#r  c                   @   r  )
TestIssuesc                    s   d }dd   fdd}t jddd}|  |jdd	}|jd
d	 |jdd	} | d
dg  | td
d	d
g  | t|dg  |d
g|| |d
dg|| t jj	dd}|j
| |d
dg|| |d
g|| d S )Nc                 S   s   dd | D |ksJ d S )Nc                 S   r   rD   namerf   rD   rD   rE   ri   	  r   zXTestIssues.test_many_to_many_django_user_anonymous.<locals>.qs_check.<locals>.<listcomp>rD   )qsr   rD   rD   rE   qs_check	  s   zDTestIssues.test_many_to_many_django_user_anonymous.<locals>.qs_checkc                    s(    |  tddt|dB |  d S )Nfirstr  users)r  r   r   )r   r,  userr  rD   rE   qs_check_first_or_user	  s   zRTestIssues.test_many_to_many_django_user_anonymous.<locals>.qs_check_first_or_user	test_userztest@example.com
testpasswdzthe root noder  r  secondr  )username)r   rm   create_userr  r   rW  r  r   r   r   r  add)rw   rV   anonuserobjr  r  r,  r  rD   r  rE   'test_many_to_many_django_user_anonymous  s"   z2TestIssues.test_many_to_many_django_user_anonymousN)r   r   r   r  rD   rD   rD   rE   r    s    r  c                   @   r  )TestMoveNodeFormc                 C      dd |D S )Nc                 S   s*   g | ]\}}}|d d|d  |f fqS )z%s%sz&nbsp;&nbsp;&nbsp;&nbsp;r+   rD   )rg   r   strr  rD   rD   rE   ri   #	  s    z4TestMoveNodeForm._get_nodes_list.<locals>.<listcomp>rD   rw   r   rD   rD   rE   _get_nodes_list"	  s   z TestMoveNodeForm._get_nodes_listc                 C   s<   |j d j}|dd d u sJ |dd |D ksJ d S )N_ref_node_idr   c                 S   s   g | ]
}|d  |d fqS )r   r+   rD   rg   choicerD   rD   rE   ri   *	  r   z=TestMoveNodeForm._assert_nodes_in_choices.<locals>.<listcomp>)fieldschoicespop)rw   formr   r  rD   rD   rE   _assert_nodes_in_choices'	  s   z)TestMoveNodeForm._assert_nodes_in_choicesc                 C   sp   t t|}||d}g dt|j ksJ dd |jd jD }g d|ks+J | |}| || d S )Nr   r   	_positionr  c                 S   r   r   rD   r  rD   rD   rE   ri   0	  r   z6TestMoveNodeForm._move_node_helper.<locals>.<listcomp>r  )r  r  r  )	r   r   rX   base_fieldskeysr  r  r  r  )rw   r   safe_parent_nodes
form_classr  r{   r   rD   rD   rE   _move_node_helper,	  s   

z"TestMoveNodeForm._move_node_helperc                 C   r  )Nc                 S   s    g | ]}|j t|| fqS rD   )r   r  rd   r   rD   rD   rE   ri   6	  r   zBTestMoveNodeForm._get_node_ids_strs_and_depths.<locals>.<listcomp>rD   r  rD   rD   rE   _get_node_ids_strs_and_depths5	  s   z.TestMoveNodeForm._get_node_ids_strs_and_depthsc                 C   s0   t | }|d}| |}| || d S )Nr   )rX   rv   r  r  r  )rw   rF   r   r   r  rD   rD   rE   test_form_root_node8	  s   

z$TestMoveNodeForm.test_form_root_nodec                 C   s.   t | }| |}| }| || d S r=   )rX   rv   r  r  r  )rw   rF   r   r  r   rD   rD   rE   test_form_leaf_node>	  s   
z$TestMoveNodeForm.test_form_leaf_nodec                 C   s   d }t | }| |}|j D ]U}t }t|}t|}|||}	t |	|j	
 }
g d}||
ks8J |	|}
d d|ifg}|
|ksJJ |	||}
|
|ksVJ |	| }| |}| || qd S )Nr  r  )rX   rv   r  rm   r   r   r   r   get_formr  r   get_fieldsetsr  r  )rw   rF   rC   r   r  r   siter  admin_classmar{   desc_pos_refnodeidr   r  rD   rD   rE   test_form_adminD	  s(   



z TestMoveNodeForm.test_form_adminN)
r   r   r   r  r  r  r  r  r  r  rD   rD   rD   rE   r   	  s    	r  c                   @   r  )TestModelAdminc                 C   sD   t  }t|}t|}|||}t|d j g dks J d S )Nr  )r   r   r   rX   r  r  r   )rw   rF   r	  r  r
  r  rD   rD   rE   test_default_fields\	  s
   
$z"TestModelAdmin.test_default_fieldsN)r   r   r   r  rD   rD   rD   rE   r  Z	  r  r  c                   @   r  )TestSortedFormc                 C   s   |j dddd |j dddd |j dddd |j ddd	d |j ddd
d |j ddd	d |j dddd |j dddd t|}| }t|j g dksTJ ||jjddd}t|j g dkskJ dt|v ssJ dt|v s{J d S )Nr3   r  r  r+   r-   r  r/   r   r  r  r   r!  )r  r  r   r  r  r   r   id__positionid__ref_node_id)r   r   rX   r  r   rm   r   r  )rw   rN   r  r  rD   rD   rE   test_sorted_formj	  s   zTestSortedForm.test_sorted_formN)r   r   r   r  rD   rD   rD   rE   r  h	  r  r  c                   @   r  )TestFormc                 C   sz   t |}| }t|j g dksJ ||jjddd}t|j g dks+J dt|v s3J dt|v s;J d S )Nr  r   r   r   r  r  )r   rX   r  r   rm   r   r  )rw   rF   r  r  rD   rD   rE   	test_form	  s   zTestForm.test_formc                 C   sX   t |}|jjddjdd}||d}| }d|v sJ d|vs$J d|v s*J d S )Nr   r   z,Benign<script>alert("Compromised");</script>r   Benignz<script>z&lt;script&gt;)r   rm   r   rW  as_p)rw   rF   r  bad_noder  rendered_htmlrD   rD   rE   test_move_node_form	  s   
zTestForm.test_move_node_formc                 C   s   t |}|jjdd}||d}||dddksJ |jjdd}||d}||d|jjddjdks:J |jjd	d}||d}||d
|jjddjdksXJ |jjdd}||d}||d|jjddjdksvJ d S )Nr   r   r   r  rW   )r  r  r   r   r    r  r"   r!   )r   rm   r   _get_position_ref_noder   )rw   rF   r  instance_parentr  instance_childinstance_grandchildrD   rD   rE   test_get_position_ref_node	  s2   



z#TestForm.test_get_position_ref_nodec                 C   sX   |j jdd}d}d}t|}|||||jdd}| s J | ||fks*J d S )Nr   r   r  rW   r  r  r   r   r   )rm   r   r   r   is_valid_clean_cleaned_data)rw   rF   r  r  r  r  r  rD   rD   rE   test_clean_cleaned_data	  s   z TestForm.test_clean_cleaned_datac                 C   s,  |j jdd}t|j  }t|}||d|j jddj|jdd}| s)J | }||j  	 ks8J |
 dks@J | dksHJ | rNJ | sTJ t|}||dd	|jdd}| siJ | }||j  	 ksxJ |
 dksJ | d
ksJ | sJ | sJ d S )Nr   r   r  r   r   r!  r   r/   rW   r+   )rm   r   rr   r   r   r   r   r"  r  r  re   rd   r   r   )rw   rF   r  original_countr  r  saved_instancerestored_instancerD   rD   rE   test_save_edit	  s@   zTestForm.test_save_editc                 C   sl   |j   }|dksJ d}t|}||ddd}| s!J | d us)J ||j   k s4J d S )Nr  r  New Form Testr  r   r   )rm   r   r  r   r"  r  rw   rF   r%  r  r  r  rD   rD   rE   test_save_new	  s   zTestForm.test_save_newc                 C   sv   |j   }|dksJ d}t|}||dddd}| s"J d|j_| dus.J ||j   k s9J dS )rb  r  r  rc  r)  )r  idr   r+  N)rm   r   r  r   r"  r   r.  r  r,  rD   rD   rE   test_save_new_with_pk_set
  s   
z"TestForm.test_save_new_with_pk_setc                 C   sF   t |}|dddd}| sJ d|j_| }|jdks!J d S )Nr  zTest Instancer*  r+  zModified Instance)r   r"  r   r   r  )rw   rF   r  r  r   rD   rD   rE   test_save_instance
  s   zTestForm.test_save_instanceN)r   r   r   r  r  r  r$  r(  r-  r/  r0  rD   rD   rD   rE   r  	  s    
&
r  c                   @   s,   e Zd ZedZdd Zdd Zdd ZdS )	TestAdminTreezR{% load admin_tree %}{% spaceless %}{% result_tree cl request %}{% endspaceless %}c                 C   s  |}t  d}t |_t }t|}t|}|||}||}|||}	t	t
||||	|j|j|j|j|j|j|j|g  }
d|
_t|
|d}| j|}d}|||j ks^J |j D ]}|
|}d|t|f }||v sxJ qcd|v sJ dS )z
        Verifies that inclusion tag result_list generates a table when with
        default ModelAdmin settings.
        /admin/tree/NclrC   1<td class="drag-handler"><span>&nbsp;</span></td><a href="%s">%s</a>1<input type="hidden" id="has-filters" value="0"/>)r   r   r   r  r   r   r   get_list_displayget_list_display_linksr   r]   list_filterdate_hierarchysearch_fieldslist_select_relatedlist_per_pagelist_max_show_alllist_editableformsetr   templaterenderr  rm   r   url_for_resultr  )rw   rL   rF   rC   r	  r  r
  mlist_displaylist_display_linksr5  contexttable_outputdrag_handlerobjecturlr   rD   rD   rE   test_result_tree&
  sD   


zTestAdminTree.test_result_treec                 C   s  |}|j dd t d}t |_t }t|}t|}G dd d|}|||}||}	|	||	}
t
t|||	|
|j|j|j|j|j|j|j|g  }d|_t||d}| j|}d}|||j kslJ |j D ]}||}d	||jf }||v sJ qqd
|v sJ dS )r2  u
   áéîøür   r3  c                   @   s   e Zd ZdZdS )zATestAdminTree.test_unicode_result_tree.<locals>.UnicodeModelAdmin)__str__r   N)r   r   r   rG  rD   rD   rD   rE   UnicodeModelAdmin_
  s    rP  Nr4  r6  r7  r8  )r   r   r   r   r  r   r   r   r9  r:  r   r]   r;  r<  r=  r>  r?  r@  rA  rB  r   rC  rD  r  rm   r   rE  r   )rw   rM   rF   rC   r	  r  
ModelAdminrP  rF  rG  rH  r5  rI  rJ  rK  rL  rM  r   rD   rD   rE   test_unicode_result_treeQ
  sH   


z&TestAdminTree.test_unicode_result_treec                 C   s  |}t  d}t |_t }t|}t|}|||}||}|||}	t	t
||||	|j|j|j|j|j|j|j|g  }
d|
_t|
|d}| j|}d|v sVJ t  d}t |_||}|||}	t	t
||||	|j|j|j|j|j|j|j|g  }
d|
_t|
|d}| j|}d|v sJ t  d}t |_||}|||}	t	t
||||	|j|j|j|j|j|j|j|g  }
d|
_t|
|d}| j|}d|v sJ dS )z1Test template changes with filters or pagination.z/admin/tree/?desc=1Nr4  z1<input type="hidden" id="has-filters" value="1"/>z/admin/tree/?p=1r8  z/admin/tree/?all=1)r   r   r   r  r   r   r   r9  r:  r   r]   r;  r<  r=  r>  r?  r@  rA  rB  r   rC  rD  )rw   rL   rF   rC   r	  r  r
  rF  rG  rH  r5  rI  rJ  rD   rD   rE   test_result_filtered
  s   



z"TestAdminTree.test_result_filteredN)r   r   r   r
   rC  rN  rR  rS  rD   rD   rD   rE   r1  
  s    +1r1  c                   @   s4   e Zd ZedZdd Zdd Zdd Zdd	 Zd
S )TestAdminTreeListzW{% load admin_tree_list %}{% spaceless %}{% result_tree cl request %}{% endspaceless %}c                 C   s   |}t  d}t |_t }t|}t|}|||}||}|||}	t	t
||||	|j|j|j|j|j|j|j|g  }
d|
_t|
|d}| j|}d}|j D ]}||jt|f }||v shJ qWdS )r2  r3  Nr4  z<li><a href="%s/" >%s</a>r   r   r   r  r   r   r   r9  r:  r   r]   r;  r<  r=  r>  r?  r@  rA  rB  r   rC  rD  rm   r   r   r  rw   rL   rF   rC   r	  r  r
  rF  rG  rH  r5  rI  rJ  output_templaterL  expected_outputrD   rD   rE   test_result_tree_list
  s@   

z'TestAdminTreeList.test_result_tree_listc                 C   s   |}t  d}t |_t }t|}t|}|||}||}|||}	t	t
||||	|j|j|j|j|j|j|j|g  }
d |
_t|
|dd}| j|}d}|j D ]}||j|jt|f }||v skJ qXd S )Nr3  T)r5  rC   action_formzg<input type="checkbox" class="action-select" value="%s" name="_selected_action" /><a href="%s/" >%s</a>rU  rV  rD   rD   rE   !test_result_tree_list_with_action  sB   

z3TestAdminTreeList.test_result_tree_list_with_actionc                 C   s   |}|j jj}t dt|}t |_t	 }t
| t|}t|}|||}||}	|||	}
tt|||	|
|j|j|j|j|j|j|j|g  }d |_t||d}| j|}d}|j D ]}||j }||v sqJ qdd S )Nz/admin/tree/?{0}={1}r4  z/opener.dismissRelatedLookupPopup(window, '%s');)r  r   attnamer   r   rl  r   r   r  r   admin_register_allr   r   r9  r:  r   r]   r;  r<  r=  r>  r?  r@  rA  rB  r   rC  rD  rm   r   )rw   rL   rF   pk_fieldrC   r	  r  r
  rF  rG  rH  r5  rI  rJ  rW  rL  rX  rD   rD   rE   test_result_tree_list_with_get*  sH   




z0TestAdminTreeList.test_result_tree_list_with_getc                 C   s   |j dd}t d}t |_t }t|}t|}|||}||}|	||}	t
t||||	|j|j|j|j|j|j|j|g  }
d|
_t|
|d}| j|}d|j d}||v saJ dS )r2  z<>r   r3  Nr4  z<li><a href="z/" >&lt;&gt;</a>)r   r   r   r   r  r   r   r   r9  r:  r   r]   r;  r<  r=  r>  r?  r@  rA  rB  r   rC  rD  r   )rw   rM   rL  rC   r	  r  r
  rF  rG  rH  r5  rI  rJ  rX  rD   rD   rE   $test_result_tree_list_escapes_labelsP  s:   

z6TestAdminTreeList.test_result_tree_list_escapes_labelsN)	r   r   r   r
   rC  rY  r[  r_  r`  rD   rD   rD   rE   rT  
  s    %&&rT  c                   @   sz   e Zd Ze 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 )TestTreeAdminc                 C   s   t jj|ddS )NT)r  is_superuser)r   rm   create)rw   r  rD   rD   rE   _create_superuserx  s   zTestTreeAdmin._create_superuserc                 C   s   t  }||}||_|S r=   )r   r   r  )rw   rM  r  request_factoryrC   rD   rD   rE   _mocked_authenticated_request{  s   
z+TestTreeAdmin._mocked_authenticated_requestc                 C   s8   t  }|jd|d}t|dd t|}t|d| |S )N/r+  session	_messages)r   postsetattrr   )rw   r   re  rC   messagesrD   rD   rE   _mocked_request  s   zTestTreeAdmin._mocked_requestc                 C   s   t |}t|}||| jS r=   )r   r   r	  )rw   model_classr  r
  rD   rD   rE   _get_admin_obj  s   zTestTreeAdmin._get_admin_objc                 C   sb   |  d}| d|}| tj}|| |jdksJ | tj}|| |jdks/J d S )Nchangelist_tmprg  zadmin/tree_list.html)rd  rf  ro  r   AL_TestNodechangelist_viewchange_list_templateMP_TestNode)rw   tmp_userrC   	admin_objrD   rD   rE   test_changelist_view  s   


z"TestTreeAdmin.test_changelist_viewc                 C   s0   |  |}|jjdd}||j|ksJ d S )Nr   r   )ro  rm   r   r7  r   )rw   rF   rv  r  rD   rD   rE   test_get_node  s   
zTestTreeAdmin.test_get_nodec                 C   sZ   |  |}| ji d}||}|jdksJ | jddid}||}|jdks+J d S )Nr+    r.  r+   ro  rm  	move_nodestatus_coderw   rF   rv  rC   responserD   rD   rE    test_move_node_validate_keyerror  s   


z.TestTreeAdmin.test_move_node_validate_keyerrorc                 C   s:   |  |}| jddddd}||}|jdksJ d S )Nr+   r/   invalidr.  
sibling_idas_childr+  ry  rz  r}  rD   rD   rE   "test_move_node_validate_valueerror  s   


z0TestTreeAdmin.test_move_node_validate_valueerrorc                 C   sl   |j jdd}| |}| ji d}|jd|d||d}|jdks#J |jd|d||d}|jdks4J d S )	Nr"   r   r+  Tr  r  ry  rt  rm   r   ro  rm  try_to_move_noder|  rw   rF   r   rv  rC   r~  rD   rD   rE   &test_move_validate_missing_nodeorderby  s   


z4TestTreeAdmin.test_move_validate_missing_nodeorderbyc                 C   sJ   |j jdd}| |}| ji d}|jd|d||d}|jdks#J d S )Nr"   r   r+  Trq  r  ry  r  r  rD   rD   rE   test_move_validate_invalid_pos  s   

z,TestTreeAdmin.test_move_validate_invalid_posc                 C   sV   |j jdd}|j jdd}| |}| ji d}|d|d||}|jdks)J d S )Nr   r   r"   r+  Tr  ry  r  )rw   rF   r   r  rv  rC   r~  rD   rD   rE    test_move_validate_to_descendant  s   

z.TestTreeAdmin.test_move_validate_to_descendantc                 C   t   |j jdd}|j jdd}| |}| j|j|jddd}||}|jdks+J g d}| ||ks8J d S )	Nr"   r   r   r   r  r+     r  rm   r   ro  rm  r   r{  r|  r{   rw   rF   r   r  rv  rC   r~  r   rD   rD   rE   test_move_left     

zTestTreeAdmin.test_move_leftc                 C   r  )	Nr"   r   r   r+   r  r+  r  r  r  r  rD   rD   rE   test_move_last_child  r  z"TestTreeAdmin.test_move_last_childN)r   r   r   r   r	  rd  rf  rm  ro  rw  rx  r  r  r  r  r  r  r  rD   rD   rD   rE   ra  t  s    		
ra  c                   @   r  )TestMPFormPerformancec                 C   sb   t j}|t t|}| }|t| d  || W d    d S 1 s*w   Y  d S rj  )r   rt  r@   rA   r   rr   r   mk_dropdown_tree)rw   django_assert_num_queriesrF   r  r  rD   rD   rE   #test_form_add_subtree_no_of_queries  s   
"z9TestMPFormPerformance.test_form_add_subtree_no_of_queriesN)r   r   r   r  rD   rD   rD   rE   r    r  r  c                   @   r  )!TestMP_TreeDescendantsPerformancec              	   C   sl   t j}|t g d}|D ]%\}}|jj|d}|| t|  W d    n1 s.w   Y  qd S )N))r   r+   r  r  r9  r:  r   )r   rt  r@   rA   rm   r   rX   r7  )rw   r  rF   r   r   r   r   rD   rD   rE   "test_get_descendants_no_of_queries  s   

zDTestMP_TreeDescendantsPerformance.test_get_descendants_no_of_queriesN)r   r   r   r  rD   rD   rD   rE   r    r  r  )sr  r  ru  django.contrib.admin.sitesr   django.contrib.admin.views.mainr   django.contrib.auth.modelsr   r   (django.contrib.messages.storage.fallbackr   django.db.modelsr   django.db.models.signalsr   django.dispatchr	   django.templater
   r   django.testr   django.test.clientr   django.templatetags.staticr   django.contrib.admin.optionsr   djangor   rY   r   	treebeardr   treebeard.adminr   treebeard.exceptionsr   r   r   r   r   treebeard.formsr   treebeard.testsr   treebeard.tests.adminr   r]  rA   r   r  r  r  rF   rJ   rL   UNICODE_MODELSrM   SORTED_MODELSrN   RELATED_MODELSrO   r^  rP   MP_SHORTPATH_MODELSrQ   r  rR   MP_TestNodeAlphabetrS   MP_TestNodeSortedAutoNowrT   MP_TestNodeSmallSteprU   MP_TestManyToManyWithUserrV   r]   r^   rs  	django_dbr   r   r   r   rR  ro  r  r  r  r  r  r  r  r  r?  r_  rw  r  r  r  r  r  r  r  r  r  r  r1  rT  ra  rL  r  r  rD   rD   rD   rE   <module>   s"   



















/ L  V m^hm    1*+!v29!  9  
