
    BhJ                        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mZ d
Z G d dej"                        Zej                  j'                  eed      Zej                  j+                  eed      Z G d d      Z ed       G d dee             Z ed       G d dee             Z ed       G d de             Z G d de      Z G d de      Z G d d e      Z G d! d"e      Zy)#    N)forms)User)TestCaseoverride_settings)RequestFactory)CookieWizardView   )temp_storage)PoemPoetztests.pyc                        e Zd Z G d d      Zy)UserFormc                       e Zd ZeZdZy)UserForm.Meta__all__N)__name__
__module____qualname__r   modelfields     N/home/dcms/DCMS/lib/python3.12/site-packages/tests/wizard/wizardtests/tests.pyMetar      s    r   r   N)r   r   r   r   r   r   r   r   r      s     r   r      )formextrar   )r   c                   T    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)WizardTestsc                     t         j                  j                  d      \  | _        }t	        j
                  | j                        | _        | j                  j                  | j                  d   d<   y N	testuser1)usernamer   z
form1-user)r   objectsget_or_createtestusercopydeepcopywizard_step_datapkselfcreateds     r   setUpzWizardTests.setUp   sV    !%!;!;[!;!Qw $d.C.C D151A1Aa .r   c                 h    t        j                  d      d   D ]  }t        j                  |        y )N r	   )r
   listdirdelete)r,   files     r   tearDownzWizardTests.tearDown"   s1     !((,Q/ 	&D%	&r   c                 V   | j                   j                  | j                        }|j                  d   }| j	                  |j
                  d       | j	                  |d   j                  d       | j	                  |d   j                  d       | j	                  |d   j                  d       | j	                  |d   j                  d       | j	                  |d   j                  d        | j	                  |d   j                  d       | j	                  |d   j                  d	       y )
Nwizard   stepsform1r   r	   form4form2   )clientget
wizard_urlcontextassertEqualstatus_codecurrentstep0step1lastprevnextcountr,   responser6   s      r   test_initial_callzWizardTests.test_initial_call,   s    ;;??4??3!!(+--s300':..2..2--w7--t4--w7..2r   c                 V   | j                   j                  | j                  | j                        }| j	                  |j
                  d       | j	                  |j                  d   d   j                  d       | j	                  |j                  d   d   j                  dgdgd       y )Nr7   r6   r8   r9   r   zThis field is required.)nameuser)	r=   postr?   wizard_step_1_datarA   rB   r@   rC   errorsr,   rK   s     r   test_form_post_errorz WizardTests.test_form_post_error8   s    ;;##DOOT5L5LM--s3))(3G<DDgN))(3F;BB#<"=#<"=?	@r   c                    | j                   d   j                         }t        |j                               D ]
  }d|v s||=  | j                  j                  | j                  |      }| j                  |j                  d       y )Nr   current_stepi  )	r)   r'   listkeysr=   rP   r?   rA   rB   )r,   r)   keyrK   s       r    test_form_post_mgmt_data_missingz,WizardTests.test_form_post_mgmt_data_missing@   s    00388: (--/0 	*C$$S)	* ;;##DOO5EF--s3r   c                    | j                   j                  | j                  | j                  d         }|j                  d   }| j                  |j                  d       | j                  |d   j                  d       | j                  |d   j                  d       | j                  |d   j                  d       | j                  |d   j                  d       y )	Nr   r6   r7   r8   r;   r	   r9   form3)r=   rP   r?   r)   r@   rA   rB   rC   rD   rG   rH   rJ   s      r   test_form_post_successz"WizardTests.test_form_post_successL   s    ;;##DOOT5J5J15MN!!(+--s300':..2--w7--w7r   c                    | j                   j                  | j                        }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                   j                  | j                  d|j
                  d   d   j                  i      }| j                  |j                  d       | j                  |j
                  d   d   j                  d       y )Nr7   r6   r8   r9   r   r;   wizard_goto_step)
r=   r>   r?   rA   rB   r@   rC   rP   r)   rG   rS   s     r   test_form_stepbackzWizardTests.test_form_stepbackU   s-   ;;??4??3--s3))(3G<DDgN;;##DOOT5J5J15MN--s3))(3G<DDgN;;##DOO 0 0 :7 C H H6J K--s3))(3G<DDgNr   c                    | j                   j                  | j                        }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                  |j
                  j                  dd       d        | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                  |j
                  j                  dd       d       |j                  d   d	   }| j                  |j                  d	   |       y )
Nr7   r6   r8   r9   another_varr   r;   Tr   )
r=   r>   r?   rA   rB   r@   rC   rP   r)   context_data)r,   rK   r   s      r   test_template_contextz!WizardTests.test_template_contextc   s-   ;;??4??3--s3))(3G<DDgN))--mTBDI;;##DOOT5J5J15MN--s3))(3G<DDgN))--mTBDI $$X.v6..v6=r   c           	         | j                   j                  | j                        }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                  d   }t        t        d      5 }||d	<   | j                   j                  | j                  |      }d d d        | j                  |j                  d       | j                  |j
                  d   d   j                  d
       t        t        d      5 }t        j                  t              5 }| j                  |j                         |j                                d d d        d d d        | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  t        j                  t                     |j
                  d   }|d   d= | j                  |dd| j                   ddddddiddiddigg       y # 1 sw Y   xY w# 1 sw Y   VxY w# 1 sw Y   [xY w)Nr7   r6   r8   r9   r   r;   r	   rbform2-file1r\   r   r:      	form_listfile1PonyT)rN   thirstyrO   123 Main St
Djangoland)address1address2random_crap	blah blah)r=   r>   r?   rA   rB   r@   rC   rP   r)   open__file__r
   UPLOADED_FILE_NAMEreadassertFalseexistsr&   )r,   rK   	post_data	post_fileff2all_datas          r   test_form_finishzWizardTests.test_form_finishr   s   ;;??4??3--s3))(3G<DDgN;;##DOOT5J5J15MN--s3))(3G<DDgN))!,	(D! 	DY'0Im${{''CH	D 	--s3))(3G<DDgN (D! 	2Q(9(9:L(M 	2QSQVVXrwwy1	2 	2 ;;##DOOT5J5J15MN--s3))(3G<DDgN;;##DOOT5J5J15MN--s3 	,,-?@A##K0QK dmmD&LAK([)[)+	$, 	--	D 	D	2 	2 	2 	2s0   ,L$L>./L1L>$L.1L;	6L>>Mc                    | j                   j                  | j                        }| j                  |j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  d   }t        t        d      5 }||d<   | j                   j                  | j                  |      }d d d        | j                  |j                  d       | j                  t        j                  t                     | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       |j                  d   }| j                  |d	   j                  t               | j                  |d	   j                         | j!                  t        j                  t                     |d	= | j                  |d
d| j"                  dddddiddigd       y # 1 sw Y   xY w)Nr7   r   r	   rf   rg   r   rh   all_cleaned_datarj   rk   Trm   rn   rr   rq   )rN   rl   rO   ro   rp   rq   zformset-form4)r=   r>   r?   rA   rB   rP   r)   rs   rt   
assertTruer
   rx   ru   r@   rN   closedrw   r&   )r,   rK   ry   rz   r}   s        r   test_cleaned_datazWizardTests.test_cleaned_data   s   ;;??4??3--s3;;##DOOT5J5J15MN--s3))!,	(D! 	DY'0Im${{''CH	D 	--s3++,>?@;;##DOOT5J5J15MN--s3;;##DOOT5J5J15MN--s3##$67'*//1CD)001,,-?@AWtT]]%<&,,:.$/ 	0#	D 	Ds   0,I,,I6c                 H   | j                   j                  | j                        }| j                  |j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  d   }t        t        d      5 }||d<   | j                   j                  | j                  |      }d d d        | j                  |j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                   j                  j                  dd        | j                   j                  j                  dd        | j                   j                  | j                  | j                  d	         }| j                  |j                  d       | j                  |j                  d
   d   j                  d       y # 1 sw Y   =xY w)Nr7   r   r	   rf   rg   r   	sessionidwizard_cookie_contact_wizardrh   r6   r8   r9   )r=   r>   r?   rA   rB   rP   r)   rs   rt   cookiespopr@   rC   r,   rK   ry   rz   s       r   test_manipulated_dataz!WizardTests.test_manipulated_data   s   ;;??4??3--s3;;##DOOT5J5J15MN--s3))!,	(D! 	DY'0Im${{''CH	D 	--s3;;##DOOT5J5J15MN--s3T2 >E;;##DOOT5J5J15MN--s3))(3G<DDgN	D 	Ds   0,HH!c                    | j                   j                  | j                        }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                  d   }t        t        d      5 }||d	<   | j                   j                  | j                  |      }d d d        | j                  |j                  d       | j                  |j
                  d   d   j                  d
       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       | j                  |j
                  d   d   j                  d       | j                   j                  | j                  | j                  d         }| j                  |j                  d       y # 1 sw Y   xY w)Nr7   r6   r8   r9   r   r;   r	   rf   rg   r\   r   r:   rh   )r=   r>   r?   rA   rB   r@   rC   rP   r)   rs   rt   r   s       r   test_form_refreshzWizardTests.test_form_refresh   s   ;;??4??3--s3))(3G<DDgN;;##DOOT5J5J15MN--s3))(3G<DDgN;;##DOOT5J5J15MN--s3))(3G<DDgN))!,	(D! 	DY'0Im${{''CH	D 	--s3))(3G<DDgN;;##DOOT5J5J15MN--s3))(3G<DDgN;;##DOOT5J5J15MN--s3))(3G<DDgN;;##DOOT5J5J15MN--s3	D 	Ds   ,MMN)r   r   r   r.   r4   rL   rT   rZ   r]   r`   rd   r~   r   r   r   r   r   r   r   r      sD    B&
3@
48O>%-N0@O,4r   r   ztests.wizard.wizardtests.urls)ROOT_URLCONFc            
       H    e Zd ZdZddiZddddddd	d
ddddddddddfZy)SessionWizardTestsz/wiz_session/#session_contact_wizard-current_stepr9   rk   2)
form1-nameform1-thirstyr   rm   rn   r;   )form2-address1form2-address2r   rr   r\   )form3-random_crapr   0r:   )form4-INITIAL_FORMSform4-TOTAL_FORMSform4-MAX_NUM_FORMSform4-0-random_crapform4-1-random_crapr   Nr   r   r   r?   rQ   r)   r   r   r   r   r      sb     J-w
 ! 3:	
 ,*3:	
 "-3:	

 $'!$#&#.#.3:	
r   r   c            
       H    e Zd ZdZddiZddddddd	d
ddddddddddfZy)CookieWizardTestsz/wiz_cookie/"cookie_contact_wizard-current_stepr9   rk   r   r   r   r   rm   rn   r;   r   r   r   rr   r\   r   r   r   r:   r   r   r   r   r   r   Nr   r   r   r   r   r     sb    J,g
 ! 29	
 ,*29	
 "-29	

 $'!$#&#.#.29	
r   r   c            
       T    e Zd ZdZddiZddddddd	d
ddddddddddfZd Zd Zy)WizardTestKwargsz/wiz_other_template/r   r9   rk   r   r   rm   rn   r;   r   rr   r\   r   r   r:   r   c                     t         j                  j                  d      \  | _        }| j                  j                  | j
                  d   d<   y r!   )r   r$   r%   r&   r*   r)   r+   s     r   r.   zWizardTestKwargs.setUpN  s?    !%!;!;[!;!Qw151A1Aa .r   c                 r    | j                   j                  | j                        }| j                  |d       y )Nzother_wizard_form.html)r=   r>   r?   assertTemplateUsedrS   s     r   test_templatezWizardTestKwargs.test_templateR  s)    ;;??4??3*BCr   N)r   r   r   r?   rQ   r)   r.   r   r   r   r   r   r   /  sn    'J,g
 ! 29	
 ,*29	
 "-29	

 $'!$#&#.#.29	
2BDr   r   c                       e Zd Zd Zd Zy)WizardTestGenericViewInterfacec                      G d dt               }t               }|j                  t        j                  g      } ||j                  d            }| j                  |j                  d   d       y )Nc                   "     e Zd ZdZ fdZ xZS )TWizardTestGenericViewInterface.test_get_context_data_inheritance.<locals>.TestWizard
            A subclass that implements ``get_context_data`` using the standard
            protocol for generic views (accept only **kwargs).

            See ticket #17148.
            c                 0    t        |   di |}d|d<   |S N
test_valuetest_keyr   superget_context_datar,   kwargsr@   	__class__s      r   r   zeWizardTestGenericViewInterface.test_get_context_data_inheritance.<locals>.TestWizard.get_context_data`  $    '2<V<&2
#r   r   r   r   __doc__r   __classcell__r   s   @r   
TestWizardr   Y       r   r   /r   r   r   r   as_viewr   Formr>   rA   rc   )r,   r   factoryviewrK   s        r   !test_get_context_data_inheritancez@WizardTestGenericViewInterface.test_get_context_data_inheritanceX  s]    
	) 
	 !"!!5::,/C()..z:LIr   c                 6    G d d      } G d d|t               }t               }|j                  t        j                  g      } ||j                  d            }| j                  |j                  d   d       | j                  |j                  d   d	       y )
Nc                        e Zd Z fdZ xZS )UWizardTestGenericViewInterface.test_get_context_data_with_mixin.<locals>.AnotherMixinc                 0    t        |   di |}d|d<   |S )Nanother_valueanother_keyr   r   r   s      r   r   zfWizardTestGenericViewInterface.test_get_context_data_with_mixin.<locals>.AnotherMixin.get_context_datam  s$    '2<V<)8&r   )r   r   r   r   r   r   s   @r   AnotherMixinr   l  s     r   r   c                   "     e Zd ZdZ fdZ xZS )SWizardTestGenericViewInterface.test_get_context_data_with_mixin.<locals>.TestWizardr   c                 0    t        |   di |}d|d<   |S r   r   r   s      r   r   zdWizardTestGenericViewInterface.test_get_context_data_with_mixin.<locals>.TestWizard.get_context_datay  r   r   r   r   s   @r   r   r   r  r   r   r   r   r   r   r   r   r   )r,   r   r   r   r   rK   s         r    test_get_context_data_with_mixinz?WizardTestGenericViewInterface.test_get_context_data_with_mixink  s    	 	
	'7 
	 !"!!5::,/C()..z:LI..}=Or   N)r   r   r   r   r   r   r   r   r   r   W  s    J&Pr   r   c                       e Zd Zd Zd Zy)WizardTestPrefixc                      G d dt               }t               }|j                  t        j                  g      } ||j                  d            }|j                  d   d   j                  }| j                  |d       y )Nc                       e Zd Zd Zy)4WizardTestPrefix.test_get_prefix.<locals>.TestWizardc                      y)Nsample_prefixr   r,   requestargsr   s       r   
get_prefixz?WizardTestPrefix.test_get_prefix.<locals>.TestWizard.get_prefix  s    &r   Nr   r   r   r   r   r   r   r   r     s    'r   r   r   r6   management_formr   )	r   r   r   r   r   r>   rc   prefixrA   )r,   r   r   r   rK   r   s         r   test_get_prefixz WizardTestPrefix.test_get_prefix  sn    	') 	' !"!!5::,/C()&&x01BCJJ1r   c                     G d dt               }t               }|j                  t        j                  g      }|j                  d      }d|_         ||      }|j                  d   d   j                  }| j                  |d       y )Nc                       e Zd Zd Zy)IWizardTestPrefix.test_get_prefix_using_request_object.<locals>.TestWizardc                     |j                   S N)prefix_valuer   s       r   r   zTWizardTestPrefix.test_get_prefix_using_request_object.<locals>.TestWizard.get_prefix  s    +++r   Nr   r   r   r   r   r     s    ,r   r   r   text_prefixr6   r   )
r   r   r   r   r   r>   r   rc   r   rA   )r,   r   r   r   r   rK   r   s          r   $test_get_prefix_using_request_objectz5WizardTestPrefix.test_get_prefix_using_request_object  sz    	,) 	, !"!!5::,/++c",=&&x01BCJJ/r   N)r   r   r   r   r   r   r   r   r   r     s    
20r   r   c                   *     e Zd Z fdZd Zd Z xZS )WizardFormKwargsOverrideTestsc                     t         |           t               | _        t        j
                  j                  dd      | _        t        j
                  j                  ddd      | _        y )Ntest1znormal@example.com)r#   emailtest2staff@example.comT)r#   r   is_staff)	r   r.   r   rfr   r$   createnormal_user
staff_user)r,   r   s    r   r.   z#WizardFormKwargsOverrideTests.setUp  sT     "  <<..G[.\,,--wFYdh-ir   c                    | j                  dt        j                  j                                t        j                  j	                  | j
                  j                         G fddt              }|j                  t        g      } || j                  j	                  d            }|j                  d   d   }| j                  |j                  j                  d        | j                  |j                  j                  | j
                  j                         | j                  d|j                  j	                  d	d              y )
Nr   r*   c                       e Zd Z fdZy)YWizardFormKwargsOverrideTests.test_instance_is_maintained.<locals>.InstanceOverrideWizardc                     diS )Ninstancer   r,   stepquerysets     r   get_form_kwargsziWizardFormKwargsOverrideTests.test_instance_is_maintained.<locals>.InstanceOverrideWizard.get_form_kwargs      "H--r   Nr   r   r   r   r   s   r   InstanceOverrideWizardr         .r   r  r   r6   r   r   r   )rA   r   r$   rI   r>   r   r*   r   r   r   r   rc   assertNotEqualr   initial)r,   r  r   rK   r   r   s        @r   test_instance_is_maintainedz9WizardFormKwargsOverrideTests.test_instance_is_maintained  s    DLL..01<<##t'9'9#:	.%5 	. &--xj9C()$$X.v6DMM,,d3))4??+=+=>,dll.>.>w.MNr   c           	         t         j                  j                  | j                  j                         G fddt
              }|j                  t        g      } || j                  j                  d            }|j                  d   d   }| j                  |j                  d        | j                  |j                         d       | j                  dgt        |j                  j!                  d	d
                   y )Nr   c                       e Zd Z fdZy)YWizardFormKwargsOverrideTests.test_queryset_is_maintained.<locals>.QuerySetOverrideWizardc                     diS )Nr   r   r   s     r   r   ziWizardFormKwargsOverrideTests.test_queryset_is_maintained.<locals>.QuerySetOverrideWizard.get_form_kwargs  r  r   Nr  r  s   r   QuerySetOverrideWizardr    r  r   r  r   r6   r   r	   r   r   T)flat)r   r$   filterr   r*   r   r   UserFormSetr   r>   rc   r  r   rA   initial_form_countrW   values_list)r,   r  r   rK   formsetr   s        @r   test_queryset_is_maintainedz9WizardFormKwargsOverrideTests.test_queryset_is_maintained  s    <<&&$//*<*<&=	.%5 	. &--{m<C()''1&9G,,d3335q9-.W5E5E5Q5QRY`d5Q5e0fgr   )r   r   r   r.   r  r  r   r   s   @r   r   r     s    jO"hr   r   c                       e Zd Zd Zd Zy)WizardInlineFormSetTestsc                     t               | _        t        j                  j	                  d      | _        | j
                  j                  j	                  d      | _        y )Ntest)rN   z	test poem)r   r   r   r$   r   poetpoem_setpoem)r,   s    r   r.   zWizardInlineFormSetTests.setUp  sD     "LL''V'4	II&&--;-?	r   c                    | j                    G fddt              }|j                  t        g      } || j                  j                  d            }|j                  d   d   }| j                  |j                  | j                          y )Nc                       e Zd ZdZ fdZy)GWizardInlineFormSetTests.test_set_instance.<locals>.InlineFormSetWizardNc                 B    | j                   | _         | j                   S r   )r   )r,   r   r  s     r   get_form_instancezYWizardInlineFormSetTests.test_set_instance.<locals>.InlineFormSetWizard.get_form_instance  s    ==($(DM}}$r   )r   r   r   r   r   )r  s   r   InlineFormSetWizardr    s    H%r   r!  r   r6   r   )	r  r   r   PoemFormSetr   r>   rc   rA   r   )r,   r!  r   rK   r  r  s        @r   test_set_instancez*WizardInlineFormSetTests.test_set_instance  ss    yy	%"2 	% #**K=9C()''1&9))4995r   N)r   r   r   r.   r#  r   r   r   r  r    s    @
6r   r  )r'   djangor   django.contrib.auth.modelsr   django.testr   r   django.test.clientr   formtools.wizard.viewsr   r
   modelsr   r   ru   	ModelFormr   modelformset_factoryr  inlineformset_factoryr"  r   r   r   r   r   r   r   r  r   r   r   <module>r-     s     + 3 - 3   u  ll//81/Mll00tI0NR4 R4j  ?@h  A>  ?@X  A>  ?@$Dx $D A$DN-PX -P`0x 0:)hH )hX6x 6r   