î
¾?T¤	  ã               @   só   d  d l  Z d  d l j j Z y d  d l m Z Wn" e k
 rV d  d l	 m Z Yn Xd  d l
 m Z d  d l m Z d  d l m Z m Z d d l m Z Gd d	 „  d	 e ƒ Z d
 d „  Z d d „  Z d d „  Z d d „  Z d d „  Z d S)é    N)ÚHTTPConnection)Úb)Ú
Controller)ÚClientÚrequesté   )Úurlopenc               @   sL   e  Z d  Z d d „  Z d d „  Z d d „  Z d d „  Z d	 d
 „  Z d S)ÚRootc             C   s   d S)NzHello World!© )Úselfr
   r
   ú6/home/prologic/work/circuits/tests/web/test_unicode.pyÚindex   s    z
Root.indexc             C   s   |  j  j j ƒ  S)N)r   ÚbodyÚread)r   r
   r
   r   Úrequest_body   s    zRoot.request_bodyc             C   s   d S)Nõ   Ã¤r
   )r   r
   r
   r   Úresponse_body   s    zRoot.response_bodyc             C   s   |  j  j d S)NÚA)r   Úheaders)r   r
   r
   r   Úrequest_headers   s    zRoot.request_headersc             C   s   d |  j  j d <d S)Nr   r   )Úresponser   )r   r
   r
   r   Úresponse_headers   s    zRoot.response_headersN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r
   r
   r
   r   r	      s
   r	   c             C   s3  t  |  j j j ƒ } | j ƒ  } d } t | ƒ } | | k } | s!t j d | f d | | f ƒ i d t j	 ƒ  k s‡ t j
 t ƒ r– t j t ƒ n d d 6t j | ƒ d 6d t j	 ƒ  k sÎ t j
 | ƒ rÝ t j | ƒ n d d 6t j | ƒ d	 6} d i | d 6} t t j | ƒ ƒ ‚ n  t } } } d  S)NzHello World!ú==ú0%(py0)s == %(py6)s
{%(py6)s = %(py2)s(%(py4)s)
}r   Úpy2Úpy6ÚsÚpy0Úpy4Ú úassert %(py8)sÚpy8)r   )r   r#   )r   ÚserverÚhttpÚbaser   r   Ú
@pytest_arÚ_call_reprcompareÚ@py_builtinsÚlocalsÚ_should_repr_global_nameÚ	_safereprÚAssertionErrorÚ_format_explanationÚNone)ÚwebappÚfr   Ú@py_assert3Ú@py_assert5Ú@py_assert1Ú@py_format7Ú@py_format9r
   r
   r   Ú
test_index#   s        ³   r8   c             C   s   t  |  j j |  j j ƒ } | j ƒ  t d ƒ } | j d d | ƒ | j ƒ  } | j } d } | | k } | st	 j
 d | f d | | f ƒ i t	 j | ƒ d 6t	 j | ƒ d 6d	 t j ƒ  k sÓ t	 j | ƒ râ t	 j | ƒ n d	 d
 6} d i | d 6} t t	 j | ƒ ƒ ‚ n  t } } } | j } d } | | k } | sêt	 j
 d | f d | | f ƒ i t	 j | ƒ d 6t	 j | ƒ d 6d	 t j ƒ  k s§t	 j | ƒ r¶t	 j | ƒ n d	 d
 6} d i | d 6} t t	 j | ƒ ƒ ‚ n  t } } } | j ƒ  }	 d } t | ƒ }
 |	 |
 k } | st	 j
 d | f d |	 |
 f ƒ i d t j ƒ  k sjt	 j t ƒ ryt	 j t ƒ n d d 6t	 j |
 ƒ d 6d t j ƒ  k s±t	 j |	 ƒ rÀt	 j |	 ƒ n d d
 6t	 j | ƒ d 6} d i | d 6} t t	 j | ƒ ƒ ‚ n  t } } }
 | j ƒ  d  S) Nr   ÚGETz/request_bodyéÈ   r   ú.%(py2)s
{%(py2)s = %(py0)s.status
} == %(py5)sÚpy5r   r   r    r"   úassert %(py7)sÚpy7ÚOKú.%(py2)s
{%(py2)s = %(py0)s.reason
} == %(py5)sú0%(py0)s == %(py6)s
{%(py6)s = %(py2)s(%(py4)s)
}r   r   r   r!   úassert %(py8)sr$   )r   )r;   r=   )r   )r@   r=   )r   )rA   rB   )r   r%   ÚhostÚportÚconnectr   r   ÚgetresponseÚstatusr(   r)   r-   r*   r+   r,   r.   r/   r0   Úreasonr   Úclose)r1   Ú
connectionr   r   r5   Ú@py_assert4r3   Ú@py_format6Ú@py_format8r   r4   r6   r7   r
   r
   r   Útest_request_body)   s>    
	    |   	    |       ³   rN   c             C   s  t  |  j j |  j j ƒ } | j ƒ  | j d d ƒ | j ƒ  } | j } d } | | k } | st j	 d | f d | | f ƒ i t j
 | ƒ d 6t j
 | ƒ d 6d t j ƒ  k sÄ t j | ƒ rÓ t j
 | ƒ n d d	 6} d i | d 6} t t j | ƒ ƒ ‚ n  t } } } | j } d } | | k } | sÛt j	 d | f d | | f ƒ i t j
 | ƒ d 6t j
 | ƒ d 6d t j ƒ  k s˜t j | ƒ r§t j
 | ƒ n d d	 6} d i | d 6} t t j | ƒ ƒ ‚ n  t } } } | j ƒ  } d } t | ƒ }	 | |	 k } | sõt j	 d | f d | |	 f ƒ i d t j ƒ  k s[t j t ƒ rjt j
 t ƒ n d d 6t j
 |	 ƒ d 6d t j ƒ  k s¢t j | ƒ r±t j
 | ƒ n d d	 6t j
 | ƒ d 6}
 d i |
 d 6} t t j | ƒ ƒ ‚ n  t } } }	 | j ƒ  d  S) Nr9   z/response_bodyr:   r   ú.%(py2)s
{%(py2)s = %(py0)s.status
} == %(py5)sr<   r   r   r    r"   úassert %(py7)sr>   r?   ú.%(py2)s
{%(py2)s = %(py0)s.reason
} == %(py5)sr   ú0%(py0)s == %(py6)s
{%(py6)s = %(py2)s(%(py4)s)
}r   r   r   r!   úassert %(py8)sr$   )r   )rO   rP   )r   )rQ   rP   )r   )rR   rS   )r   r%   rC   rD   rE   r   rF   rG   r(   r)   r-   r*   r+   r,   r.   r/   r0   rH   r   r   rI   )r1   rJ   r   r5   rK   r3   rL   rM   r   r4   r6   r7   r
   r
   r   Útest_response_body8   s<    
	    |   	    |       ³   rT   c             C   s0  t  |  j j |  j j ƒ } | j ƒ  t d ƒ } i d d 6} | j d d | | ƒ | j ƒ  } | j } d } | | k } | s&t	 j
 d | f d | | f ƒ i t	 j | ƒ d	 6t	 j | ƒ d
 6d t j ƒ  k sã t	 j | ƒ rò t	 j | ƒ n d d 6} d i | d 6}	 t t	 j |	 ƒ ƒ ‚ n  t } } } | j } d } | | k } | sút	 j
 d | f d | | f ƒ i t	 j | ƒ d	 6t	 j | ƒ d
 6d t j ƒ  k s·t	 j | ƒ rÆt	 j | ƒ n d d 6} d i | d 6}	 t t	 j |	 ƒ ƒ ‚ n  t } } } | j ƒ  }
 d } t | ƒ } |
 | k } | st	 j
 d | f d |
 | f ƒ i d t j ƒ  k szt	 j t ƒ r‰t	 j t ƒ n d d
 6t	 j | ƒ d 6d t j ƒ  k sÁt	 j |
 ƒ rÐt	 j |
 ƒ n d d 6t	 j | ƒ d 6} d  i | d 6} t t	 j | ƒ ƒ ‚ n  t } } } | j ƒ  d  S)!Nr"   r   r   r9   z/request_headersr:   r   ú.%(py2)s
{%(py2)s = %(py0)s.status
} == %(py5)sr<   r   r   r    úassert %(py7)sr>   r?   ú.%(py2)s
{%(py2)s = %(py0)s.reason
} == %(py5)sú0%(py0)s == %(py6)s
{%(py6)s = %(py2)s(%(py4)s)
}r   r   r   r!   úassert %(py8)sr$   )r   )rU   rV   )r   )rW   rV   )r   )rX   rY   )r   r%   rC   rD   rE   r   r   rF   rG   r(   r)   r-   r*   r+   r,   r.   r/   r0   rH   r   rI   )r1   rJ   r   r   r   r5   rK   r3   rL   rM   r   r4   r6   r7   r
   r
   r   Útest_request_headersF   s@    
	    |   	    |       ³   rZ   c          	   C   s$  t  ƒ  } | j ƒ  | j t d d |  j j |  j j f ƒ ƒ x | j d  k rT qB W| j } | j } d } | | k } | s4t	 j
 d | f d | | f ƒ i t	 j | ƒ d 6t	 j | ƒ d 6d t j ƒ  k sá t	 j | ƒ rð t	 j | ƒ n d d	 6t	 j | ƒ d
 6} d i | d 6} t t	 j | ƒ ƒ ‚ n  t } } } } | j } | j } d } | | k } | s%t	 j
 d  | f d! | | f ƒ i t	 j | ƒ d 6t	 j | ƒ d 6d t j ƒ  k sÒt	 j | ƒ rát	 j | ƒ n d d	 6t	 j | ƒ d
 6} d" i | d 6} t t	 j | ƒ ƒ ‚ n  t } } } } | j j ƒ  } | j j j d ƒ }	 d }
 |	 |
 k } | st	 j
 d# | f d$ |	 |
 f ƒ i t	 j |
 ƒ d 6d t j ƒ  k sÅt	 j |	 ƒ rÔt	 j |	 ƒ n d d	 6} d% i | d 6} t t	 j | ƒ ƒ ‚ n  t } }
 d } t | ƒ } | | k } | st	 j
 d& | f d' | | f ƒ i d t j ƒ  k sxt	 j t ƒ r‡t	 j t ƒ n d d 6t	 j | ƒ d 6d t j ƒ  k s¿t	 j | ƒ rÎt	 j | ƒ n d d	 6t	 j | ƒ d
 6} d( i | d 6} t t	 j | ƒ ƒ ‚ n  t } } } d  S))Nr9   zhttp://%s:%s/response_headersr:   r   úL%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.response
}.status
} == %(py7)sr   r>   Úclientr    r!   r"   úassert %(py9)sÚpy9r?   úL%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.response
}.reason
} == %(py7)sr   r   ú%(py0)s == %(py3)sÚpy3Úaúassert %(py5)sr<   ú0%(py0)s == %(py6)s
{%(py6)s = %(py2)s(%(py4)s)
}r   r   r   úassert %(py8)sr$   )r   )r[   r]   )r   )r_   r]   )r   )r`   rc   )r   )rd   re   )r   ÚstartÚfirer   r%   rC   rD   r   rG   r(   r)   r-   r*   r+   r,   r.   r/   r0   rH   r   r   Úgetr   )r1   r\   r5   r3   Ú@py_assert6r4   rM   Ú@py_format10r   rb   Ú@py_assert2Ú@py_format4rL   r6   r7   r
   r
   r   Útest_response_headersV   sX    	
	 	    Œ   	 	    Œ      l   
    ³   rm   )Úbuiltinsr*   Ú_pytest.assertion.rewriteÚ	assertionÚrewriter(   Úhttplibr   ÚImportErrorÚhttp.clientZcircuits.sixr   Úcircuits.webr   Úcircuits.web.clientr   r   Úhelpersr   r	   r8   rN   rT   rZ   rm   r
   r
   r
   r   Ú<module>   s     