diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e0a267b45..55b47b06d 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -182,7 +182,7 @@ jobs: -e "AUTH0_AUTH_URL=${AUTH0_AUTH_URL}" \ --rm -w /neurostore \ neurostore \ - python -m pytest neurostore/tests + bash -c "python -m pytest neurostore/tests && python -m pytest --auth neurostore/tests/test_auth.py" neurosynth_compose_backend_tests: runs-on: ubuntu-latest diff --git a/store/neurostore/resources/base.py b/store/neurostore/resources/base.py index dd8fa73e5..ff9ce365e 100644 --- a/store/neurostore/resources/base.py +++ b/store/neurostore/resources/base.py @@ -32,6 +32,24 @@ from . import data as viewdata +def create_user(): + from auth0.v3.authentication.users import Users + auth = request.headers.get("Authorization", None) + token = auth.split()[1] + profile_info = Users( + current_app.config["AUTH0_BASE_URL"].removeprefix("https://") + ).userinfo(access_token=token) + + # user signed up with auth0, but has not made any queries yet... + # should have endpoint to "create user" after sign on with auth0 + current_user = User( + external_id=connexion.context["user"], + name=profile_info.get("name", "Unknown") + ) + + return current_user + + class BaseView(MethodView): _model = None _nested = {} @@ -64,9 +82,8 @@ def update_or_create(cls, data, id=None, commit=True): current_user = get_current_user() if not current_user: - # user signed up with auth0, but has not made any queries yet... - # should have endpoint to "create user" after sign on with auth0 - current_user = User(external_id=connexion.context["user"]) + current_user = create_user() + db.session.add(current_user) db.session.commit() diff --git a/store/neurostore/tests/api/test_analyses.py b/store/neurostore/tests/api/test_analyses.py index 2996a9283..4c194c838 100644 --- a/store/neurostore/tests/api/test_analyses.py +++ b/store/neurostore/tests/api/test_analyses.py @@ -3,7 +3,7 @@ from ...schemas import AnalysisSchema -def test_get_nested_and_not_nested_analyses(auth_client, ingest_neurosynth): +def test_get_nested_and_not_nested_analyses(auth_client, ingest_neurosynth, session): analysis_id = Analysis.query.first().id non_nested = auth_client.get(f"/api/analyses/{analysis_id}?nested=false") nested = auth_client.get(f"/api/analyses/{analysis_id}?nested=true") @@ -12,7 +12,7 @@ def test_get_nested_and_not_nested_analyses(auth_client, ingest_neurosynth): assert isinstance(nested.json["points"][0], dict) -def test_get_analyses(auth_client, ingest_neurosynth): +def test_get_analyses(auth_client, ingest_neurosynth, session): # List of analyses resp = auth_client.get("/api/analyses/") assert resp.status_code == 200 diff --git a/store/neurostore/tests/api/test_annotations.py b/store/neurostore/tests/api/test_annotations.py index b33d33924..7f668c15c 100644 --- a/store/neurostore/tests/api/test_annotations.py +++ b/store/neurostore/tests/api/test_annotations.py @@ -3,7 +3,7 @@ from ...models import Studyset, User -def test_post_blank_annotation(auth_client, ingest_neurosynth): +def test_post_blank_annotation(auth_client, ingest_neurosynth, session): dset = Studyset.query.first() payload = { "studyset": dset.id, @@ -17,7 +17,7 @@ def test_post_blank_annotation(auth_client, ingest_neurosynth): ) -def test_post_annotation(auth_client, ingest_neurosynth): +def test_post_annotation(auth_client, ingest_neurosynth, session): dset = Studyset.query.first() # y for x in non_flat for y in x data = [ @@ -37,7 +37,7 @@ def test_post_annotation(auth_client, ingest_neurosynth): # for some reason output is no longer valid @pytest.mark.xfail -def test_get_annotations(auth_client, ingest_neurosynth): +def test_get_annotations(auth_client, ingest_neurosynth, session): import pandas as pd from io import StringIO @@ -59,7 +59,7 @@ def test_get_annotations(auth_client, ingest_neurosynth): assert isinstance(df, pd.DataFrame) -def test_clone_annotation(auth_client, simple_neurosynth_annotation): +def test_clone_annotation(auth_client, simple_neurosynth_annotation, session): annotation_entry = simple_neurosynth_annotation resp = auth_client.post( f"/api/annotations/?source_id={annotation_entry.id}", data={} @@ -71,7 +71,7 @@ def test_clone_annotation(auth_client, simple_neurosynth_annotation): assert data["source"] == "neurostore" -def test_single_analysis_delete(auth_client, user_data): +def test_single_analysis_delete(auth_client, user_data, session): user = User.query.filter_by(name="user1").first() # get relevant studyset studysets = auth_client.get(f"/api/studysets/?user_id={user.external_id}") @@ -215,7 +215,7 @@ def test_analysis_addition_to_studyset(auth_client, session, user_data): ) -def test_mismatched_notes(auth_client, ingest_neurosynth): +def test_mismatched_notes(auth_client, ingest_neurosynth, session): dset = Studyset.query.first() # y for x in non_flat for y in x data = [ @@ -249,7 +249,7 @@ def test_mismatched_notes(auth_client, ingest_neurosynth): # test push analysis id that does not exist # Handle error better -def test_put_nonexistent_analysis(auth_client, ingest_neurosynth): +def test_put_nonexistent_analysis(auth_client, ingest_neurosynth, session): dset = Studyset.query.first() # y for x in non_flat for y in x data = [ @@ -281,7 +281,7 @@ def test_put_nonexistent_analysis(auth_client, ingest_neurosynth): ) -def test_correct_note_overwrite(auth_client, ingest_neurosynth): +def test_correct_note_overwrite(auth_client, ingest_neurosynth, session): dset = Studyset.query.first() # y for x in non_flat for y in x data = [ diff --git a/store/neurostore/tests/api/test_base_studies.py b/store/neurostore/tests/api/test_base_studies.py index 2b5f54957..ab9606596 100644 --- a/store/neurostore/tests/api/test_base_studies.py +++ b/store/neurostore/tests/api/test_base_studies.py @@ -1,7 +1,7 @@ """Test Base Study Endpoint""" -def test_flat_base_study(auth_client, ingest_neurosynth): +def test_flat_base_study(auth_client, ingest_neurosynth, session): flat_resp = auth_client.get("/api/base-studies/?flat=true") reg_resp = auth_client.get("/api/base-studies/?flat=false") @@ -11,7 +11,7 @@ def test_flat_base_study(auth_client, ingest_neurosynth): assert "versions" in reg_resp.json["results"][0] -def test_info_base_study(auth_client, ingest_neurosynth): +def test_info_base_study(auth_client, ingest_neurosynth, session): info_resp = auth_client.get("/api/base-studies/?info=true") assert info_resp.status_code == 200 diff --git a/store/neurostore/tests/api/test_conditions.py b/store/neurostore/tests/api/test_conditions.py index 79dc09efa..2c904f98a 100644 --- a/store/neurostore/tests/api/test_conditions.py +++ b/store/neurostore/tests/api/test_conditions.py @@ -1,10 +1,10 @@ -def test_get_conditions(auth_client, ingest_neurovault): +def test_get_conditions(auth_client, ingest_neurovault, session): resp = auth_client.get("/api/conditions/") assert resp.status_code == 200 assert len(resp.json["results"]) > 1 -def test_post_conditions(auth_client, ingest_neurovault): +def test_post_conditions(auth_client, ingest_neurovault, session): my_condition = {"name": "ice cream", "description": "surprise, it's rocky road!"} post_resp = auth_client.post("/api/conditions/", data=my_condition) assert post_resp.status_code == 200 diff --git a/store/neurostore/tests/api/test_crud.py b/store/neurostore/tests/api/test_crud.py index 17bc3a1d5..3ce21979f 100644 --- a/store/neurostore/tests/api/test_crud.py +++ b/store/neurostore/tests/api/test_crud.py @@ -37,7 +37,7 @@ ("points", Point, PointSchema), ], ) -def test_create(auth_client, user_data, endpoint, model, schema): +def test_create(auth_client, user_data, endpoint, model, schema, session): user = User.query.filter_by(name="user1").first() rows = model.query.filter_by(user=user).all() @@ -77,7 +77,7 @@ def test_create(auth_client, user_data, endpoint, model, schema): ("points", Point, PointSchema), ], ) -def test_read(auth_client, user_data, endpoint, model, schema): +def test_read(auth_client, user_data, endpoint, model, schema, session): user = User.query.filter_by(name="user1").first() query = True if hasattr(model, "public"): @@ -110,7 +110,7 @@ def test_read(auth_client, user_data, endpoint, model, schema): ("points", Point, PointSchema, {"space": "MNI"}), ], ) -def test_update(auth_client, user_data, endpoint, model, schema, update): +def test_update(auth_client, user_data, endpoint, model, schema, update, session): user = User.query.filter_by(name="user1").first() record = model.query.filter_by(user=user).first() diff --git a/store/neurostore/tests/api/test_images.py b/store/neurostore/tests/api/test_images.py index ccc3e75a0..bd365c884 100644 --- a/store/neurostore/tests/api/test_images.py +++ b/store/neurostore/tests/api/test_images.py @@ -2,7 +2,7 @@ from ...models import Study, Analysis, User, Image -def test_get_images(auth_client, ingest_neurovault): +def test_get_images(auth_client, ingest_neurovault, session): # List of studysets resp = auth_client.get("/api/images/") assert resp.status_code == 200 diff --git a/store/neurostore/tests/api/test_points.py b/store/neurostore/tests/api/test_points.py index 011d5b1b3..fb9e3ac65 100644 --- a/store/neurostore/tests/api/test_points.py +++ b/store/neurostore/tests/api/test_points.py @@ -4,7 +4,7 @@ from ...models import User, Analysis, Study -def test_get_points(auth_client, ingest_neurosynth): +def test_get_points(auth_client, ingest_neurosynth, session): # Get an analysis resp = auth_client.get("/api/analyses/") analysis = decode_json(resp)["results"][0] diff --git a/store/neurostore/tests/api/test_query_params.py b/store/neurostore/tests/api/test_query_params.py index a7d044602..9cc0f9c00 100644 --- a/store/neurostore/tests/api/test_query_params.py +++ b/store/neurostore/tests/api/test_query_params.py @@ -12,7 +12,7 @@ ("analyses", AnalysisSchema()), ], ) -def test_nested(auth_client, ingest_neurosynth, nested, resource_schema): +def test_nested(auth_client, ingest_neurosynth, nested, resource_schema, session): resource, schema = resource_schema resp = auth_client.get(f"/api/{resource}/?nested={nested}") fields = [ @@ -33,7 +33,7 @@ def test_nested(auth_client, ingest_neurosynth, nested, resource_schema): continue -def test_user_id(auth_client, user_data): +def test_user_id(auth_client, user_data, session): from ...resources.users import User id_ = auth_client.username @@ -43,7 +43,7 @@ def test_user_id(auth_client, user_data): assert study["user"] == user.external_id -def test_source_id(auth_client, ingest_neurosynth): +def test_source_id(auth_client, ingest_neurosynth, session): from ...resources.data import Study study = Study.query.first() @@ -53,7 +53,7 @@ def test_source_id(auth_client, ingest_neurosynth): assert post.json == get.json["results"][0] -def test_data_type(auth_client, ingest_neurosynth, ingest_neurovault): +def test_data_type(auth_client, ingest_neurosynth, ingest_neurovault, session): get_coord = auth_client.get("/api/studies/?data_type=coordinate") assert get_coord.status_code == 200 get_img = auth_client.get("/api/studies/?data_type=image") @@ -67,12 +67,12 @@ def test_data_type(auth_client, ingest_neurosynth, ingest_neurovault): ) -def test_page_size(auth_client, ingest_neurosynth): +def test_page_size(auth_client, ingest_neurosynth, session): get_page_size = auth_client.get("/api/studies/?page_size=5") assert get_page_size.status_code == 200 -def test_common_queries(auth_client, ingest_neurosynth): +def test_common_queries(auth_client, ingest_neurosynth, session): study = Study.query.filter(Study.pmid.isnot(None)).first() pmid_search = auth_client.get(f"/api/studies/?pmid={study.pmid}") @@ -83,7 +83,7 @@ def test_common_queries(auth_client, ingest_neurosynth): assert len(pmid_search.json["results"]) == len(total_search.json["results"]) -def test_multiword_queries(auth_client, ingest_neurosynth): +def test_multiword_queries(auth_client, ingest_neurosynth, session): study = Study.query.first() name = study.name word_list = name.split(" ") diff --git a/store/neurostore/tests/api/test_studies.py b/store/neurostore/tests/api/test_studies.py index 7d9fca4ca..7fa51f004 100644 --- a/store/neurostore/tests/api/test_studies.py +++ b/store/neurostore/tests/api/test_studies.py @@ -4,7 +4,7 @@ from ...models import Studyset, Study, User, Analysis -def test_create_study_as_user_and_analysis_as_bot(auth_clients): +def test_create_study_as_user_and_analysis_as_bot(auth_clients, session): # create study as user user_auth_client = next(ac for ac in auth_clients if ac.username == "user1-id") @@ -19,7 +19,7 @@ def test_create_study_as_user_and_analysis_as_bot(auth_clients): assert analysis_resp.status_code == 200 -def test_get_studies(auth_client, ingest_neurosynth, ingest_neuroquery): +def test_get_studies(auth_client, ingest_neurosynth, ingest_neuroquery, session): # List of studies resp = auth_client.get("/api/studies/?nested=true&level=group") assert resp.status_code == 200 @@ -62,7 +62,7 @@ def test_get_studies(auth_client, ingest_neurosynth, ingest_neuroquery): }, ], ) -def test_put_studies(auth_client, ingest_neurosynth, data): +def test_put_studies(auth_client, ingest_neurosynth, data, session): study_entry = Study.query.first() study_clone = auth_client.post( f"/api/studies/?source_id={study_entry.id}", data={} @@ -87,7 +87,7 @@ def test_put_studies(auth_client, ingest_neurosynth, data): assert put_resp.json["metadata"] == updated_study_entry.metadata_ -def test_clone_studies(auth_client, ingest_neurosynth, ingest_neurovault): +def test_clone_studies(auth_client, ingest_neurosynth, ingest_neurovault, session): study_entry = Study.query.filter(Study.metadata_.isnot(None)).first() resp = auth_client.post(f"/api/studies/?source_id={study_entry.id}", data={}) data = resp.json @@ -110,7 +110,7 @@ def test_clone_studies(auth_client, ingest_neurosynth, ingest_neurovault): ) -def test_private_studies(user_data, auth_clients): +def test_private_studies(user_data, auth_clients, session): from ...resources.users import User client1, client2 = auth_clients[0:2] @@ -136,7 +136,7 @@ def test_private_studies(user_data, auth_clients): assert user1_get.status_code == 200 -def test_post_studies(auth_client, ingest_neurosynth): +def test_post_studies(auth_client, ingest_neurosynth, session): payload = auth_client.get("/api/analyses/").json["results"] analyses = [analysis["id"] for analysis in payload] my_study = { @@ -164,14 +164,14 @@ def test_delete_studies(auth_client, ingest_neurosynth, session): assert Analysis.query.filter_by(id=analysis).first() is None -def test_production_study_query(auth_client, user_data): +def test_production_study_query(auth_client, user_data, session): auth_client.get( "/api/studies/?sort=name&page=1&desc=true&page_size=29999&nested=false&unique=true" ) @pytest.mark.skip("not supporting this feature anymore") -def test_getting_studysets_by_owner(auth_clients, user_data): +def test_getting_studysets_by_owner(auth_clients, user_data, session): client1 = auth_clients[0] id1 = client1.username user_studysets_db = Studyset.query.filter_by(user_id=id1).all() @@ -191,7 +191,7 @@ def test_getting_studysets_by_owner(auth_clients, user_data): @pytest.mark.parametrize("param", ["true", "false", "doi", "name", "pmid"]) -def test_get_unique_studies(auth_client, user_data, param): +def test_get_unique_studies(auth_client, user_data, param, session): # clone a study owned by the user study_entry = Study.query.filter_by(user_id=auth_client.username).first() auth_client.post(f"/api/studies/?source_id={study_entry.id}", data={}) @@ -199,7 +199,7 @@ def test_get_unique_studies(auth_client, user_data, param): assert resp.status_code == 200 -def test_cache_update(auth_client, user_data): +def test_cache_update(auth_client, user_data, session): study_entry = Study.query.filter_by(user_id=auth_client.username).first() auth_client.get(f"/api/studies/{study_entry.id}") auth_client.get(f"/api/studies/{study_entry.id}?nested=true") @@ -208,7 +208,7 @@ def test_cache_update(auth_client, user_data): auth_client.get(f"/api/studies/{study_entry.id}") -def test_post_meta_analysis(auth_client, user_data): +def test_post_meta_analysis(auth_client, user_data, session): study_data = { "name": "meta-analysis", "analyses": [ @@ -244,7 +244,7 @@ def test_post_meta_analysis(auth_client, user_data): assert resp.status_code == 200 -def test_studies_flat(auth_client, ingest_neurosynth): +def test_studies_flat(auth_client, ingest_neurosynth, session): flat_resp = auth_client.get("/api/studies/?flat=true") reg_resp = auth_client.get("/api/studies/?flat=false") diff --git a/store/neurostore/tests/api/test_studysets.py b/store/neurostore/tests/api/test_studysets.py index 3102b33ee..9947f1b10 100644 --- a/store/neurostore/tests/api/test_studysets.py +++ b/store/neurostore/tests/api/test_studysets.py @@ -1,7 +1,7 @@ from neurostore.models import Studyset, Study -def test_post_and_get_studysets(auth_client, ingest_neurosynth): +def test_post_and_get_studysets(auth_client, ingest_neurosynth, session): # create a studyset payload = auth_client.get("/api/studies/").json study_ids = [study["id"] for study in payload["results"]] @@ -21,7 +21,7 @@ def test_post_and_get_studysets(auth_client, ingest_neurosynth): ) -def test_add_study_to_studyset(auth_client, ingest_neurosynth): +def test_add_study_to_studyset(auth_client, ingest_neurosynth, session): payload = auth_client.get("/api/studies/").json study_ids = [study["id"] for study in payload["results"]] post_data = { @@ -46,7 +46,7 @@ def test_add_study_to_studyset(auth_client, ingest_neurosynth): assert len(nested_resp.json["studies"]) == len(non_nested_resp.json["studies"]) -def test_get_nested_nonnested_studysets(auth_client, ingest_neurosynth): +def test_get_nested_nonnested_studysets(auth_client, ingest_neurosynth, session): studyset_id = Studyset.query.first().id non_nested = auth_client.get(f"/api/studysets/{studyset_id}?nested=false") nested = auth_client.get(f"/api/studysets/{studyset_id}?nested=true") @@ -55,7 +55,7 @@ def test_get_nested_nonnested_studysets(auth_client, ingest_neurosynth): assert isinstance(nested.json["studies"][0], dict) -def test_hot_swap_study_in_studyset(auth_client, ingest_neurosynth): +def test_hot_swap_study_in_studyset(auth_client, ingest_neurosynth, session): # create studyset create_ss = auth_client.post("/api/studysets/", data={"name": "test"}) diff --git a/store/neurostore/tests/api/test_users.py b/store/neurostore/tests/api/test_users.py index 8e8117360..07218b68e 100644 --- a/store/neurostore/tests/api/test_users.py +++ b/store/neurostore/tests/api/test_users.py @@ -1,7 +1,7 @@ from ...models import User -def test_create_user(auth_client): +def test_create_user(auth_client, session): new_user = { "name": "fake name", "external_id": "1234", @@ -12,12 +12,12 @@ def test_create_user(auth_client): assert User.query.filter_by(external_id="1234").first() is not None -def test_list_users(auth_client): +def test_list_users(auth_client, session): resp = auth_client.get("/api/users/") assert resp.status_code == 200 -def test_list_user(auth_client): +def test_list_user(auth_client, session): user = User.query.filter_by(name="user1").first() resp = auth_client.get(f"/api/users/{user.id}") assert resp.status_code == 200 diff --git a/store/neurostore/tests/conftest.py b/store/neurostore/tests/conftest.py index fdd14f3a1..70f2864e9 100644 --- a/store/neurostore/tests/conftest.py +++ b/store/neurostore/tests/conftest.py @@ -20,19 +20,36 @@ from auth0.v3.authentication import GetToken import shortuuid + +""" +Test selection arguments +""" + + +def pytest_addoption(parser): + parser.addoption( + "--auth", + action="store_true", + default=False, + help="Run authentication tests", + ) + + +auth_test = pytest.mark.skipif( + "not config.getoption('--auth')", + reason="Only run when --auth is given", +) + """ Test fixtures for bypassing authentication """ # https://github.com/pytest-dev/pytest/issues/363#issuecomment-406536200 -@pytest.fixture(scope="session") +@pytest.fixture(scope="session", autouse=False) def monkeysession(request): - from _pytest.monkeypatch import MonkeyPatch - - mpatch = MonkeyPatch() - yield mpatch - mpatch.undo() + with pytest.MonkeyPatch.context() as mp: + yield mp def mock_decode_token(token): @@ -65,7 +82,7 @@ def mock_auth(monkeysession): @pytest.fixture(scope="session") -def app(mock_auth): +def real_app(): """Session-wide test `Flask` application.""" from ..core import app as _app from ..core import cache @@ -90,6 +107,50 @@ def app(mock_auth): ctx.pop() +@pytest.fixture(scope="session") +def real_db(real_app): + """Session-wide test database.""" + _db.init_app(real_app) + _db.create_all() + + yield _db + + _db.session.remove() + sa.orm.close_all_sessions() + _db.drop_all() + + +@pytest.fixture(scope="session") +def app(mock_auth): + """Session-wide test `Flask` application.""" + from ..core import app as _app + from ..core import cache + + if "APP_SETTINGS" not in environ: + config = "neurostore.config.TestingConfig" + else: + config = environ["APP_SETTINGS"] + if not getattr(_app, "config", None): + _app = _app._app + _app.config.from_object(config) + # _app.config["SQLALCHEMY_ECHO"] = True + # https://docs.sqlalchemy.org/en/14/errors.html#error-3o7r + _app.config["SQLALCHEMY_ENGINE_OPTIONS"] = { + "max_overflow": -1, + "pool_timeout": 5, + "pool_size": 0 + } + cache.clear() + # Establish an application context before running the tests. + ctx = _app.app_context() + ctx.push() + + yield _app + + cache.clear() + ctx.pop() + + @pytest.fixture(scope="session") def db(app): """Session-wide test database.""" @@ -103,7 +164,7 @@ def db(app): _db.drop_all() -@pytest.fixture(scope="function", autouse=True) +@pytest.fixture(scope="function") def session(db): """Creates a new db session for a test. Changes in session are rolled back""" @@ -213,11 +274,11 @@ def mock_add_users(app, db, mock_auth): @pytest.fixture(scope="function") -def add_users(app, db): +def add_users(real_app, real_db): """Adds a test user to db""" from neurostore.resources.auth import decode_token - domain = app.config["AUTH0_BASE_URL"].split("://")[1] + domain = real_app.config["AUTH0_BASE_URL"].split("://")[1] token = GetToken(domain) users = [ @@ -236,26 +297,28 @@ def add_users(app, db): name = u["name"] passw = u["password"] payload = token.login( - client_id=app.config["AUTH0_CLIENT_ID"], - client_secret=app.config["AUTH0_CLIENT_SECRET"], + client_id=real_app.config["AUTH0_CLIENT_ID"], + client_secret=real_app.config["AUTH0_CLIENT_SECRET"], username=name + "@email.com", password=passw, realm="Username-Password-Authentication", - audience=app.config["AUTH0_API_AUDIENCE"], - scope="openid", + audience=real_app.config["AUTH0_API_AUDIENCE"], + scope="openid profile email", ) token_info = decode_token(payload["access_token"]) - user = User( - name=name, - external_id=token_info["sub"], - ) - if User.query.filter_by(name=token_info["sub"]).first() is None: - db.session.add(user) - db.session.commit() + # do not add user1 into database + if name != "user1": + user = User( + name=name, + external_id=token_info["sub"], + ) + if User.query.filter_by(external_id=token_info["sub"]).first() is None: + real_db.session.add(user) + real_db.session.commit() tokens[name] = { "token": payload["access_token"], - "id": User.query.filter_by(external_id=token_info["sub"]).first().id, + "external_id": token_info["sub"], } yield tokens diff --git a/store/neurostore/tests/test_auth.py b/store/neurostore/tests/test_auth.py index 566e9a044..62a49c441 100644 --- a/store/neurostore/tests/test_auth.py +++ b/store/neurostore/tests/test_auth.py @@ -1,6 +1,8 @@ +from neurostore.tests.conftest import auth_test import pytest +@auth_test def test_decode_token(add_users): from ..resources.auth import decode_token, AuthError @@ -9,3 +11,18 @@ def test_decode_token(add_users): for user in add_users.values(): decode_token(user["token"]) + + +@auth_test +def test_creating_new_user_on_db(add_users): + from .request_utils import Client + + token_info = add_users + user_name = "user1" # user1 was not entered into database + + client = Client( + token=token_info[user_name]["token"], + username=token_info[user_name]["external_id"] + ) + + client.post("/api/studies/", data={"name": "my study"}) diff --git a/store/neurostore/tests/test_ingestion.py b/store/neurostore/tests/test_ingestion.py index 2d0ad3e89..9488e1b74 100644 --- a/store/neurostore/tests/test_ingestion.py +++ b/store/neurostore/tests/test_ingestion.py @@ -1,5 +1,5 @@ """Test Ingestion Functions""" -def test_ingest_ace(ingest_neurosynth, ingest_ace): +def test_ingest_ace(ingest_neurosynth, ingest_ace, session): pass