<s> from __future__ import unicode_literals <EOL> import mock <EOL> import sys <EOL> import requests <EOL> import requests_oauthlib <EOL> import oauthlib <EOL> import os . path <EOL> try : <EOL> from io import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> import unittest <EOL> if sys . version [ <NUM_LIT:0> ] == '<STR_LIT:3>' : <EOL> bytes_type = bytes <EOL> else : <EOL> bytes_type = str <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> class OAuth1Test ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> def converting_equals ( a , b ) : <EOL> if isinstance ( a , bytes_type ) : <EOL> a = a . decode ( '<STR_LIT:utf-8>' ) <EOL> if isinstance ( b , bytes_type ) : <EOL> b = b . decode ( '<STR_LIT:utf-8>' ) <EOL> self . assertEquals ( a , b ) <EOL> self . assertEqual = converting_equals <EOL> def testFormEncoded ( self , generate_nonce , generate_timestamp ) : <EOL> """<STR_LIT>""" <EOL> generate_nonce . return_value = '<STR_LIT:abc>' <EOL> generate_timestamp . return_value = '<STR_LIT:1>' <EOL> oauth = requests_oauthlib . OAuth1 ( '<STR_LIT>' ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } <EOL> r = requests . Request ( method = '<STR_LIT:POST>' , url = '<STR_LIT>' , <EOL> auth = oauth , data = '<STR_LIT>' , headers = headers ) <EOL> a = r . prepare ( ) <EOL> self . assertEqual ( a . url , '<STR_LIT>' ) <EOL> self . assertEqual ( a . body , '<STR_LIT>' ) <EOL> self . assertEqual ( a . headers . get ( '<STR_LIT:Content-Type>' ) , '<STR_LIT>' ) <EOL> r = requests . Request ( method = '<STR_LIT:POST>' , url = '<STR_LIT>' , <EOL> auth = oauth , data = '<STR_LIT>' ) <EOL> b = r . prepare ( ) <EOL> self . assertEqual ( b . url , '<STR_LIT>' ) <EOL> self . assertEqual ( b . body , '<STR_LIT>' ) <EOL> self . assertEqual ( b . headers . get ( '<STR_LIT:Content-Type>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( a . headers . get ( '<STR_LIT>' ) , <EOL> b . headers . get ( '<STR_LIT>' ) ) <EOL> def testNonFormEncoded ( self , generate_nonce , generate_timestamp ) : <EOL> """<STR_LIT>""" <EOL> generate_nonce . return_value = '<STR_LIT:abc>' <EOL> generate_timestamp . return_value = '<STR_LIT:1>' <EOL> oauth = requests_oauthlib . OAuth1 ( '<STR_LIT>' ) <EOL> r = requests . Request ( method = '<STR_LIT:POST>' , url = '<STR_LIT>' , <EOL> auth = oauth , data = '<STR_LIT>' ) <EOL> a = r . prepare ( ) <EOL> r = requests . Request ( method = '<STR_LIT:POST>' , url = '<STR_LIT>' , <EOL> auth = oauth ) <EOL> b = r . prepare ( ) <EOL> self . assertEqual ( a . headers . get ( '<STR_LIT>' ) , <EOL> b . headers . get ( '<STR_LIT>' ) ) <EOL> r = requests . Request ( method = '<STR_LIT:POST>' , url = '<STR_LIT>' , <EOL> auth = oauth , files = { '<STR_LIT:test>' : StringIO ( '<STR_LIT:hello>' ) } ) <EOL> c = r . prepare ( ) <EOL> self . assertEqual ( b . headers . get ( '<STR_LIT>' ) , <EOL> c . headers . get ( '<STR_LIT>' ) ) <EOL> def testCanPostBinaryData ( self , generate_nonce , generate_timestamp ) : <EOL> """<STR_LIT>""" <EOL> generate_nonce . return_value = '<STR_LIT:abc>' <EOL> generate_timestamp . return_value = '<STR_LIT:1>' <EOL> oauth = requests_oauthlib . OAuth1 ( '<STR_LIT>' ) <EOL> dirname = os . path . dirname ( __file__ ) <EOL> fname = os . path . join ( dirname , '<STR_LIT>' ) <EOL> with open ( fname , '<STR_LIT:rb>' ) as f : <EOL> r = requests . post ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> files = { '<STR_LIT>' : ( os . path . basename ( f . name ) , f ) } , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> auth = oauth ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> def test_url_is_native_str ( self , generate_nonce , generate_timestamp ) : <EOL> """<STR_LIT>""" <EOL> generate_nonce . return_value = '<STR_LIT:abc>' <EOL> generate_timestamp . return_value = '<STR_LIT:1>' <EOL> oauth = requests_oauthlib . OAuth1 ( '<STR_LIT>' ) <EOL> r = requests . get ( '<STR_LIT>' , auth = oauth ) <EOL> self . assertTrue ( isinstance ( r . request . url , str ) ) <EOL> def test_content_type_override ( self , generate_nonce , generate_timestamp ) : <EOL> """<STR_LIT>""" <EOL> generate_nonce . return_value = '<STR_LIT:abc>' <EOL> generate_timestamp . return_value = '<STR_LIT:1>' <EOL> oauth = requests_oauthlib . OAuth1 ( '<STR_LIT>' ) <EOL> data = '<STR_LIT:a>' <EOL> r = requests . post ( '<STR_LIT>' , data = data , auth = oauth ) <EOL> self . assertEqual ( r . request . headers . get ( '<STR_LIT:Content-Type>' ) , <EOL> '<STR_LIT>' ) <EOL> r = requests . post ( '<STR_LIT>' , auth = oauth , data = data , <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } ) <EOL> self . assertEqual ( r . request . headers . get ( '<STR_LIT:Content-Type>' ) , <EOL> '<STR_LIT:application/json>' ) <EOL> def test_register_client_class ( self , generate_timestamp , generate_nonce ) : <EOL> class ClientSubclass ( oauthlib . oauth1 . Client ) : <EOL> pass <EOL> self . assertTrue ( hasattr ( requests_oauthlib . OAuth1 , '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> requests_oauthlib . OAuth1 . client_class , <EOL> oauthlib . oauth1 . Client ) <EOL> normal = requests_oauthlib . OAuth1 ( '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( normal . client , oauthlib . oauth1 . Client ) ) <EOL> self . assertFalse ( isinstance ( normal . client , ClientSubclass ) ) <EOL> requests_oauthlib . OAuth1 . client_class = ClientSubclass <EOL> self . assertEqual ( requests_oauthlib . OAuth1 . client_class , ClientSubclass ) <EOL> custom = requests_oauthlib . OAuth1 ( '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( custom . client , oauthlib . oauth1 . Client ) ) <EOL> self . assertTrue ( isinstance ( custom . client , ClientSubclass ) ) <EOL> overridden = requests_oauthlib . OAuth1 ( '<STR_LIT>' , <EOL> client_class = oauthlib . oauth1 . Client ) <EOL> self . assertTrue ( isinstance ( overridden . client , oauthlib . oauth1 . Client ) ) <EOL> self . assertFalse ( isinstance ( normal . client , ClientSubclass ) ) </s>
