Ñò
x¼Kc           @   sê  d  Z  d d k Z d d k l Z l Z d d k l Z l Z d d k l	 Z	 l
 Z
 l Z d d k l Z l Z l Z l Z l Z l Z d d k l Z d d k l Z d d	 k l Z d d
 k l Z d d k l Z l 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* d „  Z+ d „  Z, d „  Z- d „  Z. d „  Z/ d „  Z0 d „  Z1 d  „  Z2 e e ƒ d! „  ƒ Z3 d" „  Z4 d# „  Z5 d$ „  Z6 d% „  Z7 d& „  Z8 d' „  Z9 d S((   s,  
    werkzeug.test test
    ~~~~~~~~~~~~~~~~~~

    "Quis custodiet ipsos custodes?"

       -- "Who will police the police?", or in this case:

    Who will test the test?

    :copyright: (c) 2010 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t   StringIOt
   OutputType(   t   assert_raisest   raises(   t   Requestt   Responset   BaseResponse(   t   Clientt   EnvironBuildert   create_environt   ClientRedirectErrort   stream_encode_multipartt   run_wsgi_app(   t   redirect(   t   get_host(   t   parse_form_data(   t
   url_decode(   t   Headerst	   MultiDictc         C   s;   t  |  i d d ƒ d d ƒ} | i d d ƒ | |  | ƒ S(   sc   A WSGI application which sets a cookie, and returns as a ersponse any
    cookie which exists.
    t   HTTP_COOKIEs	   No Cookiet   mimetypes
   text/plaint   test(   R   t   gett
   set_cookie(   t   environt   start_responset   response(    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt
   cookie_app   s    	c         C   s   t  d ƒ } | |  | ƒ S(   Ns   http://localhost/some/redirect/(   R   (   R   R   R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   redirect_loop_app(   s    c         C   sx   t  |  ƒ } | i d j o t p t d | i ‚ n d | i j o t d ƒ } n t d | i ƒ } | |  | ƒ S(   Ns   http://localhost/s   http://localhost/first/requests   http://localhost/some/redirect/s+   redirect_demo_app() did not expect URL "%s"s   /some/redirects   current url: %s(   s   http://localhost/s   http://localhost/first/requests   http://localhost/some/redirect/(   R   t   urlt   Falset   AssertionErrorR   R   (   R   R   t   reqR   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   redirect_with_get_app-   s     
c         C   s{   t  |  ƒ } | i d j oF | i d j p
 t d ‚ | i p
 t d ‚ t d | i ƒ } n t d ƒ } | |  | ƒ S(   Ns   http://localhost/some/redirect/t   GETs   request should be GETs   request should not have datas   current url: %s(   R   R   t   methodR   t   formR   R   (   R   R   R    R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   redirect_with_post_app:   s    c         C   s   t  d ƒ } | |  | ƒ S(   Ns   http://example.org/(   R   (   R   R   R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   external_redirect_demo_appE   s    c         C   s   t  |  ƒ } | i d d j p t | i d ‚ | i i d ƒ d d g j p t | i i d ƒ ‚ t d ƒ } | |  | ƒ S(   Nt   fieldt   val1t   val2t   ok(   R   R$   R   t   getlistR   (   R   R   R    R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   multi_value_post_appJ   s
    %5c          C   s?   t  t ƒ }  |  i ƒ  \ } } } d t | ƒ j p t ‚ d S(   s9   Test that a server cookie is set and stored in the clients
   Set-CookieN(   R   R   t   opent   dictR   (   t   ct   appitert   codet   headers(    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_set_cookie_appR   s    c          C   sG   t  t ƒ }  |  i ƒ  \ } } } d |  i i d d j p t ‚ d S(   s=   Test that the cookie jar in the test client stores the cookieR   s   localhost.localt   /N(   R   R   R-   t
   cookie_jart   _cookiesR   (   R/   R0   R1   R2   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_cookiejar_stores_cookieY   s    c          C   sB   t  t ƒ }  |  i ƒ  \ } } } d i | ƒ d j p t ‚ d S(   s3   Test there is no cookie set in the client initiallyt    s	   No CookieN(   R   R   R-   t   joinR   (   R/   R0   R1   R2   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_no_initial_cookie`   s    c          C   sL   t  t ƒ }  |  i ƒ  |  i ƒ  \ } } } d i | ƒ d j p t ‚ d S(   s@   Test that the client resends cookies on subsequent requests
    R8   s	   test=testN(   R   R   R-   R9   R   (   R/   R0   R1   R2   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_resent_cookieg   s    
c          C   sR   t  t d t ƒ}  |  i ƒ  |  i ƒ  \ } } } d i | ƒ d j p t ‚ d S(   sS   Ensure that cookies are not stored when use_cookies is False in the
    client
    t   use_cookiesR8   s	   No CookieN(   R   R   R   R-   R9   R   (   R/   R0   R1   R2   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_disable_cookiesp   s    
c          C   sR   t  t ƒ }  |  i d ƒ |  i d ƒ \ } } } d i | ƒ d j p t ‚ d S(   sX   Test that the client resends cookies on subsequent requests for
    different paths
    s   /path1s   /path2R8   s	   test=testN(   R   R   R-   R9   R   (   R/   R0   R1   R2   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_cookie_for_different_pathz   s    c          C   s^  t  ƒ  }  |  i d
 j p t ‚ d |  _ |  i d j p t ‚ |  i i d t d ƒ d ƒ |  i d i d j p t ‚ |  i d j p t ‚ d |  i d <|  i	 ƒ  } |  i
 ƒ  | i d	 j p t ‚ | i d j p t ‚ | i d d j p t ‚ | i d i d j p t ‚ | i d i d j p t ‚ | i d i ƒ  d j p t ‚ d
 S(   s   Test EnvironBuilder basicst   POSTs!   application/x-www-form-urlencodedR   s   test contentss   test.txts
   text/plains   multipart/form-datas   normal values   http://localhost/N(   R   t   content_typet   NoneR   R#   t   filest   add_fileR    R$   t   get_requestt   closeR   t   filenamet   read(   t   bR    (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_environ_builder_basics„   s     		
c          C   s¹   t  d h d d 6d h d d 6ƒ }  d |  i d <|  i ƒ  } | d d j p t ‚ | d	 d j p t ‚ | d d j p t ‚ d
 |  i d <|  i ƒ  } | d d
 j p t ‚ d S(   s1   Test EnvironBuilder headers and environ overridest   environ_bases   Foo/0.1t   HTTP_USER_AGENTt   environ_overridesi   s   wsgi.versions   very well sirs   X-Suck-My-Dickt   HTTP_X_SUCK_MY_DICKs   Bar/1.0s
   User-AgentN(   i   i   (   i   i   (   R   R2   t   get_environR   (   RH   t   env(    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_environ_builder_headersš   s    c          C   s"  t  d d d d ƒ }  |  i d j p t ‚ |  i d j p t ‚ |  i d j p t ‚ |  i d j p t ‚ t  d d d d ƒ }  |  i d j p t ‚ |  i d j p t ‚ |  i d	 j p t ‚ |  i d j p t ‚ d
 |  _ |  i d j p t ‚ d |  _ |  i d j p t ‚ |  i d
 j p t ‚ |  i d j p t ‚ d |  _ d |  _ d |  _ |  i	 ƒ  } | d d j p t ‚ | d d j p t ‚ | d d j p t ‚ | d d j p t ‚ | d d j p t ‚ | d d j p t ‚ |  i d j p t ‚ d S(   s(   Test EnvironBuilder with different pathst   paths   /foot   base_urls   http://example.com/R8   s   example.coms   http://example.com/bars   http://example.com/bar/s   /bart	   localhosts   http://localhost/bar/s   http://localhost:8080/s   localhost:8080i  s   foo.invalidt   httpss   /testt   SERVER_NAMEt   SERVER_PORTt   443t   SCRIPT_NAMEt	   PATH_INFOt	   HTTP_HOSTs   wsgi.url_schemes   https://foo.invalid/test/N(
   R   RR   R   RQ   t   script_roott   hostt   server_namet   server_portt
   url_schemeRN   (   RH   RO   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_environ_builder_paths©   s6    					c          C   sã   t  ƒ  }  |  i d j p t ‚ d |  _ |  i d j p t ‚ d |  i d <|  i d j p t ‚ |  i i d t d ƒ d ƒ |  i d j p t ‚ |  i	 ƒ  } | i d d j p t ‚ | i d i
 ƒ  d j p t ‚ d S(	   s$   EnvironBuilder content type behaviorR?   s!   application/x-www-form-urlencodedt   bart   foot   blafasels   test.txts   multipart/form-dataN(   R   R@   RA   R   R#   R$   RB   RC   R    RD   RG   (   t   builderR    (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt!   test_environ_builder_content_typeË   s    		c          C   sº   t  t d d d d d d ƒ ƒ }  x’ t t f D]„ } t |  | d d ƒ\ } } } t | t ƒ | j p t ‚ t h | d	 6t	 | ƒ d
 6d | d 6ƒ d } | |  j p t ‚ q. Wd S(   s   EnvironBuilder stream switchRb   u   bart   blubu   blaht   huu   humt	   thresholdi–   s
   wsgi.inputt   CONTENT_LENGTHs"   multipart/form-data; boundary="%s"t   CONTENT_TYPEi   N(
   R   R.   R   t   TrueR   t
   isinstanceR   R   R   t   str(   t   dt   use_tempfilet   streamt   lengtht   boundaryR$   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt"   test_environ_builder_stream_switchÚ   s    ! c          C   s  t  d d ƒ }  h t d 6d! d 6t d 6t i d 6t d	 6d
 d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6} x2 | i ƒ  D]$ \ } } |  | | j p t ‚ q• W|  d i d ƒ d j p t ‚ t  d d ƒ d d j p t ‚ d  S("   s   Environment creation helpers   /foo?bar=bazs   http://example.org/s   wsgi.multiprocessi   i    s   wsgi.versions   wsgi.run_onces   wsgi.errorss   wsgi.multithreadt   https   wsgi.url_schemeR8   RX   Rj   t   0Ri   s   example.orgRU   R"   t   REQUEST_METHODRZ   s   /fooRY   t   80RV   s   HTTP/1.1t   SERVER_PROTOCOLs   bar=bazt   QUERY_STRINGs
   wsgi.inputs   http://example.com/N(   i   i    (   R	   R   t   syst   stderrt	   iteritemsR   RG   (   RO   t   expectedt   keyt   value(    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_create_environè   s.    

 !c             sœ   g  ‰  d t  f ‡  f d †  ƒ  Y}  t d h |  ƒ  d 6ƒ } t ˆ  ƒ d j p t ‚ t ƒ  } | i i d |  ƒ  ƒ | i ƒ  t ˆ  ƒ d j p t ‚ d S(	   s=   Test automatic closing of files in EnvironBuilder and friendst   SpecialInputc              s    e  Z d  „  Z ‡  f d †  Z RS(   c         S   s   d S(   NR8   (    (   t   self(    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyRG     s    c            s   ˆ  i  |  ƒ d  S(   N(   t   append(   R‚   (   t   closed(    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyRE   
  s    (   t   __name__t
   __module__RG   RE   (    (   R„   (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyR     s   	t   dataRb   i   t   blahi   N(   t   objectR	   t   lenR   R   RB   RC   RE   (   R   RO   Rd   (    (   R„   s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_file_closing  s    	
c          C   s  t  d d d ƒ}  t t ƒ } | i d |  d t ƒ \ } } } | d j p t ‚ d i | ƒ d j p t ‚ t t d	 t ƒ} | i d d t ƒ} | i	 d
 j p t ‚ | i
 d j p t ‚ t t d	 t ƒ} | i d d t ƒ} | i	 d
 j p t ‚ | i
 d j p t ‚ d  S(   NR4   RR   s   http://localhostRL   t   follow_redirectss   200 OKR8   s,   current url: http://localhost/some/redirect/t   response_wrapperiÈ   s   /first/request(   R	   R   R!   R-   Rk   R   R9   R   R   t   status_codeR‡   (   RO   R/   R0   R1   R2   t   resp(    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_follow_redirect  s    !c              s;   t  d d d ƒ‰ t t ƒ ‰  t t ‡  ‡ f d †  ƒ d  S(   NR4   RR   s   http://localhostc              s   ˆ  i  d  ˆ d t ƒ S(   RL   RŒ   (   R-   Rk   (    (   R/   RO   (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   <lambda>,  s    (   R	   R   R&   R   t   RuntimeError(    (    (   R/   RO   s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_follow_external_redirect)  s    c          C   s+   t  t d t ƒ}  |  i d d t ƒ} d  S(   NR   R4   RŒ   (   R   R   R   R   Rk   (   R/   R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_follow_redirect_loop/  s    c          C   s_   t  t d t ƒ}  |  i d d t d d ƒ} | i d j p t ‚ | i d j p t ‚ d  S(   NR   R4   RŒ   R‡   s   foo=blub+hehe&blah=42iÈ   s,   current url: http://localhost/some/redirect/(   R   R%   R   t   postRk   RŽ   R   R‡   (   R/   R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_follow_redirect_with_post5  s    c          C   s€   d „  }  t  |  d t ƒ} | i d ƒ } | i d j p t ‚ t  |  d t ƒ} | i d d ƒ } | i d j p t ‚ d S(   s0   PATH_INFO and SCRIPT_NAME in client are decoded.c         S   s'   | d d g ƒ |  d d |  d g S(   Ns   200 OKs   Content-Types
   text/plainRY   s   
RX   (   s   Content-Types
   text/plain(    (   R   R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_app>  s    R   s
   /foo%40bars	   /foo@bar
s   http://localhost/bar%40bazs   /foo@bar
/bar@bazN(   R   R   R   R‡   R   (   R—   R/   R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt$   test_path_info_script_name_unquoting<  s    	c          C   s¬   t  t d t ƒ}  h d d g d 6} |  i d d | ƒ} | i d j p t ‚ t  t d t ƒ}  t h d d g d 6ƒ } |  i d d | ƒ} | i d j p t ‚ d S(	   s!   Multi-value submit in test clientR   R(   R)   R'   R4   R‡   iÈ   N(   R   R,   R   R•   RŽ   R   R   (   R/   R‡   R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_multi_value_submitI  s    c          C   sD   t  d d d ƒ}  |  i d j p t ‚ |  i d j p t ‚ d S(   s   Test client IRI supportu
   /fÃ¶Ã¶-barRR   u   http://â˜ƒ.net/s   /f%C3%B6%C3%B6-bars   http://xn--n3h.net/N(   R   RQ   R   RR   (   RH   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_iri_supportY  s    c          C   sÓ   d „  }  t  |  h  ƒ \ } } } | d j p t ‚ | d
 g j p t ‚ | d g j p t ‚ d „  } t  | h  ƒ \ } } } | d j p t ‚ | d g j p t ‚ t | ƒ d d g j p t ‚ d	 S(   s   Run various WSGI apps.c         S   s   | d d g ƒ d g S(   Ns   200 OKs   Content-Types	   text/htmls   Hello World!(   s   Content-Types	   text/html(    (   R   R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt
   simple_appb  s    s   200 OKs   Content-Types	   text/htmls   Hello World!c         s   s   | d d g ƒ d Vd Vd  S(   Ns   200 OKs   Content-Types	   text/htmls   Hello s   World!(   s   Content-Types	   text/html(    (   R   R   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   yielding_appj  s    s   Hello s   World!N(   s   Content-Types	   text/html(   s   Content-Types	   text/html(   R   R   t   list(   R›   t   app_itert   statusR2   Rœ   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_run_wsgi_apps`  s    		c          C   sq   t  i d „  ƒ }  t |  t ƒ } | i d ƒ } | i d j p t ‚ | i d ƒ } | i d j p t ‚ d S(   s7   Ensure that the test client works with multiple cookiesc         S   sE   t  t t |  i i ƒ  ƒ ƒ ƒ } | i d d ƒ | i d d ƒ | S(   Nt   test1Rb   t   test2Ra   (   R   t   reprt   sortedt   cookiest   itemsR   (   t   requestR   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyR—   v  s    !R4   s   []s'   [('test1', u'foo,'), ('test2', u'bar')]N(   R   t   applicationR   R   R   R‡   R   (   R—   t   clientR   (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   test_multiple_cookiest  s    (:   t   __doc__Rz   t	   cStringIOR    R   t
   nose.toolsR   R   t   werkzeug.wrappersR   R   R   t   werkzeug.testR   R   R	   R
   R   R   t   werkzeug.utilsR   t   werkzeug.wsgiR   t   werkzeug.formparserR   t   werkzeug.urlsR   t   werkzeug.datastructuresR   R   R   R   R!   R%   R&   R,   R3   R7   R:   R;   R=   R>   RI   RP   R`   Re   Rs   R€   R‹   R   R“   R”   R–   R˜   R™   Rš   R    Rª   (    (    (    s=   /Users/mitsuhiko/Development/werkzeug-main/tests/test_test.pyt   <module>   sL   .	
											
	
			"											