ó
ç'ÊUc           @   sŸ   d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z m Z d  d l m	 Z	 m
 Z
 m Z d g Z d e j f d „  ƒ  YZ e d k r› e j ƒ  n  d S(	   iÿÿÿÿN(   t   urlparse(   t   Responset   TextResponset   HtmlResponse(   t   response_httpreprt   open_in_browsert   get_meta_refreshs   scrapy.utils.responset   ResponseUtilsTestc           B   s8   e  Z e d  d d d ƒ Z d „  Z d „  Z d „  Z RS(   t   urls   http://example.org/t   bodyt   dummy_responsec         C   sœ   t  d ƒ } |  j t | ƒ d ƒ t  d d d d i d d 6d d	 ƒ} |  j t | ƒ d
 ƒ t  d d d d i d d 6d d	 ƒ} |  j t | ƒ d ƒ d  S(   Ns   http://www.example.coms   HTTP/1.1 200 OK

t   statusi”  t   headerss	   text/htmls   Content-typeR	   s	   Some bodys<   HTTP/1.1 404 Not Found
Content-Type: text/html

Some bodyi
  s4   HTTP/1.1 6666 
Content-Type: text/html

Some body(   R   t   assertEqualR   (   t   selft   r1(    (    s=   /home/travis/build/scrapy/scrapy/tests/test_utils_response.pyt   test_response_httprepr   s    %%c            st   d ‰  d } ‡  f d †  } t  ˆ  d | ƒ} t | d | ƒsK t d ƒ ‚ |  j t t t ˆ  d | ƒd t ƒd  S(   Ns&   http:///www.example.com/some/page.htmlsM   <html> <head> <title>test page</title> </head> <body>test body</body> </html>c            sh   t  |  ƒ j } t j j | ƒ s6 |  j d d ƒ } n  t | ƒ j ƒ  } d ˆ  | k sd t d ƒ ‚ t S(   Ns   file://t    s   <base href="%s">s   <base> tag not added(	   R    t   patht   ost   existst   replacet   opent   readt   AssertionErrort   True(   t   burlR   t   bbody(   R   (    s=   /home/travis/build/scrapy/scrapy/tests/test_utils_response.pyt   browser_open   s    R	   t	   _openfuncs   Browser not calledt   debug(   R   R   R   t   assertRaisest	   TypeErrorR   R   (   R   R	   R   t   response(    (   R   s=   /home/travis/build/scrapy/scrapy/tests/test_utils_response.pyt   test_open_in_browser   s    	c         C   s|   t  d d d ƒ} t  d d d ƒ} t  d d d ƒ} |  j t | ƒ d ƒ |  j t | ƒ d	 ƒ |  j t | ƒ d
 ƒ d  S(   Ns   http://www.example.comR	   s¹   
        <html>
        <head><title>Dummy</title><meta http-equiv="refresh" content="5;url=http://example.org/newpage" /></head>
        <body>blahablsdfsal&amp;</body>
        </html>sà   
        <html>
        <head><title>Dummy</title><noScript>
        <meta http-equiv="refresh" content="5;url=http://example.org/newpage" /></head>
        </noSCRIPT>
        <body>blahablsdfsal&amp;</body>
        </html>s"  
    <noscript><meta http-equiv="REFRESH" content="0;url=http://www.example.com/newpage</noscript>
    <script type="text/javascript">
    if(!checkCookies()){
        document.write('<meta http-equiv="REFRESH" content="0;url=http://www.example.com/newpage">');
    }
    </script>
        g      @s   http://example.org/newpage(   g      @s   http://example.org/newpage(   NN(   NN(   R   R   R   t   None(   R   R   t   r2t   r3(    (    s=   /home/travis/build/scrapy/scrapy/tests/test_utils_response.pyt   test_get_meta_refresh'   s    						(   t   __name__t
   __module__R   R
   R   R"   R&   (    (    (    s=   /home/travis/build/scrapy/scrapy/tests/test_utils_response.pyR   
   s   	
	t   __main__(   R   t   unittestt   six.moves.urllib.parseR    t   scrapy.httpR   R   R   t   scrapy.utils.responseR   R   R   t   __doctests__t   TestCaseR   R'   t   main(    (    (    s=   /home/travis/build/scrapy/scrapy/tests/test_utils_response.pyt   <module>   s   	6