def test_account_setup(app, example_cern, models_fixture): """Test account setup after login.""" with app.test_client() as c: ioc = app.extensions['oauthlib.client'] # Ensure remote apps have been loaded (due to before first request) resp = c.get(url_for('invenio_oauthclient.login', remote_app='cern')) assert resp.status_code == 302 example_response, example_token, example_account_info = example_cern mock_response(app.extensions['oauthlib.client'], 'cern', example_token) mock_remote_get(ioc, 'cern', example_response) resp = c.get(url_for( 'invenio_oauthclient.authorized', remote_app='cern', code='test', state=get_state('cern'))) assert resp.status_code == 302 assert resp.location == ('http://localhost/account/settings/' 'linkedaccounts/') assert len(g.identity.provides) == 7 datastore = app.extensions['invenio-accounts'].datastore user = datastore.find_user(email='*****@*****.**') assert user with app.test_request_context(): resp = disconnect_handler(ioc.remote_apps['cern']) assert resp.status_code >= 300 login_user(user) assert len(g.identity.provides) == 7 disconnect_handler(ioc.remote_apps['cern'])
def test_account_setup(app, example_cern, models_fixture): """Test account setup after login.""" with app.test_client() as c: ioc = app.extensions['oauthlib.client'] # Ensure remote apps have been loaded (due to before first request) resp = c.get(url_for('invenio_oauthclient.login', remote_app='cern')) assert resp.status_code == 302 example_response, example_token, example_account_info = example_cern mock_response(app.extensions['oauthlib.client'], 'cern', example_token) mock_remote_get(ioc, 'cern', example_response) resp = c.get( url_for('invenio_oauthclient.authorized', remote_app='cern', code='test', state=get_state('cern'))) assert resp.status_code == 302 assert resp.location == ('http://localhost/account/settings/' 'linkedaccounts/') assert len(g.identity.provides) == 7 datastore = app.extensions['invenio-accounts'].datastore user = datastore.find_user(email='*****@*****.**') assert user with app.test_request_context(): resp = disconnect_handler(ioc.remote_apps['cern']) assert resp.status_code >= 300 login_user(user) assert len(g.identity.provides) == 7 disconnect_handler(ioc.remote_apps['cern'])
def test_account_setup(app, example_cern, models_fixture): """Test account setup after login.""" with app.test_client() as c: ioc = app.extensions['oauthlib.client'] # Ensure remote apps have been loaded (due to before first request) resp = c.get(url_for('invenio_oauthclient.login', remote_app='cern')) assert resp.status_code == 302 example_response, example_token, example_account_info = example_cern mock_response(app.extensions['oauthlib.client'], 'cern', example_token) mock_remote_get(ioc, 'cern', example_response) resp = c.get( url_for('invenio_oauthclient.authorized', remote_app='cern', code='test', state=get_state('cern'))) assert resp.status_code == 302 assert resp.location == ('http://localhost/account/settings/' 'linkedaccounts/') assert len(g.identity.provides) == 7 datastore = app.extensions['invenio-accounts'].datastore user = datastore.find_user(email='*****@*****.**') user.password = hash_password("1234") assert user with app.test_request_context(): resp = disconnect_handler(ioc.remote_apps['cern']) assert resp.status_code >= 300 # simulate login (account_info fetch) g.oauth_logged_in_with_remote = ioc.remote_apps['cern'] login_user(user) assert len(g.identity.provides) == 7 logout_user() assert len(g.identity.provides) == 1 assert "cern_resource" not in session assert OAUTHCLIENT_CERN_SESSION_KEY not in session # Login again to test the disconnect handler g.oauth_logged_in_with_remote = ioc.remote_apps['cern'] login_user(user) assert len(g.identity.provides) == 7 disconnect_handler(ioc.remote_apps['cern'])