<s> from __future__ import absolute_import , unicode_literals <EOL> import os <EOL> from mock import patch <EOL> from oauthlib import signals <EOL> from oauthlib . oauth2 import LegacyApplicationClient <EOL> from ... . unittest import TestCase <EOL> @ patch ( '<STR_LIT>' , new = lambda : <NUM_LIT:1000> ) <EOL> class LegacyApplicationClientTest ( TestCase ) : <EOL> client_id = "<STR_LIT>" <EOL> scope = [ "<STR_LIT>" ] <EOL> kwargs = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> username = "<STR_LIT:foo>" <EOL> password = "<STR_LIT:bar>" <EOL> body = "<STR_LIT>" <EOL> body_up = "<STR_LIT>" % ( username , password ) <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> '<STR_LIT>' ) <EOL> token = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : scope , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> def test_request_body ( self ) : <EOL> client = LegacyApplicationClient ( self . client_id ) <EOL> body = client . prepare_request_body ( self . username , self . password , <EOL> body = self . body ) <EOL> self . assertFormBodyEqual ( body , self . body_up ) <EOL> body = client . prepare_request_body ( self . username , self . password , <EOL> body = self . body , ** self . kwargs ) <EOL> self . assertFormBodyEqual ( body , self . body_kwargs ) <EOL> def test_parse_token_response ( self ) : <EOL> client = LegacyApplicationClient ( 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:5>' <EOL> token = client . parse_request_body_response ( self . token_json , scope = "<STR_LIT>" ) <EOL> self . assertTrue ( token . scope_changed ) <EOL> scope_changes_recorded = [ ] <EOL> def record_scope_change ( sender , message , old , new ) : <EOL> scope_changes_recorded . append ( ( message , old , new ) ) <EOL> signals . scope_changed . connect ( record_scope_change ) <EOL> try : <EOL> client . parse_request_body_response ( self . token_json , scope = "<STR_LIT>" ) <EOL> self . assertEqual ( len ( scope_changes_recorded ) , <NUM_LIT:1> ) <EOL> message , old , new = scope_changes_recorded [ <NUM_LIT:0> ] <EOL> self . assertEqual ( message , '<STR_LIT>' ) <EOL> self . assertEqual ( old , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( new , [ '<STR_LIT>' ] ) <EOL> finally : <EOL> signals . scope_changed . disconnect ( record_scope_change ) <EOL> del os . environ [ '<STR_LIT>' ] </s>
