

r;Vc              s  d  d l  m Z y d  d l m Z Wn! e k
 rG d  d l m Z n Xd  d l Z d  d l Z d  d l Z y d  d l	 m	 Z	 m
 Z
 Wn' e k
 r d  d l m	 Z	 m
 Z
 n Xd  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 e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d S(   i(   t   unicode_literals(   t   TestCaseN(   t   urlparset   parse_qs(   t   OAuth2Session(   t   facebook_compliance_fix(   t   linkedin_compliance_fix(   t   mailchimp_compliance_fix(   t   weibo_compliance_fix(   t   slack_compliance_fixt   FacebookComplianceFixTestc             s   e  Z d    Z d   Z RS(   c      	   C  sk   t     } |  d d d d i  d d 6|    |   | j  t d d d	 } t |  |  _ d  S(
   Nu-   https://graph.facebook.com/oauth/access_tokent   textu   access_token=urlencodedt   headersu
   text/plainu   Content-Typeu   foot   redirect_uriu   https://i.b(	   t   requests_mockt   Mockert   postt   startt
   addCleanupt   stopR   R   t   session(   t   selft   mockert   facebook(    (    tZ   /Users/cory/Documents/Python/requests_org/requests-oauthlib/tests/test_compliance_fixes.pyt   setUp   s    
c         C  s@   |  j   d d d d d } |   | i  d d 6d d	 6 d  S(
   Nu-   https://graph.facebook.com/oauth/access_tokent   client_secretu   bart   authorization_responseu   https://i.b/?code=hellou
   urlencodedu   access_tokenu   Beareru
   token_type(   R   t   fetch_tokent   assertEqual(   R   t   token(    (    R   t   test_fetch_access_token&   s
    		(   t   __name__t
   __module__R   R   (    (    (    R   R
      s   	t   LinkedInComplianceFixTestc             s#   e  Z d    Z d   Z d   Z RS(   c      	   C  s   t     } |  d d i  d d 6|  d d d d i  d d	 6d
 d 6|    |   | j  t d d d } t |  |  _ d  S(   Nu/   https://www.linkedin.com/uas/oauth2/accessTokent   jsonu   linkedinu   access_tokenu+   https://api.linkedin.com/v1/people/~/sharest   status_codei   u   UPDATE-3346389-595113200u	   updateKeyu6   https://www.linkedin.com/updates?discuss=abc&scope=xyzu	   updateUrlu   fooR   u   https://i.b(	   R   R   R   R   R   R   R   R   R   (   R   R   t   linkedin(    (    R   R   1   s    
c         C  s@   |  j   d d d d d } |   | i  d d 6d d	 6 d  S(
   Nu/   https://www.linkedin.com/uas/oauth2/accessTokenR   u   barR   u   https://i.b/?code=hellou   linkedinu   access_tokenu   Beareru
   token_type(   R   R   R   (   R   R   (    (    R   R   E   s
    		c         C  sa   i  d d 6|  j  _ |  j   d  } | j j } t t |  j  } |   | d d g  d  S(   Nu   dummy-access-tokenu   access_tokenu+   https://api.linkedin.com/v1/people/~/sharesu   oauth2_access_token(	   R   R   R   t   requestt   urlR   R   t   queryR   (   R   t   responseR'   R(   (    (    R   t   test_protected_requestM   s    		(   R    R!   R   R   R*   (    (    (    R   R"   /   s   		t   MailChimpComplianceFixTestc             s   e  Z d    Z d   Z RS(   c         C  ss   t     } |  d d i  d d 6d d 6d  d 6|    |   | j  t d d	 d
 } t |  |  _ d  S(   Nu(   https://login.mailchimp.com/oauth2/tokenR#   u	   mailchimpu   access_tokeni    u
   expires_inu   scopeu   fooR   u   https://i.b(	   R   R   R   R   R   R   R   R   R   (   R   R   t	   mailchimp(    (    R   R   Y   s    
c         C  s   |  j   d d d d d } t    d } |  d  } |   | | d d	 |   | i  d
 d 6d d 6 |   d |  d  S(   Nu(   https://login.mailchimp.com/oauth2/tokenR   u   barR   u   https://i.b/?code=helloi  u
   expires_att   placesi   u	   mailchimpu   access_tokenu
   expires_inu   scope(   R   R   t   timet   popt   assertAlmostEqualR   t   assertNotIn(   R   R   t   approx_expires_att   actual_expires_at(    (    R   R   e   s    		(   R    R!   R   R   (    (    (    R   R+   W   s   	t   WeiboComplianceFixTestc             s   e  Z d    Z d   Z RS(   c         C  se   t     } |  d d i  d d 6|    |   | j  t d d d } t |  |  _ d  S(   Nu)   https://api.weibo.com/oauth2/access_tokenR#   u   weibou   access_tokenu   fooR   u   https://i.b(	   R   R   R   R   R   R   R   R   R   (   R   R   t   weibo(    (    R   R   y   s    
c         C  s@   |  j   d d d d d } |   | i  d d 6d d	 6 d  S(
   Nu)   https://api.weibo.com/oauth2/access_tokenR   u   barR   u   https://i.b/?code=hellou   weibou   access_tokenu   Beareru
   token_type(   R   R   R   (   R   R   (    (    R   R      s
    		(   R    R!   R   R   (    (    (    R   R4   w   s   	t   SlackComplianceFixTestc             s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C  s   t     } |  d d i  d d 6d d 6xT d D]L } |  d | d	 d
 d i  t d 6d d 6d d 6d d 6d d 6d d 6 q4 W|    |   | j  t d d d } t	 |  |  _
 d  S(   Nu"   https://slack.com/api/oauth.accessR#   u   xoxt-23984754863-2348975623103u   access_tokenu   readu   scope(   u   GETu   POSTt   methodR'   u   https://slack.com/api/auth.testu   oku   https://myteam.slack.com/u   urlu   My Teamu   teamu   calu   useru   T12345u   team_idu   U12345u   user_idu   fooR   u   https://i.b(   R   R   R   R&   t   TrueR   R   R   R   R	   R   (   R   R   R7   t   slack(    (    R   R      s,     	
c         C  s   i  d d 6|  j  _ |  j   d  } | j j } t t |  j  } |   d |  | j j	 } t |  } |  
 | d d g  d  S(   Nu   dummy-access-tokenu   access_tokenu   https://slack.com/api/auth.testu   token(   R   R   t   getR&   R'   R   R   R(   R1   t   bodyR   (   R   R)   R'   R(   R;   t   data(    (    R   R*      s    		c         C  s   i  d d 6|  j  _ |  j   d d i  d d 6} | j j } t t |  j  } |   d |  | j j	 } t |  } |  
 | d d g  d  S(   Nu   dummy-access-tokenu   access_tokenu   https://slack.com/api/auth.testR<   u   different-tokenu   token(   R   R   R:   R&   R'   R   R   R(   R1   R;   R   (   R   R)   R'   R(   R;   R<   (    (    R   t)   test_protected_request_override_token_get   s    	c         C  s   i  d d 6|  j  _ |  j   d d i  d d 6} | j j } t t |  j  } |   d |  | j j	 } t |  } |  
 | d d g  d  S(   Nu   dummy-access-tokenu   access_tokenu   https://slack.com/api/auth.testR<   u   different-tokenu   token(   R   R   R   R&   R'   R   R   R(   R1   R;   R   (   R   R)   R'   R(   R;   R<   (    (    R   t*   test_protected_request_override_token_post   s    	c         C  st   i  d d 6|  j  _ |  j   d  } | j j } t t |  j  } |   | d d g  |  	 | j j
  d  S(   Nu   dummy-access-tokenu   access_tokenu5   https://slack.com/api/auth.test?token=different-tokenu   tokenu   different-token(   R   R   R:   R&   R'   R   R   R(   R   t   assertIsNoneR;   (   R   R)   R'   R(   (    (    R   t)   test_protected_request_override_token_url   s    		(   R    R!   R   R*   R=   R>   R@   (    (    (    R   R6      s
   				(   t
   __future__R    t	   unittest2R   t   ImportErrort   unittestt   requestsR   R.   R   R   t   urllib.parset   requests_oauthlibR   t"   requests_oauthlib.compliance_fixesR   R   R   R   R	   R
   R"   R+   R4   R6   (    (    (    R   t   <module>   s,   ( 