ó
ø¢TQc           @  s  d  d l  m Z d  d l Z d  d l Z d  d l 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 d  d l m Z d  d l Td  d l Td Z e j ƒ  Z d e j f d „  ƒ  YZ  e d e j! j" e j! j# e e$ ƒ ƒ d ƒ f ƒ d e f d „  ƒ  Yƒ Z% d e j f d „  ƒ  YZ& d e f d „  ƒ  YZ' d e j( f d „  ƒ  YZ) e d d d e j! j" e j! j# e e$ ƒ ƒ d ƒ f ƒ d e f d „  ƒ  Yƒ Z* d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   http(   t   settings(   t   previewt   utils(   t
   FormWizard(   t   TestCase(   t
   parse_html(   t   override_settings(   t   upath(   t   unittest(   t   *u   Done was called!t   TestFormPreviewc           B  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C  s3   t  t |  ƒ j | | ƒ } | j i t d 6ƒ | S(   Nu   custom_context(   t   superR   t   get_contextt   updatet   True(   t   selft   requestt   formt   context(    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyR      s    c         C  s   i d d 6S(   Nu   Works!u   field1(    (   R   R   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   get_initial    s    c         C  s   t  j t ƒ S(   N(   R   t   HttpResponset   success_string(   R   R   t   cleaned_data(    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   done#   s    (   t   __name__t
   __module__R   R   R   (    (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyR      s   		t   TEMPLATE_DIRSu	   templatest   PreviewTestsc           B  sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   u#   django.contrib.formtools.tests.urlsc         C  se   t  t |  ƒ j ƒ  t j t ƒ |  _ d } | |  j j d ƒ d f |  _ i d d 6d d 6|  _ d  S(   Nu,   <input type="hidden" name="%s" value="%s" />u   stageu   %du   foou   field1u   asdfu   field1_(	   R   R   t   setUpR   t   FormPreviewt   TestFormt   unused_namet   inputt	   test_data(   R   t   input_template(    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyR   .   s
    c         C  s    |  j  |  j j d ƒ d ƒ d S(   uA   
        Verifies name mangling to get uniue field name.
        u   field1u   field1__N(   t   assertEqualR   R!   (   R   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_unused_name6   s    c         C  sn   |  j  j d ƒ } |  j d } |  j | | d ƒ |  j | j d t ƒ |  j | j d j i d d 6ƒ d S(   u'  
        Test contrib.formtools.preview form retrieval.

        Use the client library to see if we can sucessfully retrieve
        the form (mostly testing the setup ROOT_URLCONF
        process). Verify that an additional  hidden input field
        is created to manage the stage.

        u	   /preview/i   u   custom_contextu   formu   Works!u   field1N(   t   clientt   getR"   t   assertContainsR%   R   R   t   initial(   R   t   responset   stage(    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_form_get<   s
    
c         C  si   |  j  j i d d 6t j d d d ƒ d 6ƒ |  j j d |  j  ƒ } |  j d } |  j | | d ƒ d	 S(
   u  
        Test contrib.formtools.preview form preview rendering.

        Use the client library to POST to the form to see if a preview
        is returned.  If we do get a form back check that the hidden
        value is correctly managing the state of the form.

        i   u   stageiÖ  i
   i   u   date1u	   /preview/i   N(   R#   R   t   datetimet   dateR'   t   postR"   R)   (   R   R+   R,   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_form_previewL   s    -c         C  s¼   |  j  j i d d 6t j d d d ƒ d 6ƒ |  j j d |  j  ƒ } |  j | j t ƒ |  j	 j
 d	 t |  j  ƒ ƒ } |  j  j i | d 6ƒ |  j j d |  j  ƒ } |  j | j t ƒ d	 S(
   u1  
        Test contrib.formtools.preview form submittal.

        Use the client library to POST to the form with stage set to 3
        to see if our forms done() method is called. Check first
        without the security hash, verify failure, retry with security
        hash and verify sucess.

        i   u   stageiÖ  i
   i   u   date1u	   /preview/u   hashN(   R#   R   R.   R/   R'   R0   t   assertNotEqualt   contentt   success_string_encodedR   t   security_hasht   NoneR    R%   (   R   R+   t   hash(    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_form_submit]   s    -c         C  s›   |  j  j i d d 6ƒ |  j j d t |  j  ƒ ƒ } |  j  j i | d 6d d 6ƒ t j d t ƒ 0 |  j	 j
 d |  j  ƒ } |  j | j t ƒ Wd QXd S(	   uS  
        Test contrib.formtools.preview form submittal when form contains:
        BooleanField(required=False)

        Ticket: #6209 - When an unchecked BooleanField is previewed, the preview
        form's hash would be computed with no value for ``bool1``. However, when
        the preview form is rendered, the unchecked hidden BooleanField would be
        rendered with the string value 'False'. So when the preview form is
        resubmitted, the hash would be computed with the value 'False' for
        ``bool1``. We need to make sure the hashes are the same in both cases.

        i   u   stageu   hashu   Falseu   bool1t   recordu	   /preview/N(   R#   R   R   R5   R6   R    t   warningst   catch_warningsR   R'   R0   R%   R3   R4   (   R   R7   R+   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_bool_submitq   s    c         C  s    |  j  j i d d 6ƒ |  j j d |  j  ƒ } |  j | j t ƒ t j t	 |  j  ƒ ƒ } |  j  j i | d 6ƒ |  j j d |  j  ƒ } |  j
 | j t ƒ d S(   u]   
        Test contrib.formtools.preview form submittal, using a correct
        hash
        i   u   stageu	   /preview/u   hashN(   R#   R   R'   R0   R2   R3   R4   R   t	   form_hmacR    R%   (   R   R+   R7   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_form_submit_good_hash…   s    c         C  s·   |  j  j i d d 6ƒ |  j j d |  j  ƒ } |  j | j d ƒ |  j | j t ƒ t	 j
 t |  j  ƒ ƒ d } |  j  j i | d 6ƒ |  j j d |  j  ƒ } |  j | j t ƒ d S(	   ur   
        Test contrib.formtools.preview form submittal does not proceed
        if the hash is incorrect.
        i   u   stageu	   /preview/iÈ   u   badu   hashu   /previewpreview/N(   R#   R   R'   R0   R%   t   status_codeR2   R3   R4   R   R=   R    (   R   R+   R7   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_form_submit_bad_hash•   s    (   R   R   t   urlsR   R&   R-   R1   R8   R<   R>   R@   (    (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyR   &   s   							t   FormHmacTestsc           B  s   e  Z d  „  Z d „  Z RS(   c         C  sf   t  i d d 6d d 6ƒ } t  i d d 6d d 6ƒ } t j | ƒ } t j | ƒ } |  j | | ƒ d S(   uÓ   
        Regression test for #10034: the hash generation function should ignore
        leading/trailing whitespace so as to be friendly to broken browsers that
        submit it (usually in textareas).
        u   joeu   nameu   Speaking espaÃ±ol.u   biou     joeu   Speaking espaÃ±ol.  N(   t   HashTestFormR   R=   R%   (   R   t   f1t   f2t   hash1t   hash2(    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_textfield_hash¨   s
    c         C  sP   t  i  ƒ } t i  d t ƒ} t j | ƒ } t j | ƒ } |  j | | ƒ d S(   uœ   
        Regression test for #10643: the security hash should allow forms with
        empty_permitted = True, or forms where data has not changed.
        t   empty_permittedN(   t   HashTestBlankFormRC   R   R   R=   R%   (   R   RD   RE   RF   RG   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_empty_permitted´   s
    (   R   R   RH   RK   (    (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRB   ¦   s   	t   TestWizardClassc           B  s   e  Z d  „  Z d „  Z RS(   c         C  s   d S(   Nu   forms/wizard.html(    (   R   t   step(    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   get_templateÆ   s    c         C  s   t  j t ƒ S(   N(   R   R   R   (   R   R   R   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyR   É   s    (   R   R   RN   R   (    (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRL   Ä   s   	t   DummyRequestc           B  s   e  Z d d  „ Z RS(   c         C  sT   t  t |  ƒ j ƒ  | r d p" d |  _ | d  k	 rG |  j j | ƒ n  t |  _ d  S(   Nu   POSTu   GET(	   R   RO   t   __init__t   methodR6   t   POSTR   R   t   _dont_enforce_csrf_checks(   R   RR   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRP   Ï   s
    N(   R   R   R6   RP   (    (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRO   Í   s   t
   SECRET_KEYu   123t   WizardTestsc           B  sµ   e  Z d  Z i d d 6d d 6i d d 6d d 6i d	 d
 6f 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 RS(   u#   django.contrib.formtools.tests.urlsu   Ponyu   0-nameu   2u	   0-thirstyu   123 Main Stu
   1-address1u
   Djangolandu
   1-address2u	   blah blahu   2-random_crapc         C  s:   t  t |  ƒ j ƒ  |  j ƒ  t j d d t d d ƒd  S(   Nu   ignoret   categoryt   moduleu   django.contrib.formtools.wizard(   R   RU   R   t   save_warnings_stateR:   t   filterwarningst   DeprecationWarning(   R   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyR   í   s    
c         C  s!   t  t |  ƒ j ƒ  |  j ƒ  d  S(   N(   R   RU   t   tearDownt   restore_warnings_state(   R   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyR[   ó   s    c         C  s-   |  j  j d ƒ } |  j d | j d ƒ d S(   u8   
        step should be zero for the first form
        u	   /wizard1/i    u   step0N(   R'   R(   R%   R   (   R   R+   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_step_starts_at_zero÷   s    c         C  s>   |  j  j d i d d 6d d 6ƒ } |  j d | j d ƒ d S(	   uH   
        step should be incremented when we go to the next page
        u	   /wizard1/u   testu   0-fieldu   0u   wizard_stepi   u   step0N(   R'   R0   R%   R   (   R   R+   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_step_incrementsþ   s    #c         C  sE   |  j  j d i d d 6d d 6d d 6ƒ } |  j d | j d	 ƒ d
 S(   uG   
        Form should not advance if the hash is missing or bad
        u	   /wizard1/u   testu   0-fieldu   test2u   1-fieldu   1u   wizard_stepi    u   step0N(   R'   R0   R%   R   (   R   R+   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_bad_hash  s
    
c         C  sg   i d d 6d d 6i d d 6d d 6t  j d	 6d
 d 6} |  j j d | ƒ } |  j d | j d ƒ d S(   ur   
        Form should advance if the hash is present and good, as calculated using
        current method.
        u   testu   0-fieldu   test2u   1-fieldu(   cd13b1db3e8f55174bc5745a1b1a53408d4fd1cai   u(   9355d5dff22d49dbad58e46189982cec649f9f5bi   u   hash_0u   1u   wizard_stepu	   /wizard1/u   step0N(   t   picklet   HIGHEST_PROTOCOLR'   R0   R%   R   (   R   t   dataR+   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   test_good_hash  s    

c           s  t  g ‰ |  ‰  d t f ‡ ‡  f d †  ƒ  Y} | t g ƒ } i d d 6d d 6i d d 6d	 d
 6t j d 6d d 6} | t d | ƒ ƒ |  j ˆ d ƒ i d d 6d d 6i d d 6d	 d
 6t j d 6i d d 6d d
 6t j d 6d d 6} |  j t j	 | t d | ƒ ƒ d S(   u~   
        Regression test for ticket #11726.
        Wizard should not raise Http404 when steps are added dynamically.
        t   WizardWithProcessStepc             s   e  Z ‡ ‡  f d  †  Z RS(   c           sg   | d k r4 |  j  ƒ  d k  r4 |  j j t ƒ q4 n  | d k rc ˆ  j t | t ƒ ƒ t ˆ d <n  d  S(   Ni    i   i   (   t	   num_stepst	   form_listt   appendt   WizardPageTwoFormt
   assertTruet
   isinstanceR   (   R   R   R   RM   (   t   thatt   reached(    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   process_step'  s    (   R   R   Rm   (    (   Rl   Rk   (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRd   &  s   u   testu   0-fieldu   test2u   1-fieldu(   cd13b1db3e8f55174bc5745a1b1a53408d4fd1cai   u(   9355d5dff22d49dbad58e46189982cec649f9f5bi   u   hash_0u   1u   wizard_stepRR   i    u(   1e6f6315da42e62f33a30640ec7e007ad3fbf1a1u(   c33142ef9d01b1beae238adf22c3c6c57328f51au   hash_1u   2N(
   t   FalseRL   t   WizardPageOneFormR`   Ra   RO   Ri   t   assertRaisesR   t   Http404(   R   Rd   t   wizardRb   (    (   Rk   Rl   s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt
   test_11726  s2    		



c           s¢   t  g ‰ |  ‰  d t f ‡ ‡  f d †  ƒ  Y} | t t t g ƒ } i d d 6d d 6i d d 6d	 d
 6t j d 6d d 6} | t d | ƒ ƒ |  j ˆ d ƒ d S(   ul   
        Regression test for ticket #14498.  All previous steps' forms should be
        validated.
        Rd   c             s   e  Z ‡ ‡  f d  †  Z RS(   c           s!   ˆ  j  | j ƒ  ƒ t ˆ d <d  S(   Ni    (   Ri   t   is_validR   (   R   R   R   RM   (   Rk   Rl   (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRm   P  s    (   R   R   Rm   (    (   Rl   Rk   (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRd   O  s   u   testu   0-fieldu   test2u   1-fieldu(   cd13b1db3e8f55174bc5745a1b1a53408d4fd1cai   u(   9355d5dff22d49dbad58e46189982cec649f9f5bi   u   hash_0u   1u   wizard_stepRR   i    N(	   Rn   RL   Ro   Rh   t   WizardPageThreeFormR`   Ra   RO   Ri   (   R   Rd   Rr   Rb   (    (   Rk   Rl   s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt
   test_14498G  s    	

c           sŸ   t  g ‰ |  ‰  d t f ‡ ‡  f d †  ƒ  Y} | t t g ƒ } i d d 6d d 6i d d 6d	 d
 6t j d 6d d 6} | t d | ƒ ƒ |  j ˆ d ƒ d S(   uy   
        Regression test for ticket #14576.

        The form of the last step is not passed to the done method.
        t   Wizardc             s   e  Z ‡ ‡  f d  †  Z RS(   c           s'   t  ˆ d <ˆ  j t | ƒ d k ƒ d  S(   Ni    i   (   R   Ri   t   len(   R   R   Rf   (   Rk   Rl   (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyR   k  s    
(   R   R   R   (    (   Rl   Rk   (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRw   j  s   u   testu   0-fieldu   test2u   1-fieldu(   cd13b1db3e8f55174bc5745a1b1a53408d4fd1cai   u(   9355d5dff22d49dbad58e46189982cec649f9f5bi   u   hash_0u   1u   wizard_stepRR   i    N(   Rn   RL   Ro   Rh   R`   Ra   RO   Ri   (   R   Rw   Rr   Rb   (    (   Rk   Rl   s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt
   test_14576a  s    	

c           s¢   t  g ‰ |  ‰  d t f ‡ ‡  f d †  ƒ  Y} | t t t g ƒ } i d d 6d d 6i d d 6d	 d
 6t j d 6d d 6} | t d | ƒ ƒ |  j ˆ d ƒ d S(   uq   
        Regression test for ticket #15075.  Allow modifying wizard's form_list
        in process_step.
        Rd   c             s   e  Z ‡ ‡  f d  †  Z RS(   c           sO   | d k r t  |  j d <n  | d k rK ˆ  j t | t  ƒ ƒ t ˆ d <n  d  S(   Ni    i   (   t   WizardPageTwoAlternativeFormRf   Ri   Rj   R   (   R   R   R   RM   (   Rk   Rl   (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRm   …  s
    (   R   R   Rm   (    (   Rl   Rk   (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRd   „  s   u   testu   0-fieldu   test2u   1-fieldu(   cd13b1db3e8f55174bc5745a1b1a53408d4fd1cai   u(   9355d5dff22d49dbad58e46189982cec649f9f5bi   u   hash_0u   1u   wizard_stepRR   i    N(	   Rn   RL   Ro   Rh   Ru   R`   Ra   RO   Ri   (   R   Rd   Rr   Rb   (    (   Rk   Rl   s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt
   test_15075|  s    	

c         C  s]   t  | j d ƒ } i | j d d 6} x/ | D]' } t | j ƒ } | d | | d <q. W| S(   ub   
        Pull the appropriate field data from the context to pass to the next wizard step
        u   previous_fieldsu   step0u   wizard_stepu   valueu   name(   R   R   t   dictt
   attributes(   R   R+   t   previous_fieldst   fieldst   input_fieldt   input_attrs(    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   grab_field_data™  s    c         C  sc   t  |  j ƒ } |  j | d | | f ƒ |  j | ƒ } | j |  j | d ƒ |  j j d | ƒ S(   uÛ   
        Helper function to test each step of the wizard
        - Make sure the call succeeded
        - Make sure response is the proper step number
        - return the result from the post for the next step
        u   Step %d of %di   u	   /wizard2/(   Rx   t   wizard_step_dataR)   R‚   R   R'   R0   (   R   R+   t   step_not
   step_countRb   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   check_wizard_step¦  s
    c         C  sO   |  j  j d ƒ } x6 t d t |  j ƒ d ƒ D] } |  j | | ƒ } q/ Wd  S(   Nu	   /wizard2/i   (   R'   R(   t   rangeRx   Rƒ   R†   (   R   R+   R„   (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt	   test_9473¶  s    #(   R   R   RA   Rƒ   R   R[   R]   R^   R_   Rc   Rs   Rv   Ry   R{   R‚   R†   Rˆ   (    (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyRU   ×   s,   					
		)					(+   t
   __future__R    R.   t   osR`   t   reR:   t   djangoR   t   django.confR   t   django.contrib.formtoolsR   R   t   django.contrib.formtools.wizardR   t   django.testR   t   django.test.htmlR   t   django.test.utilsR   t   django.utils._osR	   t   django.utilsR
   t%   django.contrib.formtools.tests.wizardt$   django.contrib.formtools.tests.formsR   t   encodeR4   R   R   t   patht   joint   dirnamet   __file__R   RB   RL   t   HttpRequestRO   RU   (    (    (    s@   ../Django//lib/python/django/contrib/formtools/tests/__init__.pyt   <module>   s:   

-{	
-