ó
ç'ÊUc           @   sl   d  d l  m Z d  d l Z d  d l m Z m Z d  d l m Z d  d l m	 Z	 d e f d „  ƒ  YZ
 d S(   iÿÿÿÿ(   t   TestCaseN(   t   Responset   Request(   t   Spider(   t   CookiesMiddlewaret   CookiesMiddlewareTestc           B   s\   e  Z d	 d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(
   c         C   s4   d „  } |  j  t | | ƒ ƒ t | | ƒ ƒ | ƒ S(   Nc         S   s   t  j d |  ƒ S(   Ns   ;\s*(   t   ret   split(   t   cv(    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   <lambda>   s    (   t   assertEqualt   sorted(   t   selft   firstt   secondt   msgt   cookievaleq(    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   assertCookieValEqual   s    	c         C   s   t  d ƒ |  _ t ƒ  |  _ d  S(   Nt   foo(   R   t   spiderR   t   mw(   R   (    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   setUp   s    c         C   s
   |  `  d  S(   N(   R   (   R   (    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   tearDown   s    c         C   sÛ   i d d 6} t  d ƒ } |  j j | |  j ƒ d  k s= t ‚ d | j k sR t ‚ t d d | ƒ} |  j j | | |  j ƒ | k s‹ t ‚ t  d ƒ } |  j j | |  j ƒ d  k s» t ‚ |  j	 | j j
 d ƒ d ƒ d  S(   Ns   C1=value1; path=/s
   Set-Cookies   http://scrapytest.org/t   Cookiet   headerss   http://scrapytest.org/sub1/s	   C1=value1(   R   R   t   process_requestR   t   Nonet   AssertionErrorR   R   t   process_responset   assertEqualst   get(   R   R   t   reqt   rest   req2(    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt
   test_basic   s    $'$c         C   s  i d d 6} t  d ƒ } t d d | ƒ} |  j j | | |  j ƒ | k sR t ‚ t  d d i d d 6ƒ} |  j j | |  j ƒ d  k s t ‚ d	 | j k s¤ t ‚ t d d i d
 d 6ƒ} |  j j | | |  j ƒ | k sä t ‚ t  d ƒ } |  j j | |  j ƒ d  k st ‚ |  j	 | j j
 d	 ƒ d ƒ t  d d i d d 6ƒ} |  j j | |  j ƒ d  k smt ‚ |  j	 | j j
 d	 ƒ d ƒ d  S(   Ns   C1=value1; path=/s
   Set-Cookies   http://scrapytest.org/R   s   http://scrapytest.org/dontmerget   metai   t   dont_merge_cookiesR   s   dont=mergeme; path=/s   http://scrapytest.org/mergemes	   C1=value1i    (   R   R   R   R   R   R   R   R   R   R   R   (   R   R   R   R    (    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   test_dont_merge_cookies'   s    '$'$$c         C   sc  i d d 6d d 6d d 6d d 6i d	 d 6d
 d 6d d 6d d 6i d d 6d d 6d d 6d d 6i d d 6d d 6d d 6d d 6g } t  d d | ƒ} |  j j | |  j ƒ t  d ƒ } |  j j | |  j ƒ | j j d ƒ d k sê t ‚ t  d ƒ } |  j j | |  j ƒ |  j | j j d ƒ d ƒ t  d ƒ } |  j j | |  j ƒ d | j k s_t ‚ d  S(   Nt   C1t   namet   value1t   values   /foot   paths   scrapytest.orgt   domaint   C2t   value2s   /bart   C3t   value3t   C4t   value4s
   scrapy.orgs   http://scrapytest.org/t   cookiess   http://scrapytest.org/fooR   s   C1=value1; C3=value3s   C3=value3; C1=value1s   http://scrapytest.org/bars	   C2=value2s   http://scrapytest.org/baz(   s   C1=value1; C3=value3s   C3=value3; C1=value1(   R   R   R   R   R   R   R   R   (   R   R2   R   (    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   test_complex_cookiesA   s    %c         C   sï   t  d d i d d 6ƒ} |  j j | |  j ƒ d  k s= t ‚ |  j | j j d ƒ d ƒ i d d 6} t	 d d	 | ƒ} |  j j
 | | |  j ƒ | k sŸ t ‚ t  d
 ƒ } |  j j | |  j ƒ d  k sÏ t ‚ |  j | j j d ƒ d ƒ d  S(   Ns   http://scrapytest.org/R2   t   saladat   galletaR   s   galleta=saladas   C1=value1; path=/s
   Set-CookieR   s   http://scrapytest.org/sub1/s   C1=value1; galleta=salada(   R   R   R   R   R   R   R   R   R   R   R   R   (   R   R   R   R    R!   (    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   test_merge_request_cookies[   s    $'$c         C   sr  t  d d i d d 6d i d d 6ƒ} |  j j | |  j ƒ d  k sJ t ‚ |  j | j j d ƒ d	 ƒ i d
 d 6} t	 d d | d | ƒ} |  j j
 | | |  j ƒ | k s² t ‚ t  d d | j ƒ} |  j j | |  j ƒ d  k së t ‚ |  j | j j d ƒ d ƒ t  d d i d d 6d i d d 6ƒ} |  j j | |  j ƒ d  k sQt ‚ |  j | j j d ƒ d ƒ i d d 6} t	 d d | d | ƒ} |  j j
 | | |  j ƒ | k s¹t ‚ t  d d | j ƒ} |  j j | |  j ƒ d  k sòt ‚ |  j | j j d ƒ d ƒ t  d ƒ } |  j j | |  j ƒ d  k s>t ‚ i d
 d 6} t	 d d | d | ƒ}	 |  j j
 | |	 |  j ƒ |	 k sŠt ‚ t  d ƒ }
 |  j j |
 |  j ƒ d  k sºt ‚ |  j |
 j j d ƒ d ƒ t  d ƒ } |  j j | |  j ƒ d  k st ‚ |  j | j j d ƒ d ƒ t  d ƒ } |  j j | |  j ƒ d  k sRt ‚ |  j | j j d ƒ d  ƒ d  S(   Ns   http://scrapytest.org/R2   R4   R5   R#   t   store1t	   cookiejarR   s   galleta=saladas   C1=value1; path=/s
   Set-CookieR   t   requests   C1=value1; galleta=saladat   dulcet   store2s   galleta=dulces   C2=value2; path=/s   C2=value2; galleta=dulces   http://scrapytest.org:1104/s/   http://scrapytest.org:1104/some-redirected-paths	   C1=value1s*   http://scrapytest.org/some-redirected-paths   file:///scrapy/sometempfile(   R   R   R   R   R   R   R   R   R   R   R   R#   R   (   R   R   R   R    R!   t   req3t   res2t   req4t   req5_1t   res5_1t   req5_2t   req5_3t   req6(    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   test_cookiejar_keyi   s@    &$'$&$'$$'$$$c         C   sk   t  d d i d d 6ƒ} |  j j | |  j ƒ d  k s= t ‚ |  j d | j ƒ |  j d | j d ƒ d  S(   Ns   http://example-host/R2   t   USDt   currencyCookieR   (   R   R   R   R   R   R   t   assertInR   (   R   R9   (    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   test_local_domain—   s    $N(   t   __name__t
   __module__R   R   R   R   R"   R%   R3   R6   RD   RH   (    (    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyR   	   s   							.(   t   unittestR    R   t   scrapy.httpR   R   t   scrapy.spidersR   t$   scrapy.downloadermiddlewares.cookiesR   R   (    (    (    sK   /home/travis/build/scrapy/scrapy/tests/test_downloadermiddleware_cookies.pyt   <module>   s
   