Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/compose/neurosynth…
Browse files Browse the repository at this point in the history
…-frontend/tough-cookie-and-cypress/request-4.1.3
  • Loading branch information
nicoalee committed Aug 22, 2023
2 parents e09a053 + 57a9dcd commit e529785
Show file tree
Hide file tree
Showing 31 changed files with 212 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[codespell]
skip = .git,*.pdf,*.svg,*.ts,*.tsx,package-lock.json,data-*vocabulary.txt,sample_*.csv
# regexes
ignore-regex = r"\(\?i\).*\\\\1
ignore-words-list = te,fwe,connexion,zoon,covert,rime
22 changes: 22 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Codespell

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Codespell
uses: codespell-project/actions-codespell@v2
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ First, set up the main environment variables in `.env` (see: `.env.example`).

Edit the `.env` template to set the correct variables

## Initalizing backend
## Initializing backend
Create the network, build the containers, and start services using the development configuration:

docker network create nginx-proxy # if this does not already exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"default": 10000
},
"xyz": {
"description": "Tab-delimited file of coordinates from database or numpy array with XYZ coordinates. Voxels are rows and x, y, z (meaning coordinates) values are the three columnns.",
"description": "Tab-delimited file of coordinates from database or numpy array with XYZ coordinates. Voxels are rows and x, y, z (meaning coordinates) values are the three columns.",
"type": "str",
"default": null
},
Expand Down
2 changes: 1 addition & 1 deletion compose/neurosynth-frontend/src/neurostore-typescript-sdk
2 changes: 1 addition & 1 deletion compose/neurosynth_compose/openapi
Submodule openapi updated 1 files
+211 −0 neurostore-openapi.yml
2 changes: 1 addition & 1 deletion compose/neurosynth_compose/schemas/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class MetaAnalysisResultSchema(BaseSchema):

@post_load
def process_data(self, data, **kwargs):
# propogate meta-analysis id to the neurovault collection
# propagate meta-analysis id to the neurovault collection
if data.get("neurovault_collection", None):
data["neurovault_collection"]["meta_analysis_id"] = data["meta_analysis_id"]

Expand Down
2 changes: 1 addition & 1 deletion compose/neurosynth_compose/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def mock_ns(monkeysession):


"""
Session / db managment tools
Session / db management tools
"""


Expand Down
2 changes: 1 addition & 1 deletion docs/taxonomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The study is connected to the original journal it was published in.

### Functions

Studies can be created, cloned, and edited to accomodate your needs for your meta-analysis
Studies can be created, cloned, and edited to accommodate your needs for your meta-analysis

## Analysis

Expand Down
2 changes: 1 addition & 1 deletion docs/typical-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If the study does indeed use a finger tapping task, she wants to keep track of t
To the left of the study there is a plus button.
She clicks on the plus button and sees she can add the study to a "study-set".
She names the studyset "finger tapping" and adds the selected study.
When she is done reading and adding all relevent studies, she notices
When she is done reading and adding all relevant studies, she notices
that the finger tapping task typically falls under three categories:
1) right handed index finger,
2) right handed multiple fingers, and
Expand Down
2 changes: 1 addition & 1 deletion store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ First, set up the main environment variables in `.env` (see: `.env.example`).

Edit the `.env` template to set the correct variables

## Initalizing backend
## Initializing backend
Create the network, build the containers, and start services using the development configuration:

docker network create nginx-proxy
Expand Down
4 changes: 2 additions & 2 deletions store/neurostore/ingest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def ingest_neurosynth(max_rows=None):
base_study = base_studies[0]
elif len(base_studies) > 1:
source_base_study = base_studies[0]
# do not overwrite the verions column
# do not overwrite the versions column
# we want to append to this column
columns = [
c
Expand Down Expand Up @@ -484,7 +484,7 @@ def ace_ingestion_logic(coordinates_df, metadata_df, text_df):
other_base_studies = [
bs for bs in base_studies if bs.id != source_base_study.id
]
# do not overwrite the verions column
# do not overwrite the versions column
# we want to append to this column
columns = [
c.name
Expand Down
2 changes: 1 addition & 1 deletion store/neurostore/openapi
23 changes: 20 additions & 3 deletions store/neurostore/resources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions store/neurostore/tests/api/test_analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions store/neurostore/tests/api/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = [
Expand All @@ -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

Expand All @@ -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={}
Expand All @@ -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}")
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions store/neurostore/tests/api/test_base_studies.py
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions store/neurostore/tests/api/test_conditions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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):
my_condition = {"name": "ice cream", "description": "suprise, it's rocky road!"}
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
post_data = post_resp.json
Expand Down
6 changes: 3 additions & 3 deletions store/neurostore/tests/api/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion store/neurostore/tests/api/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion store/neurostore/tests/api/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions store/neurostore/tests/api/test_query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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}")
Expand All @@ -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(" ")
Expand Down
Loading

0 comments on commit e529785

Please sign in to comment.