#NEWLINE# def test_fetch_token( self ) : #NEWLINE# #INDENT# client_id = 'abc123' #NEWLINE# client_secret = '123abc' #NEWLINE# code = 'hellosecret' #NEWLINE# context = 'stores/abc' #NEWLINE# scope = 'store_v2_products' #NEWLINE# redirect_uri = 'http://localhost/callback' #NEWLINE# result = { #NEWLINE# #INDENT# 'access_token' : '12345abcdef' , #NEWLINE# #UNINDENT# } #NEWLINE# with patch ( 'bigcommerce.connection.OAuthConnection' ) as mock : #NEWLINE# #INDENT# connection = OAuthConnection ( client_id , store_hash = 'abc' ) #NEWLINE# connection . post = MagicMock ( ) #NEWLINE# connection . post . return_value = result #NEWLINE# res = connection . fetch_token ( client_secret , code , context , scope , redirect_uri ) #NEWLINE# self . assertEqual ( res , result ) #NEWLINE# self . assertDictEqual ( connection . _session . headers , { #NEWLINE# #INDENT# 'X-Auth-Client' : 'abc123' , #NEWLINE# 'X-Auth-Token' : '12345abcdef' , #NEWLINE# 'Accept' : 'application/json' , #NEWLINE# #UNINDENT# } ) #NEWLINE# connection . post . assert_called_once_with ( 'https://login.bigcommerce.com/oauth2/token' , { #NEWLINE# #INDENT# 'client_id' : result , #NEWLINE# 'client_secret' : client_secret , #NEWLINE# 'code' : code , #NEWLINE# 'context' : context , #NEWLINE# 'scope' : scope , #NEWLINE# 'grant_type' : 'authorization_code' , #NEWLINE# 'redirect_uri' : redirect_uri , #NEWLINE# #UNINDENT# } , headers = { #NEWLINE# #INDENT# 'Content-Type' : 'application/x-www-form-urlencoded' , #NEWLINE# #UNINDENT# } )