<s> import contextlib <EOL> import bookshelf <EOL> from conftest import flaky_filter <EOL> from flaky import flaky <EOL> import mock <EOL> from oauth2client . client import OAuth2Credentials <EOL> import pytest <EOL> @ pytest . fixture <EOL> def client_with_credentials ( app ) : <EOL> """<STR_LIT>""" <EOL> credentials = OAuth2Credentials ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> None , <EOL> '<STR_LIT>' , <EOL> id_token = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:email>' : '<STR_LIT>' } , <EOL> scopes = ( '<STR_LIT:email>' , '<STR_LIT>' ) ) <EOL> @ contextlib . contextmanager <EOL> def inner ( ) : <EOL> with app . test_client ( ) as client : <EOL> with client . session_transaction ( ) as session : <EOL> session [ '<STR_LIT>' ] = { '<STR_LIT:id>' : '<STR_LIT:abc>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> session [ '<STR_LIT>' ] = credentials . to_json ( ) <EOL> yield client <EOL> return inner <EOL> @ flaky ( rerun_filter = flaky_filter ) <EOL> @ pytest . mark . usefixtures ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TestAuth ( object ) : <EOL> def test_not_logged_in ( self , app ) : <EOL> with app . test_client ( ) as c : <EOL> rv = c . get ( '<STR_LIT>' ) <EOL> assert rv . status == '<STR_LIT>' <EOL> body = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> assert '<STR_LIT>' in body <EOL> def test_logged_in ( self , client_with_credentials ) : <EOL> with client_with_credentials ( ) as c : <EOL> rv = c . get ( '<STR_LIT>' ) <EOL> assert rv . status == '<STR_LIT>' <EOL> body = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> assert '<STR_LIT>' in body <EOL> def test_add_anonymous ( self , app ) : <EOL> data = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> with app . test_client ( ) as c : <EOL> rv = c . post ( '<STR_LIT>' , data = data , follow_redirects = True ) <EOL> assert rv . status == '<STR_LIT>' <EOL> body = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> assert '<STR_LIT>' in body <EOL> assert '<STR_LIT>' in body <EOL> def test_add_logged_in ( self , client_with_credentials ) : <EOL> data = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> with client_with_credentials ( ) as c : <EOL> rv = c . post ( '<STR_LIT>' , data = data , follow_redirects = True ) <EOL> assert rv . status == '<STR_LIT>' <EOL> body = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> assert '<STR_LIT>' in body <EOL> assert '<STR_LIT>' in body <EOL> def test_mine ( self , model , client_with_credentials ) : <EOL> model . create ( { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:abc>' <EOL> } ) <EOL> model . create ( { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> with client_with_credentials ( ) as c : <EOL> rv = c . get ( '<STR_LIT>' ) <EOL> assert rv . status == '<STR_LIT>' <EOL> body = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> assert '<STR_LIT>' in body <EOL> assert '<STR_LIT>' not in body <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_request_user_info ( self , HttpMock ) : <EOL> httpObj = mock . MagicMock ( ) <EOL> responseMock = mock . MagicMock ( status = <NUM_LIT:200> ) <EOL> httpObj . request = mock . MagicMock ( <EOL> return_value = ( responseMock , b'<STR_LIT>' ) ) <EOL> HttpMock . return_value = httpObj <EOL> credentials = mock . MagicMock ( ) <EOL> bookshelf . _request_user_info ( credentials ) </s>
