3
S,Z*                 @   s^  d dl mZ d dlZd dljjZd dlm	Z	 d dl
Z
d dlZd dlZyd dlmZmZ W n$ ek
r|   d dlmZmZ Y nX d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ G dd de	ZG dd de	ZG dd de	ZG dd de	Z G dd de	Z!G dd de	Z"G dd de	Z#dS )    )unicode_literalsN)TestCase)urlparseparse_qs)InvalidGrantError)OAuth2Session)facebook_compliance_fix)fitbit_compliance_fix)linkedin_compliance_fix)mailchimp_compliance_fix)weibo_compliance_fix)slack_compliance_fix)plentymarkets_compliance_fixc               @   s   e Zd Zdd Zdd ZdS )FacebookComplianceFixTestc             C   sJ   t j }|jddddid |j  | j|j tddd}t|| _d S )	Nz-https://graph.facebook.com/oauth/access_tokenzaccess_token=urlencodedzContent-Typez
text/plain)textheadersfoozhttps://i.b)redirect_uri)	requests_mockMockerpoststart
addCleanupstopr   r   session)selfmockerZfacebook r   M/Users/singingwolfboy/clones/requests-oauthlib/tests/test_compliance_fixes.pysetUp   s    zFacebookComplianceFixTest.setUpc             C   s(   | j jdddd}| j|ddd d S )Nz-https://graph.facebook.com/oauth/access_tokenbarzhttps://i.b/?code=hello)client_secretauthorization_responseZ
urlencodedBearer)access_token
token_type)r   fetch_tokenassertEqual)r   tokenr   r   r   test_fetch_access_token&   s
    z1FacebookComplianceFixTest.test_fetch_access_tokenN)__name__
__module____qualname__r   r)   r   r   r   r   r      s   r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )FitbitComplianceFixTestc             C   sV   t j | _| jjddddigid | jj  | j| jj tddd}t|| _	d S )	Nz#https://api.fitbit.com/oauth2/tokenerrorsZ	errorTypeZinvalid_grant)jsonr   zhttps://i.b)r   )
r   r   r   r   r   r   r   r   r	   r   )r   fitbitr   r   r   r   1   s    

zFitbitComplianceFixTest.setUpc             C   sP   | j t| jjdddd | jjdddid | jjddd	}| j|ddi d S )
Nz#https://api.fitbit.com/oauth2/tokenr    zhttps://i.b/?code=hello)r!   r"   r$   r0   )r/   Zgood)r!   )assertRaisesr   r   r&   r   r   r'   )r   r(   r   r   r   r)   =   s    z/FitbitComplianceFixTest.test_fetch_access_tokenc             C   st   | j t| jjdtjjddd | jjddddd | jjdtjjddd}| j	|d	 d | j	|d
 d d S )Nz#https://api.fitbit.com/oauth2/tokenr   r    )authaccessZrefresh)r$   refresh_token)r/   r$   r4   )
r1   r   r   r4   requestsr2   ZHTTPBasicAuthr   r   r'   )r   r(   r   r   r   test_refresh_tokenR   s    z*FitbitComplianceFixTest.test_refresh_tokenN)r*   r+   r,   r   r)   r6   r   r   r   r   r-   /   s   r-   c               @   s$   e Zd Zdd Zdd Zdd ZdS )LinkedInComplianceFixTestc             C   s^   t j }|jdddid |jddddd	d
 |j  | j|j tddd}t|| _d S )Nz/https://www.linkedin.com/uas/oauth2/accessTokenr$   linkedin)r/   z+https://api.linkedin.com/v1/people/~/shares   zUPDATE-3346389-595113200z6https://www.linkedin.com/updates?discuss=abc&scope=xyz)Z	updateKeyZ	updateUrl)Zstatus_coder/   r   zhttps://i.b)r   )	r   r   r   r   r   r   r   r
   r   )r   r   r8   r   r   r   r   j   s    zLinkedInComplianceFixTest.setUpc             C   s(   | j jdddd}| j|ddd d S )Nz/https://www.linkedin.com/uas/oauth2/accessTokenr    zhttps://i.b/?code=hello)r!   r"   r8   r#   )r$   r%   )r   r&   r'   )r   r(   r   r   r   r)   ~   s
    z1LinkedInComplianceFixTest.test_fetch_access_tokenc             C   sD   ddi| j _| j jd}|jj}tt|j}| j|d dg d S )Nr$   zdummy-access-tokenz+https://api.linkedin.com/v1/people/~/sharesZoauth2_access_token)	r   r(   r   requesturlr   r   queryr'   )r   responser;   r<   r   r   r   test_protected_request   s    z0LinkedInComplianceFixTest.test_protected_requestN)r*   r+   r,   r   r)   r>   r   r   r   r   r7   h   s   r7   c               @   s   e Zd Zdd Zdd ZdS )MailChimpComplianceFixTestc             C   sL   t j }|jdddd dd |j  | j|j tddd}t|| _d S )	Nz(https://login.mailchimp.com/oauth2/token	mailchimpr   )r$   
expires_inscope)r/   r   zhttps://i.b)r   )	r   r   r   r   r   r   r   r   r   )r   r   r@   r   r   r   r      s    z MailChimpComplianceFixTest.setUpc             C   sZ   | j jdddd}tj d }|jd}| j||dd | j|d	dd
 | jd| d S )Nz(https://login.mailchimp.com/oauth2/tokenr    zhttps://i.b/?code=hello)r!   r"   i  
expires_at   )placesr@   )r$   rA   rB   )r   r&   timepopassertAlmostEqualr'   assertNotIn)r   r(   approx_expires_atactual_expires_atr   r   r   r)      s    
z2MailChimpComplianceFixTest.test_fetch_access_tokenN)r*   r+   r,   r   r)   r   r   r   r   r?      s   r?   c               @   s   e Zd Zdd Zdd ZdS )WeiboComplianceFixTestc             C   sH   t j }|jdddid |j  | j|j tddd}t|| _d S )Nz)https://api.weibo.com/oauth2/access_tokenr$   weibo)r/   r   zhttps://i.b)r   )	r   r   r   r   r   r   r   r   r   )r   r   rM   r   r   r   r      s    zWeiboComplianceFixTest.setUpc             C   s(   | j jdddd}| j|ddd d S )Nz)https://api.weibo.com/oauth2/access_tokenr    zhttps://i.b/?code=hello)r!   r"   rM   r#   )r$   r%   )r   r&   r'   )r   r(   r   r   r   r)      s
    z.WeiboComplianceFixTest.test_fetch_access_tokenN)r*   r+   r,   r   r)   r   r   r   r   rL      s   rL   c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )SlackComplianceFixTestc             C   sv   t j }|jddddd x*dD ]"}|j|dd	d
dddddd q"W |j  | j|j tddd}t|| _	d S )Nz"https://slack.com/api/oauth.accesszxoxt-23984754863-2348975623103read)r$   rB   )r/   GETPOSTzhttps://slack.com/api/auth.testTzhttps://myteam.slack.com/zMy TeamcalZT12345ZU12345)okr;   ZteamuserZteam_idZuser_id)methodr;   r/   r   zhttps://i.b)r   )rP   rQ   )
r   r   r   r:   r   r   r   r   r   r   )r   r   rU   Zslackr   r   r   r      s&    
zSlackComplianceFixTest.setUpc             C   s`   ddi| j _| j jd}|jj}tt|j}| jd| |jj	}t|}| j
|d dg d S )Nr$   zdummy-access-tokenzhttps://slack.com/api/auth.testr(   )r   r(   getr:   r;   r   r   r<   rI   bodyr'   )r   r=   r;   r<   rW   datar   r   r   r>      s    z-SlackComplianceFixTest.test_protected_requestc             C   sh   ddi| j _| j jdddid}|jj}tt|j}| jd| |jj	}t|}| j
|d dg d S )Nr$   zdummy-access-tokenzhttps://slack.com/api/auth.testr(   zdifferent-token)rX   )r   r(   rV   r:   r;   r   r   r<   rI   rW   r'   )r   r=   r;   r<   rW   rX   r   r   r   )test_protected_request_override_token_get   s    z@SlackComplianceFixTest.test_protected_request_override_token_getc             C   sh   ddi| j _| j jdddid}|jj}tt|j}| jd| |jj	}t|}| j
|d dg d S )Nr$   zdummy-access-tokenzhttps://slack.com/api/auth.testr(   zdifferent-token)rX   )r   r(   r   r:   r;   r   r   r<   rI   rW   r'   )r   r=   r;   r<   rW   rX   r   r   r   *test_protected_request_override_token_post   s    zASlackComplianceFixTest.test_protected_request_override_token_postc             C   sR   ddi| j _| j jd}|jj}tt|j}| j|d dg | j	|jj
 d S )Nr$   zdummy-access-tokenz5https://slack.com/api/auth.test?token=different-tokenr(   zdifferent-token)r   r(   rV   r:   r;   r   r   r<   r'   assertIsNonerW   )r   r=   r;   r<   r   r   r   )test_protected_request_override_token_url  s    z@SlackComplianceFixTest.test_protected_request_override_token_urlN)r*   r+   r,   r   r>   rY   rZ   r\   r   r   r   r   rN      s
   rN   c               @   s   e Zd Zdd Zdd ZdS )PlentymarketsComplianceFixTestc             C   sT   t j }|jddddddddid	 |j  | j|j td
dd}t|| _d S )Nz&https://shop.plentymarkets-cloud02.com(ecUN1r8KhJewMCdLAmpHOdZ4O0ofXKB9zf6CXK61r#   iQ (iG2kBGIjcXaRE4xmTVUnv7xwxX7XMcWCHqJmFaSX)ZaccessTokenZ	tokenTypeZ	expiresInZrefreshTokenzContent-Typezapplication/json)r/   r   r   zhttps://i.b)r   )	r   r   r   r   r   r   r   r   r   )r   r   Zplentymarketsr   r   r   r     s    z$PlentymarketsComplianceFixTest.setUpc             C   sP   | j jddd}tj d }|jd}| j||dd | j|ddd	d
d d S )Nz&https://shop.plentymarkets-cloud02.comzhttps://i.b/?code=hello)r"   iQ rC   rD   )rE   r^   r#   r_   )r$   rA   r%   r4   )r   r&   rF   rG   rH   r'   )r   r(   rJ   rK   r   r   r   r)   +  s    
z6PlentymarketsComplianceFixTest.test_fetch_access_tokenN)r*   r+   r,   r   r)   r   r   r   r   r]     s   r]   )$
__future__r   builtins@py_builtins_pytest.assertion.rewrite	assertionrewrite
@pytest_arunittestr   r5   r   rF   r   r   ImportErrorurllib.parseZoauthlib.oauth2.rfc6749.errorsr   Zrequests_oauthlibr   Z"requests_oauthlib.compliance_fixesr   r	   r
   r   r   r   r   r   r-   r7   r?   rL   rN   r]   r   r   r   r   <module>   s4     9( O