Skip to content

Commit

Permalink
make openapi more permissive and style
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkent committed Nov 16, 2023
1 parent 7ef39e2 commit 47586cb
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 23 deletions.
4 changes: 1 addition & 3 deletions store/neurostore/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ class BaseStudy(BaseMixin, db.Model):

user = relationship("User", backref=backref("base_studies"))
# retrieve versions of same study
versions = relationship(
"Study", backref=backref("base_study")
)
versions = relationship("Study", backref=backref("base_study"))

def update_has_images_and_points(self):
# Calculate has_images and has_coordinates for the BaseStudy
Expand Down
1 change: 0 additions & 1 deletion store/neurostore/models/event_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,4 @@ def get_base_study(obj):
):
continue


base_study.update_has_images_and_points()
2 changes: 1 addition & 1 deletion store/neurostore/openapi
Submodule openapi updated 1 files
+10 −8 neurostore-openapi.yml
11 changes: 6 additions & 5 deletions store/neurostore/resources/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,13 @@ def post(self):
record = (
BaseStudy.query.filter_by(**filter_params)
.options(
joinedload(BaseStudy.versions)
.options(joinedload(Study.studyset_studies)
.joinedload(StudysetStudy.studyset),
joinedload(Study.user),
joinedload(BaseStudy.versions).options(
joinedload(Study.studyset_studies).joinedload(
StudysetStudy.studyset
),
joinedload(Study.user),
),
joinedload(BaseStudy.user)
joinedload(BaseStudy.user),
)
.one_or_none()
)
Expand Down
3 changes: 2 additions & 1 deletion store/neurostore/schemas/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def _serialize(self, value, attr, obj, **ser_kwargs):
"has_images",
]
nested_schema = self.nested(
context=self.context, only=info_fields,
context=self.context,
only=info_fields,
)
return nested_schema.dump(value, many=self.many)
else:
Expand Down
4 changes: 4 additions & 0 deletions store/neurostore/tests/api/test_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def test_post_studies(auth_client, ingest_neurosynth, session):

auth_client.post("/api/studies/", data=my_study)

my_second_study = {"name": "asdfasfa", "pmid": "100000", "doi": "asdf;lds"}

auth_client.post("/api/studies/", data=my_second_study)


def test_delete_studies(auth_client, ingest_neurosynth, session):
study_db = Study.query.first()
Expand Down
20 changes: 12 additions & 8 deletions store/neurostore/tests/api/test_studysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_post_and_get_studysets(auth_client, ingest_neurosynth, session):
== post_resp.json()
)


# @add_event_listeners
def test_add_many_studies_to_studyset(auth_client, ingest_neurosynth, session):
existing_studies = Study.query.all()
Expand All @@ -38,26 +39,29 @@ def generate_doi():
# List comprehension to generate the desired structure
made_up_studies = [
{
"pmid": random.randint(100000, 999999),
"pmid": str(random.randint(100000, 999999)),
"doi": generate_doi(),
"name": ''.join(random.choices(string.ascii_letters, k=10)),
} for _ in range(1)
"name": "".join(random.choices(string.ascii_letters, k=10)),
}
for _ in range(1)
]
# create empty studyset
ss = auth_client.post("/api/studysets/", data={"name": "mixed_studyset"})

assert ss.status_code == 200

ss_id = ss.json()['id']

# combine made_up and created studies
all_studies = existing_study_ids# + made_up_studies
ss_id = ss.json()["id"]

# combine made_up and created studies
all_studies = existing_study_ids + made_up_studies

ss_update = auth_client.put(f"/api/studysets/{ss_id}", data={"studies": all_studies})
ss_update = auth_client.put(
f"/api/studysets/{ss_id}", data={"studies": all_studies}
)

assert ss_update.status_code == 200


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"]]
Expand Down
17 changes: 13 additions & 4 deletions store/neurostore/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,32 @@
"""
Record sql queries
"""
def add_event_listeners(f):


def add_event_listeners(f):
@functools.wraps(f)
def event_listeners(*args, **kwargs):
@sa.event.listens_for(_db.engine, "before_cursor_execute")
def _record_query_start(conn, cursor, statement, parameters, context, executemany):
def _record_query_start(
conn, cursor, statement, parameters, context, executemany
):
conn.info["query_start"] = datetime.now()

@sa.event.listens_for(_db.engine, "after_cursor_execute")
def _calculate_query_run_time(conn, cursor, statement, parameters, context, executemany):
def _calculate_query_run_time(
conn, cursor, statement, parameters, context, executemany
):
LOGGER.warning(f"\n\n{statement}")
LOGGER.warning("this query took {}".format(datetime.now() - conn.info["query_start"]))
LOGGER.warning(
"this query took {}".format(datetime.now() - conn.info["query_start"])
)
print("here!")

return f(*args, **kwargs)

return event_listeners


"""
Test selection arguments
"""
Expand Down

0 comments on commit 47586cb

Please sign in to comment.