<s> import abc <EOL> import datetime <EOL> import mock <EOL> from nose . tools import * <EOL> from framework . auth import Auth <EOL> from framework . exceptions import HTTPError <EOL> from website . addons . base import exceptions <EOL> from website . addons . base . testing . utils import MockFolder <EOL> from tests . factories import ProjectFactory , UserFactory <EOL> from tests . utils import mock_auth <EOL> class OAuthAddonModelTestSuiteMixinBase ( object ) : <EOL> ___metaclass__ = abc . ABCMeta <EOL> @ abc . abstractproperty <EOL> def short_name ( self ) : <EOL> pass <EOL> @ abc . abstractproperty <EOL> def full_name ( self ) : <EOL> pass <EOL> @ abc . abstractproperty <EOL> def ExternalAccountFactory ( self ) : <EOL> pass <EOL> class OAuthAddonUserSettingTestSuiteMixin ( OAuthAddonModelTestSuiteMixinBase ) : <EOL> def setUp ( self ) : <EOL> super ( OAuthAddonUserSettingTestSuiteMixin , self ) . setUp ( ) <EOL> self . node = ProjectFactory ( ) <EOL> self . user = self . node . creator <EOL> self . external_account = self . ExternalAccountFactory ( ) <EOL> self . user . external_accounts . append ( self . external_account ) <EOL> self . user . save ( ) <EOL> self . user_settings = self . user . get_or_add_addon ( self . short_name ) <EOL> def test_grant_oauth_access_no_metadata ( self ) : <EOL> self . user_settings . grant_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account , <EOL> ) <EOL> self . user_settings . save ( ) <EOL> assert_equal ( <EOL> self . user_settings . oauth_grants , <EOL> { self . node . _id : { self . external_account . _id : { } } } , <EOL> ) <EOL> def test_grant_oauth_access_metadata ( self ) : <EOL> self . user_settings . grant_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account , <EOL> metadata = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> self . user_settings . save ( ) <EOL> assert_equal ( <EOL> self . user_settings . oauth_grants , <EOL> { <EOL> self . node . _id : { <EOL> self . external_account . _id : { '<STR_LIT>' : '<STR_LIT>' } <EOL> } , <EOL> } <EOL> ) <EOL> def test_verify_oauth_access_no_metadata ( self ) : <EOL> self . user_settings . grant_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account , <EOL> ) <EOL> self . user_settings . save ( ) <EOL> assert_true ( <EOL> self . user_settings . verify_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account <EOL> ) <EOL> ) <EOL> assert_false ( <EOL> self . user_settings . verify_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . ExternalAccountFactory ( ) <EOL> ) <EOL> ) <EOL> def test_verify_oauth_access_metadata ( self ) : <EOL> self . user_settings . grant_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account , <EOL> metadata = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> self . user_settings . save ( ) <EOL> assert_true ( <EOL> self . user_settings . verify_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account , <EOL> metadata = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> ) <EOL> assert_false ( <EOL> self . user_settings . verify_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account , <EOL> metadata = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> ) <EOL> class OAuthAddonNodeSettingsTestSuiteMixin ( OAuthAddonModelTestSuiteMixinBase ) : <EOL> @ abc . abstractproperty <EOL> def NodeSettingsFactory ( self ) : <EOL> pass <EOL> @ abc . abstractproperty <EOL> def NodeSettingsClass ( self ) : <EOL> pass <EOL> @ abc . abstractproperty <EOL> def UserSettingsFactory ( self ) : <EOL> pass <EOL> def _node_settings_class_kwargs ( self , node , user_settings ) : <EOL> return { <EOL> '<STR_LIT>' : self . user_settings , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . node <EOL> } <EOL> def setUp ( self ) : <EOL> super ( OAuthAddonNodeSettingsTestSuiteMixin , self ) . setUp ( ) <EOL> self . node = ProjectFactory ( ) <EOL> self . user = self . node . creator <EOL> self . external_account = self . ExternalAccountFactory ( ) <EOL> self . user . add_addon ( self . short_name ) <EOL> self . user . external_accounts . append ( self . external_account ) <EOL> self . user . save ( ) <EOL> self . user_settings = self . user . get_addon ( self . short_name ) <EOL> self . user_settings . grant_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account , <EOL> metadata = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> self . user_settings . save ( ) <EOL> self . node_settings = self . NodeSettingsFactory ( <EOL> ** self . _node_settings_class_kwargs ( self . node , self . user_settings ) <EOL> ) <EOL> self . node_settings . external_account = self . external_account <EOL> self . node_settings . save ( ) <EOL> def tearDown ( self ) : <EOL> super ( OAuthAddonNodeSettingsTestSuiteMixin , self ) . tearDown ( ) <EOL> self . user_settings . remove ( ) <EOL> self . node_settings . remove ( ) <EOL> self . external_account . remove ( ) <EOL> self . node . remove ( ) <EOL> self . user . remove ( ) <EOL> def test_configured_true ( self ) : <EOL> assert_true ( self . node_settings . has_auth ) <EOL> assert_true ( self . node_settings . complete ) <EOL> assert_true ( self . node_settings . configured ) <EOL> def test_configured_false ( self ) : <EOL> self . node_settings . clear_settings ( ) <EOL> self . node_settings . save ( ) <EOL> assert_false ( self . node_settings . configured ) <EOL> def test_complete_true ( self ) : <EOL> assert_true ( self . node_settings . has_auth ) <EOL> assert_true ( self . node_settings . complete ) <EOL> def test_complete_has_auth_not_verified ( self ) : <EOL> with mock_auth ( self . user ) : <EOL> self . user_settings . revoke_oauth_access ( self . external_account ) <EOL> self . node_settings . reload ( ) <EOL> assert_false ( self . node_settings . has_auth ) <EOL> assert_false ( self . node_settings . complete ) <EOL> def test_complete_auth_false ( self ) : <EOL> self . node_settings . user_settings = None <EOL> assert_false ( self . node_settings . has_auth ) <EOL> assert_false ( self . node_settings . complete ) <EOL> def test_fields ( self ) : <EOL> node_settings = self . NodeSettingsClass ( user_settings = self . user_settings ) <EOL> node_settings . save ( ) <EOL> assert_true ( node_settings . user_settings ) <EOL> assert_equal ( node_settings . user_settings . owner , self . user ) <EOL> assert_true ( hasattr ( node_settings , '<STR_LIT>' ) ) <EOL> assert_true ( hasattr ( node_settings , '<STR_LIT>' ) ) <EOL> def test_folder_defaults_to_none ( self ) : <EOL> node_settings = self . NodeSettingsClass ( user_settings = self . user_settings ) <EOL> node_settings . save ( ) <EOL> assert_is_none ( node_settings . folder_id ) <EOL> def test_has_auth ( self ) : <EOL> self . user . external_accounts = [ ] <EOL> self . user_settings . reload ( ) <EOL> node = ProjectFactory ( ) <EOL> settings = self . NodeSettingsClass ( user_settings = self . user_settings , owner = node ) <EOL> settings . save ( ) <EOL> assert_false ( settings . has_auth ) <EOL> self . user . external_accounts . append ( self . external_account ) <EOL> settings . set_auth ( self . external_account , self . user ) <EOL> settings . reload ( ) <EOL> assert_true ( settings . has_auth ) <EOL> def test_clear_auth ( self ) : <EOL> node_settings = self . NodeSettingsFactory ( ) <EOL> node_settings . external_account = self . ExternalAccountFactory ( ) <EOL> node_settings . user_settings = self . UserSettingsFactory ( ) <EOL> node_settings . save ( ) <EOL> node_settings . clear_auth ( ) <EOL> assert_is_none ( node_settings . external_account ) <EOL> assert_is_none ( node_settings . user_settings ) <EOL> def test_clear_settings ( self ) : <EOL> node_settings = self . NodeSettingsFactory ( ) <EOL> node_settings . external_account = self . ExternalAccountFactory ( ) <EOL> node_settings . user_settings = self . UserSettingsFactory ( ) <EOL> node_settings . save ( ) <EOL> node_settings . clear_settings ( ) <EOL> assert_is_none ( node_settings . folder_id ) <EOL> def test_to_json ( self ) : <EOL> settings = self . node_settings <EOL> user = UserFactory ( ) <EOL> result = settings . to_json ( user ) <EOL> assert_equal ( result [ '<STR_LIT>' ] , self . short_name ) <EOL> def test_delete ( self ) : <EOL> assert_true ( self . node_settings . user_settings ) <EOL> assert_true ( self . node_settings . folder_id ) <EOL> old_logs = self . node . logs <EOL> self . node_settings . delete ( ) <EOL> self . node_settings . save ( ) <EOL> assert_is ( self . node_settings . user_settings , None ) <EOL> assert_is ( self . node_settings . folder_id , None ) <EOL> assert_true ( self . node_settings . deleted ) <EOL> assert_equal ( list ( self . node . logs ) , list ( old_logs ) ) <EOL> def test_deauthorize ( self ) : <EOL> assert_true ( self . node_settings . user_settings ) <EOL> assert_true ( self . node_settings . folder_id ) <EOL> self . node_settings . deauthorize ( auth = Auth ( self . user ) ) <EOL> self . node_settings . save ( ) <EOL> assert_is ( self . node_settings . user_settings , None ) <EOL> assert_is ( self . node_settings . folder_id , None ) <EOL> last_log = self . node . logs [ - <NUM_LIT:1> ] <EOL> assert_equal ( last_log . action , '<STR_LIT>' . format ( self . short_name ) ) <EOL> params = last_log . params <EOL> assert_in ( '<STR_LIT>' , params ) <EOL> assert_in ( '<STR_LIT>' , params ) <EOL> def test_set_folder ( self ) : <EOL> folder_id = '<STR_LIT>' <EOL> self . node_settings . set_folder ( folder_id , auth = Auth ( self . user ) ) <EOL> self . node_settings . save ( ) <EOL> assert_equal ( self . node_settings . folder_id , folder_id ) <EOL> last_log = self . node . logs [ - <NUM_LIT:1> ] <EOL> assert_equal ( last_log . action , '<STR_LIT>' . format ( self . short_name ) ) <EOL> def test_set_user_auth ( self ) : <EOL> node_settings = self . NodeSettingsFactory ( ) <EOL> user_settings = self . UserSettingsFactory ( ) <EOL> external_account = self . ExternalAccountFactory ( ) <EOL> user_settings . owner . external_accounts . append ( external_account ) <EOL> user_settings . save ( ) <EOL> node_settings . external_account = external_account <EOL> node_settings . set_auth ( external_account , user_settings . owner ) <EOL> node_settings . save ( ) <EOL> assert_true ( node_settings . has_auth ) <EOL> assert_equal ( node_settings . user_settings . _id , user_settings . _id ) <EOL> last_log = node_settings . owner . logs [ - <NUM_LIT:1> ] <EOL> assert_equal ( last_log . action , '<STR_LIT>' . format ( self . short_name ) ) <EOL> log_params = last_log . params <EOL> assert_equal ( log_params [ '<STR_LIT>' ] , node_settings . owner . _primary_key ) <EOL> assert_equal ( last_log . user , user_settings . owner ) <EOL> def test_serialize_credentials ( self ) : <EOL> self . user_settings . external_accounts [ <NUM_LIT:0> ] . oauth_key = '<STR_LIT>' <EOL> self . user_settings . save ( ) <EOL> credentials = self . node_settings . serialize_waterbutler_credentials ( ) <EOL> expected = { '<STR_LIT>' : self . node_settings . external_account . oauth_key } <EOL> assert_equal ( credentials , expected ) <EOL> def test_serialize_credentials_not_authorized ( self ) : <EOL> self . node_settings . user_settings = None <EOL> self . node_settings . save ( ) <EOL> with assert_raises ( exceptions . AddonError ) : <EOL> self . node_settings . serialize_waterbutler_credentials ( ) <EOL> def test_serialize_settings ( self ) : <EOL> settings = self . node_settings . serialize_waterbutler_settings ( ) <EOL> expected = { '<STR_LIT>' : self . node_settings . folder_id } <EOL> assert_equal ( settings , expected ) <EOL> def test_serialize_settings_not_configured ( self ) : <EOL> self . node_settings . clear_settings ( ) <EOL> self . node_settings . save ( ) <EOL> with assert_raises ( exceptions . AddonError ) : <EOL> self . node_settings . serialize_waterbutler_settings ( ) <EOL> def test_create_log ( self ) : <EOL> action = '<STR_LIT>' <EOL> path = '<STR_LIT>' <EOL> nlog = len ( self . node . logs ) <EOL> self . node_settings . create_waterbutler_log ( <EOL> auth = Auth ( user = self . user ) , <EOL> action = action , <EOL> metadata = { '<STR_LIT:path>' : path , '<STR_LIT>' : path } , <EOL> ) <EOL> self . node . reload ( ) <EOL> assert_equal ( len ( self . node . logs ) , nlog + <NUM_LIT:1> ) <EOL> assert_equal ( <EOL> self . node . logs [ - <NUM_LIT:1> ] . action , <EOL> '<STR_LIT>' . format ( self . short_name , action ) , <EOL> ) <EOL> assert_equal ( <EOL> self . node . logs [ - <NUM_LIT:1> ] . params [ '<STR_LIT:path>' ] , <EOL> path <EOL> ) <EOL> def test_after_fork_by_authorized_user ( self ) : <EOL> fork = ProjectFactory ( ) <EOL> clone , message = self . node_settings . after_fork ( <EOL> node = self . node , fork = fork , user = self . user_settings . owner <EOL> ) <EOL> assert_equal ( clone . user_settings . _id , self . user_settings . _id ) <EOL> def test_after_fork_by_unauthorized_user ( self ) : <EOL> fork = ProjectFactory ( ) <EOL> user = UserFactory ( ) <EOL> clone , message = self . node_settings . after_fork ( <EOL> node = self . node , fork = fork , user = user , <EOL> save = True <EOL> ) <EOL> assert_is ( clone . user_settings , None ) <EOL> def test_before_fork ( self ) : <EOL> node = ProjectFactory ( ) <EOL> message = self . node_settings . before_fork ( node , self . user ) <EOL> assert_true ( message ) <EOL> def test_before_remove_contributor_message ( self ) : <EOL> message = self . node_settings . before_remove_contributor ( <EOL> self . node , self . user ) <EOL> assert_true ( message ) <EOL> assert_in ( self . user . fullname , message ) <EOL> assert_in ( self . node . project_or_component , message ) <EOL> def test_after_remove_authorized_user_not_self ( self ) : <EOL> message = self . node_settings . after_remove_contributor ( <EOL> self . node , self . user_settings . owner ) <EOL> self . node_settings . save ( ) <EOL> assert_is_none ( self . node_settings . user_settings ) <EOL> assert_true ( message ) <EOL> assert_in ( "<STR_LIT>" , message ) <EOL> def test_after_remove_authorized_user_self ( self ) : <EOL> auth = Auth ( user = self . user_settings . owner ) <EOL> message = self . node_settings . after_remove_contributor ( <EOL> self . node , self . user_settings . owner , auth ) <EOL> self . node_settings . save ( ) <EOL> assert_is_none ( self . node_settings . user_settings ) <EOL> assert_true ( message ) <EOL> assert_not_in ( "<STR_LIT>" , message ) <EOL> def test_after_delete ( self ) : <EOL> self . node . remove_node ( Auth ( user = self . node . creator ) ) <EOL> self . node_settings . reload ( ) <EOL> assert_is_none ( self . node_settings . user_settings ) <EOL> assert_is_none ( self . node_settings . folder_id ) <EOL> class OAuthCitationsTestSuiteMixinBase ( OAuthAddonModelTestSuiteMixinBase ) : <EOL> @ abc . abstractproperty <EOL> def ProviderClass ( self ) : <EOL> pass <EOL> @ abc . abstractproperty <EOL> def OAuthProviderClass ( self ) : <EOL> pass <EOL> class OAuthCitationsNodeSettingsTestSuiteMixin ( OAuthAddonNodeSettingsTestSuiteMixin , OAuthCitationsTestSuiteMixinBase ) : <EOL> def setUp ( self ) : <EOL> super ( OAuthCitationsNodeSettingsTestSuiteMixin , self ) . setUp ( ) <EOL> self . user_settings . grant_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account , <EOL> metadata = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> self . user_settings . save ( ) <EOL> def test_fetch_folder_name_root ( self ) : <EOL> self . node_settings . list_id = '<STR_LIT>' <EOL> assert_equal ( <EOL> self . node_settings . fetch_folder_name , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_selected_folder_name_empty ( self ) : <EOL> self . node_settings . list_id = None <EOL> assert_equal ( <EOL> self . node_settings . fetch_folder_name , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_selected_folder_name ( self ) : <EOL> mock_folder = MockFolder ( ) <EOL> name = None <EOL> with mock . patch . object ( self . OAuthProviderClass , '<STR_LIT>' , return_value = mock_folder ) : <EOL> name = self . node_settings . fetch_folder_name <EOL> assert_equal ( <EOL> name , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_api_not_cached ( self ) : <EOL> with mock . patch . object ( self . NodeSettingsClass , '<STR_LIT>' ) as mock_api : <EOL> api = self . node_settings . api <EOL> mock_api . assert_called_once ( ) <EOL> assert_equal ( api , mock_api ( ) ) <EOL> def test_api_cached ( self ) : <EOL> with mock . patch . object ( self . NodeSettingsClass , '<STR_LIT>' ) as mock_api : <EOL> self . node_settings . _api = '<STR_LIT>' <EOL> api = self . node_settings . api <EOL> assert_false ( mock_api . called ) <EOL> assert_equal ( api , '<STR_LIT>' ) <EOL> def _node_settings_class_kwargs ( self , node , user_settings ) : <EOL> return { <EOL> '<STR_LIT>' : self . user_settings , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . node <EOL> } <EOL> def test_serialize_credentials ( self ) : <EOL> pass <EOL> def test_serialize_credentials_not_authorized ( self ) : <EOL> pass <EOL> def test_serialize_settings ( self ) : <EOL> pass <EOL> def test_serialize_settings_not_configured ( self ) : <EOL> pass <EOL> def test_create_log ( self ) : <EOL> pass <EOL> def test_set_folder ( self ) : <EOL> folder_id = '<STR_LIT>' <EOL> folder_name = '<STR_LIT>' <EOL> self . node_settings . clear_settings ( ) <EOL> self . node_settings . save ( ) <EOL> assert_is_none ( self . node_settings . list_id ) <EOL> provider = self . ProviderClass ( ) <EOL> provider . set_config ( <EOL> self . node_settings , <EOL> self . user , <EOL> folder_id , <EOL> folder_name , <EOL> auth = Auth ( user = self . user ) , <EOL> ) <EOL> assert_equal ( <EOL> self . node_settings . list_id , <EOL> '<STR_LIT>' , <EOL> ) <EOL> assert_true ( <EOL> self . user_settings . verify_oauth_access ( <EOL> node = self . node , <EOL> external_account = self . external_account , <EOL> metadata = { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> ) <EOL> log = self . node . logs [ - <NUM_LIT:1> ] <EOL> assert_equal ( log . action , '<STR_LIT>' . format ( self . short_name ) ) <EOL> assert_equal ( log . params [ '<STR_LIT>' ] , folder_id ) <EOL> assert_equal ( log . params [ '<STR_LIT>' ] , folder_name ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_remove_contributor_authorizer ( self , mock_push_status ) : <EOL> contributor = UserFactory ( ) <EOL> self . node . add_contributor ( contributor , permissions = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . node . remove_contributor ( self . node . creator , auth = Auth ( user = contributor ) ) <EOL> assert_false ( self . node_settings . has_auth ) <EOL> assert_false ( self . user_settings . verify_oauth_access ( self . node , self . external_account ) ) <EOL> def test_remove_contributor_not_authorizer ( self ) : <EOL> contributor = UserFactory ( ) <EOL> self . node . add_contributor ( contributor ) <EOL> self . node . remove_contributor ( contributor , auth = Auth ( user = self . node . creator ) ) <EOL> assert_true ( self . node_settings . has_auth ) <EOL> assert_true ( self . user_settings . verify_oauth_access ( self . node , self . external_account ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_fork_by_authorizer ( self , mock_push_status ) : <EOL> fork = self . node . fork_node ( auth = Auth ( user = self . node . creator ) ) <EOL> self . user_settings . reload ( ) <EOL> assert_true ( fork . get_addon ( self . short_name ) . has_auth ) <EOL> assert_true ( self . user_settings . verify_oauth_access ( fork , self . external_account ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_fork_not_by_authorizer ( self , mock_push_status ) : <EOL> contributor = UserFactory ( ) <EOL> self . node . add_contributor ( contributor ) <EOL> fork = self . node . fork_node ( auth = Auth ( user = contributor ) ) <EOL> assert_false ( fork . get_addon ( self . short_name ) . has_auth ) <EOL> assert_false ( self . user_settings . verify_oauth_access ( fork , self . external_account ) ) <EOL> class CitationAddonProviderTestSuiteMixin ( OAuthCitationsTestSuiteMixinBase ) : <EOL> @ abc . abstractproperty <EOL> def ApiExceptionClass ( self ) : <EOL> pass <EOL> def setUp ( self ) : <EOL> super ( CitationAddonProviderTestSuiteMixin , self ) . setUp ( ) <EOL> self . provider = self . OAuthProviderClass ( ) <EOL> @ abc . abstractmethod <EOL> def test_handle_callback ( self ) : <EOL> pass <EOL> def test_citation_lists ( self ) : <EOL> mock_client = mock . Mock ( ) <EOL> mock_folders = [ MockFolder ( ) ] <EOL> mock_list = mock . Mock ( ) <EOL> mock_list . items = mock_folders <EOL> mock_client . folders . list . return_value = mock_list <EOL> mock_client . collections . return_value = mock_folders <EOL> self . provider . _client = mock_client <EOL> mock_account = mock . Mock ( ) <EOL> self . provider . account = mock_account <EOL> res = self . provider . citation_lists ( self . ProviderClass ( ) . _extract_folder ) <EOL> assert_equal ( res [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] , mock_folders [ <NUM_LIT:0> ] . name ) <EOL> assert_equal ( res [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , mock_folders [ <NUM_LIT:0> ] . json [ '<STR_LIT:id>' ] ) <EOL> def test_client_not_cached ( self ) : <EOL> with mock . patch . object ( self . OAuthProviderClass , '<STR_LIT>' ) as mock_get_client : <EOL> mock_account = mock . Mock ( ) <EOL> mock_account . expires_at = datetime . datetime . now ( ) <EOL> self . provider . account = mock_account <EOL> self . provider . client <EOL> mock_get_client . assert_called <EOL> assert_true ( mock_get_client . called ) <EOL> def test_client_cached ( self ) : <EOL> with mock . patch . object ( self . OAuthProviderClass , '<STR_LIT>' ) as mock_get_client : <EOL> self . provider . _client = mock . Mock ( ) <EOL> res = self . provider . client <EOL> assert_equal ( res , self . provider . _client ) <EOL> assert_false ( mock_get_client . called ) <EOL> def test_has_access ( self ) : <EOL> with mock . patch . object ( self . OAuthProviderClass , '<STR_LIT>' ) as mock_get_client : <EOL> mock_client = mock . Mock ( ) <EOL> mock_error = mock . PropertyMock ( ) <EOL> mock_error . status_code = <NUM_LIT> <EOL> mock_error . text = '<STR_LIT>' <EOL> mock_client . folders . list . side_effect = self . ApiExceptionClass ( mock_error ) <EOL> mock_client . collections . side_effect = self . ApiExceptionClass ( mock_error ) <EOL> mock_get_client . return_value = mock_client <EOL> with assert_raises ( HTTPError ) as exc_info : <EOL> self . provider . client <EOL> assert_equal ( exc_info . exception . code , <NUM_LIT> ) </s>
