

Sc              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 Z y d  d l	 m
 Z
 Wn! e k
 r d  d l
 m
 Z
 n Xd  d l Z e j d d k r e Z n e Z e  d  e  d  d e j f d	     Y  Z d S(
   i(   t   unicode_literalsN(   t   StringIOi    u   3u*   oauthlib.oauth1.rfc5849.generate_timestampu&   oauthlib.oauth1.rfc5849.generate_noncet
   OAuth1Testc             sG   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c           s     f d   } |   _  d  S(   Nc           sV   t  |  t  r! |   d  }  n  t  | t  rB |  d  } n     |  |  d  S(   Nu   utf-8(   t
   isinstancet
   bytes_typet   decodet   assertEquals(   t   at   b(   t   self(    tN   /Users/cory/Documents/Python/requests_org/requests-oauthlib/tests/test_core.pyt   converting_equals   s
    (   t   assertEqual(   R	   R   (    (   R	   R
   t   setUp   s    c         C  sD  d | _  d | _  t  d  } i  d d 6} t  d d d d	 d
 | d d d |  } |    } |   | j d	  |   | j d  |   | j	 
 d  d  t  d d d d	 d
 | d d  } |    } |   | j d	  |   | j d  |   | j	 
 d  d  |   | j	 
 d  | j	 
 d   d S(   u=   OAuth1 assumes form encoded if content type is not specified.u   abcu   1u
   client_keyu!   application/x-www-form-urlencodedu   Content-typet   methodu   POSTt   urlu   http://a.b/path?query=retaint   autht   datau   this=really&is=&+form=encodedt   headersu   Content-Typeu   AuthorizationN(   t   return_valuet   requests_oauthlibt   OAuth1t   requestst   Requestt   prepareR   R   t   bodyR   t   get(   R	   t   generate_noncet   generate_timestampt   oauthR   t   rR   R   (    (    R
   t   testFormEncoded#   s$    		c         C  s  d | _  d | _  t  d  } t  d d d d d | d	 d
  } |    } t  d d d d d |  } |    } |   | j  d  | j  d   t  d d d d d | d i  t	 d  d 6 } |    } |   | j  d  | j  d   d S(   u:   OAuth signature only depend on body if it is form encoded.u   abcu   1u
   client_keyR   u   POSTR   u   http://a.b/path?query=retainR   R   u   this really is not form encodedu   Authorizationt   filesu   hellou   testN(
   R   R   R   R   R   R   R   R   R   R   (   R	   R   R   R   R   R   R   t   c(    (    R
   t   testNonFormEncoded<   s     			c         C  s   d | _  d | _  t  d  } t j  t  } t j  | d  } t | d  k } t	 
 d d i  d d	 6d
 i  t j  | j  | f d 6d i  d d 6d | } |   | j d  Wd QXd S(   ur   
        Test we can post binary data. Should prevent regression of the
        UnicodeDecodeError issue.
        u   abcu   1u
   client_keyu   test.binu   rbu   http://httpbin.org/postR   u   thereu   hiR    u   mediaR   u   application/octet-streamu   content-typeR   i   N(   R   R   R   t   ost   patht   dirnamet   __file__t   joint   openR   t   postt   basenamet   nameR   t   status_code(   R	   R   R   R   R%   t   fnamet   fR   (    (    R
   t   testCanPostBinaryDataT   s    		"	c         C  sV   d | _  d | _  t  d  } t  d d | } |   t | j j t	   d S(   u>   
        Test that the URL is always a native string.
        u   abcu   1u
   client_keyu   http://httpbin.org/getR   N(
   R   R   R   R   R   t
   assertTrueR   t   requestR   t   str(   R	   R   R   R   R   (    (    R
   t   test_url_is_native_strf   s
    		c         C  s   d | _  d | _  t  d  } d } t  d d | d | } |   | j j  d  d	  t  d d | d | d
 i  d d 6} |   | j j  d  d  d S(   uG   
        Content type should only be guessed if none is given.
        u   abcu   1u
   client_keyu   au   http://httpbin.org/getR   R   u   Content-Typeu!   application/x-www-form-urlencodedR   u   application/jsonu   Content-typeN(	   R   R   R   R   R)   R   R1   R   R   (   R	   R   R   R   R   R   (    (    R
   t   test_content_type_overrideq   s    		c         C  sX  d t  j j f d     Y} |   t t j d   |   t j j t  j j  t  d  } |   t	 | j
 t  j j   |   t	 | j
 |   | t j _ |   t j j |  t  d  } |   t	 | j
 t  j j   |   t	 | j
 |   t  d d t  j j } |   t	 | j
 t  j j   |   t	 | j
 |   d  S(   Nt   ClientSubclassc             s   e  Z RS(    (   t   __name__t
   __module__(    (    (    R
   R5      s   u   client_classu
   client_keyt   client_class(   t   oauthlibt   oauth1t   ClientR0   t   hasattrR   R   R   R8   R   t   clientt   assertFalse(   R	   R   R   R5   t   normalt   customt
   overridden(    (    R
   t   test_register_client_class   s"    	(	   R6   R7   R   R   R"   R/   R3   R4   RB   (    (    (    R
   R      s   	
					(   t
   __future__R    t   mockt   sysR   R   R9   t   os.pathR#   t   ioR   t   ImportErrort   unittestt   versiont   bytesR   R2   t   patcht   TestCaseR   (    (    (    R
   t   <module>   s"   	