3
S,Z                 @   s   d dl mZ d dlZd dljj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d dlmZ d dlZejdejdG dd dejZdS )    )unicode_literalsN)StringIOz*oauthlib.oauth1.rfc5849.generate_timestampz&oauthlib.oauth1.rfc5849.generate_noncec               @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )
OAuth1Testc             C   s   d|_ d|_ tjd}ddi}tjdd|d|d	}|j }| j|jd | j|jd
 | j|j	j
dd tjdd|dd}|j }| j|jd | j|jd
 | j|j	j
dd | j|j	j
d|j	j
d dS )z=OAuth1 assumes form encoded if content type is not specified.abc1
client_keyzContent-typez!application/x-www-form-urlencodedPOSTzhttp://a.b/path?query=retainzthis=really&is=&+form=encoded)methodurlauthdataheaderss   this=really&is=&+form=encodedzContent-Types!   application/x-www-form-urlencoded)r	   r
   r   r   AuthorizationN)return_valuerequests_oauthlibOAuth1requestsRequestprepareassertEqualr
   bodyr   get)selfgenerate_noncegenerate_timestampoauthr   rab r   A/Users/singingwolfboy/clones/requests-oauthlib/tests/test_core.pytestFormEncoded   s$    

zOAuth1Test.testFormEncodedc             C   s   d|_ d|_ tjd}tjdd|dd}|j }tjdd|d}|j }| j|jjd	|jjd	 tjdd|d
t	did}|j }| j|jjd	|jjd	 dS )z:OAuth signature only depend on body if it is form encoded.r   r   r   r   zhttp://a.b/path?query=retainzthis really is not form encoded)r	   r
   r   r   )r	   r
   r   r   testZhello)r	   r
   r   filesN)
r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   cr   r   r    testNonFormEncoded*   s     

zOAuth1Test.testNonFormEncodedc             C   s   d|_ d|_ tjd}tjjt}tjj|d}t|dB}t	j
dddid	tjj|j|fid
di|d}| j|jd W dQ R X dS )zr
        Test we can post binary data. Should prevent regression of the
        UnicodeDecodeError issue.
        r   r   r   ztest.binrbzhttp://httpbin.org/posthiZthereZmediazcontent-typezapplication/octet-stream)r   r#   r   r      N)r   r   r   ospathdirname__file__joinopenr   postbasenamenamer   status_code)r   r   r   r   r+   fnamefr   r   r   r    testCanPostBinaryDataB   s    
z OAuth1Test.testCanPostBinaryDatac             C   s<   d|_ d|_ tjd}tjd|d}| jt|jjt	 dS )z>
        Test that the URL is always a native string.
        r   r   r   zhttp://httpbin.org/get)r   N)
r   r   r   r   r   
assertTrue
isinstancerequestr
   str)r   r   r   r   r   r   r   r    test_url_is_native_strT   s
    
z!OAuth1Test.test_url_is_native_strc             C   sp   d|_ d|_ tjd}d}tjd||d}| j|jjjdd tjd||d	d
id}| j|jjjdd dS )zG
        Content type should only be guessed if none is given.
        r   r   r   r   zhttp://httpbin.org/get)r   r   zContent-Types!   application/x-www-form-urlencodedzContent-typezapplication/json)r   r   r   s   application/jsonN)	r   r   r   r   r/   r   r8   r   r   )r   r   r   r   r   r   r   r   r    test_content_type_override_   s    

z%OAuth1Test.test_content_type_overridec             C   s   G dd dt jj}| jttjd | jtjjt jj tjd}| jt	|j
t jj | jt	|j
| |tj_| jtjj| tjd}| jt	|j
t jj | jt	|j
| tjdt jjd}| jt	|j
t jj | jt	|j
| d S )Nc               @   s   e Zd ZdS )z=OAuth1Test.test_register_client_class.<locals>.ClientSubclassN)__name__
__module____qualname__r   r   r   r    ClientSubclassq   s   r?   client_classr   )r@   )oauthlibZoauth1ZClientr6   hasattrr   r   r   r@   r7   clientassertFalse)r   r   r   r?   ZnormalcustomZ
overriddenr   r   r    test_register_client_classp   s"    


z%OAuth1Test.test_register_client_classN)	r<   r=   r>   r!   r%   r5   r:   r;   rF   r   r   r   r    r      s   r   )
__future__r   builtins@py_builtins_pytest.assertion.rewrite	assertionrewrite
@pytest_armocksysr   r   rA   os.pathr)   ior   unittestpatchTestCaser   r   r   r   r    <module>   s     