<s> """<STR_LIT>""" <EOL> from datetime import datetime <EOL> from facepy import ( <EOL> get_application_access_token , <EOL> get_extended_access_token , <EOL> GraphAPI <EOL> ) <EOL> from mock import patch <EOL> from nose . tools import ( <EOL> assert_equal , <EOL> assert_raises , <EOL> with_setup <EOL> ) <EOL> mock_request = None <EOL> patch = patch ( '<STR_LIT>' ) <EOL> def mock ( ) : <EOL> global mock_request <EOL> mock_request = patch . start ( ) ( ) . request <EOL> def unmock ( ) : <EOL> patch . stop ( ) <EOL> @ with_setup ( mock , unmock ) <EOL> def test_get_extended_access_token ( ) : <EOL> mock_request . return_value . status_code = <NUM_LIT:200> <EOL> mock_request . return_value . content = '<STR_LIT>' <EOL> access_token , expires_at = get_extended_access_token ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> mock_request . assert_called_with ( <EOL> '<STR_LIT:GET>' , <EOL> '<STR_LIT>' , <EOL> allow_redirects = True , <EOL> verify = True , <EOL> timeout = None , <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> assert_equal ( access_token , '<STR_LIT>' ) <EOL> assert isinstance ( expires_at , datetime ) <EOL> @ with_setup ( mock , unmock ) <EOL> def test_get_extended_access_token_v23_plus ( ) : <EOL> mock_request . return_value . status_code = <NUM_LIT:200> <EOL> mock_request . return_value . content = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> access_token , expires_at = get_extended_access_token ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> api_version = '<STR_LIT>' <EOL> ) <EOL> mock_request . assert_called_with ( <EOL> '<STR_LIT:GET>' , <EOL> '<STR_LIT>' , <EOL> allow_redirects = True , <EOL> verify = True , <EOL> timeout = None , <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> assert_equal ( access_token , '<STR_LIT>' ) <EOL> assert not expires_at <EOL> @ with_setup ( mock , unmock ) <EOL> def test_get_extended_access_token_no_expiry ( ) : <EOL> mock_request . return_value . status_code = <NUM_LIT:200> <EOL> mock_request . return_value . content = '<STR_LIT>' <EOL> access_token , expires_at = get_extended_access_token ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> mock_request . assert_called_with ( <EOL> '<STR_LIT:GET>' , <EOL> '<STR_LIT>' , <EOL> allow_redirects = True , <EOL> verify = True , <EOL> timeout = None , <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> assert_equal ( access_token , '<STR_LIT>' ) <EOL> assert expires_at is None <EOL> @ with_setup ( mock , unmock ) <EOL> def test_get_application_access_token ( ) : <EOL> mock_request . return_value . status_code = <NUM_LIT:200> <EOL> mock_request . return_value . content = '<STR_LIT>' <EOL> access_token = get_application_access_token ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> mock_request . assert_called_with ( <EOL> '<STR_LIT:GET>' , <EOL> '<STR_LIT>' , <EOL> allow_redirects = True , <EOL> verify = True , <EOL> timeout = None , <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> assert_equal ( access_token , '<STR_LIT>' ) <EOL> @ with_setup ( mock , unmock ) <EOL> def test_get_application_access_token_v23_plus ( ) : <EOL> mock_request . return_value . status_code = <NUM_LIT:200> <EOL> mock_request . return_value . content = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> access_token , expires_at = get_application_access_token ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> api_version = '<STR_LIT>' <EOL> ) <EOL> mock_request . assert_called_with ( <EOL> '<STR_LIT:GET>' , <EOL> '<STR_LIT>' , <EOL> allow_redirects = True , <EOL> verify = True , <EOL> timeout = None , <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> assert_equal ( access_token , '<STR_LIT>' ) <EOL> @ with_setup ( mock , unmock ) <EOL> def test_get_application_access_token_raises_error ( ) : <EOL> mock_request . return_value . status_code = <NUM_LIT:200> <EOL> mock_request . return_value . content = '<STR_LIT>' <EOL> assert_raises ( <EOL> GraphAPI . FacebookError , <EOL> get_application_access_token , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) </s>
