<s> from datetime import datetime , timedelta <EOL> from mock import Mock <EOL> from flask import request <EOL> from app . modules import auth <EOL> def test_loading_user_from_anonymous_request ( flask_app ) : <EOL> with flask_app . test_request_context ( '<STR_LIT:/>' ) : <EOL> assert auth . load_user_from_request ( request ) is None <EOL> def test_loading_user_from_request_with_oauth_user_cached ( flask_app ) : <EOL> mock_user = Mock ( ) <EOL> with flask_app . test_request_context ( '<STR_LIT:/>' ) : <EOL> request . oauth = Mock ( ) <EOL> request . oauth . user = mock_user <EOL> assert auth . load_user_from_request ( request ) == mock_user <EOL> del request . oauth <EOL> def test_loading_user_from_request_with_bearer_token ( flask_app , db , regular_user ) : <EOL> oauth2_bearer_token = auth . models . OAuth2Token ( <EOL> client_id = <NUM_LIT:0> , <EOL> user = regular_user , <EOL> token_type = '<STR_LIT>' , <EOL> access_token = '<STR_LIT>' , <EOL> _scopes = '<STR_LIT>' , <EOL> expires = datetime . utcnow ( ) + timedelta ( days = <NUM_LIT:1> ) , <EOL> ) <EOL> db . session . add ( oauth2_bearer_token ) <EOL> db . session . commit ( ) <EOL> with flask_app . test_request_context ( <EOL> path = '<STR_LIT:/>' , <EOL> headers = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' % oauth2_bearer_token . access_token ) , <EOL> ) <EOL> ) : <EOL> assert auth . load_user_from_request ( request ) == regular_user <EOL> db . session . delete ( oauth2_bearer_token ) <EOL> db . session . commit ( ) </s>
