<s> from __future__ import absolute_import , unicode_literals <EOL> import os <EOL> from time import time <EOL> import jwt <EOL> from mock import patch <EOL> from oauthlib . common import Request <EOL> from oauthlib . oauth2 import ServiceApplicationClient <EOL> from ... . unittest import TestCase <EOL> class ServiceApplicationClientTest ( TestCase ) : <EOL> gt = ServiceApplicationClient . grant_type <EOL> private_key = """<STR_LIT>""" <EOL> public_key = """<STR_LIT>""" <EOL> subject = '<STR_LIT>' <EOL> issuer = '<STR_LIT>' <EOL> audience = '<STR_LIT>' <EOL> client_id = "<STR_LIT>" <EOL> scope = [ "<STR_LIT>" ] <EOL> kwargs = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> body = "<STR_LIT>" <EOL> body_up = "<STR_LIT>" % gt <EOL> body_kwargs = body_up + "<STR_LIT>" <EOL> token_json = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> token = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_request_body ( self , t ) : <EOL> t . return_value = time ( ) <EOL> self . token [ '<STR_LIT>' ] = self . token [ '<STR_LIT>' ] + t . return_value <EOL> client = ServiceApplicationClient ( <EOL> self . client_id , private_key = self . private_key ) <EOL> body = client . prepare_request_body ( issuer = self . issuer , <EOL> subject = self . subject , <EOL> audience = self . audience , <EOL> body = self . body ) <EOL> r = Request ( '<STR_LIT>' , body = body ) <EOL> self . assertEqual ( r . isnot , '<STR_LIT>' ) <EOL> self . assertEqual ( r . grant_type , ServiceApplicationClient . grant_type ) <EOL> claim = jwt . decode ( r . assertion , self . public_key , audience = self . audience , algorithms = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( claim [ '<STR_LIT>' ] , self . issuer ) <EOL> self . assertEqual ( claim [ '<STR_LIT>' ] , self . subject ) <EOL> self . assertEqual ( claim [ '<STR_LIT>' ] , int ( t . return_value ) ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_parse_token_response ( self , t ) : <EOL> t . return_value = time ( ) <EOL> self . token [ '<STR_LIT>' ] = self . token [ '<STR_LIT>' ] + t . return_value <EOL> client = ServiceApplicationClient ( self . client_id ) <EOL> response = client . parse_request_body_response ( self . token_json , scope = self . scope ) <EOL> self . assertEqual ( response , self . token ) <EOL> self . assertEqual ( client . access_token , response . get ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( client . refresh_token , response . get ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( client . token_type , response . get ( "<STR_LIT>" ) ) <EOL> self . assertRaises ( Warning , client . parse_request_body_response , self . token_json , scope = "<STR_LIT>" ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:2>' <EOL> token = client . parse_request_body_response ( self . token_json , scope = "<STR_LIT>" ) <EOL> self . assertTrue ( token . scope_changed ) <EOL> del os . environ [ '<STR_LIT>' ] </s>
