From bc1ccef71906ad992abaa7aa2972c4d83da87e32 Mon Sep 17 00:00:00 2001 From: James Kent Date: Fri, 17 Jan 2025 16:27:08 -0600 Subject: [PATCH] style with black --- store/neurostore/ingest/extracted_features.py | 10 ++- store/neurostore/models/data.py | 5 +- store/neurostore/resources/__init__.py | 1 + store/neurostore/resources/pipeline.py | 27 ++++-- store/neurostore/schemas/pipeline.py | 9 +- .../tests/api/test_pipeline_resources.py | 90 +++++++++++++------ store/neurostore/tests/conftest.py | 4 +- store/neurostore/tests/test_models.py | 1 + store/neurostore/tests/test_schemas.py | 40 +++++---- 9 files changed, 132 insertions(+), 55 deletions(-) diff --git a/store/neurostore/ingest/extracted_features.py b/store/neurostore/ingest/extracted_features.py index 7a2cfc4a..43b7c2c6 100644 --- a/store/neurostore/ingest/extracted_features.py +++ b/store/neurostore/ingest/extracted_features.py @@ -36,9 +36,13 @@ def ingest_feature(feature_directory): name=pipeline_info["name"], version=pipeline_info["version"], description=pipeline_info.get("description"), - study_dependent=True if pipeline_info.get("type", False) == "dependent" else False, - ace_compatible="ace" in pipeline_info.get("arguments", {}).get("input_sources", []), - pubget_compatible="pubget" in pipeline_info.get("arguments", {}).get("input_sources", []), + study_dependent=( + True if pipeline_info.get("type", False) == "dependent" else False + ), + ace_compatible="ace" + in pipeline_info.get("arguments", {}).get("input_sources", []), + pubget_compatible="pubget" + in pipeline_info.get("arguments", {}).get("input_sources", []), derived_from=pipeline_info.get("derived_from", None), ) db.session.add(pipeline) diff --git a/store/neurostore/models/data.py b/store/neurostore/models/data.py index 8047e367..f0f297e5 100644 --- a/store/neurostore/models/data.py +++ b/store/neurostore/models/data.py @@ -596,7 +596,9 @@ class PipelineRunResultVote(BaseMixin, db.Model): __tablename__ = "pipeline_run_result_votes" run_result_id = db.Column( - db.Text, db.ForeignKey("pipeline_run_results.id", ondelete="CASCADE"), index=True + db.Text, + db.ForeignKey("pipeline_run_results.id", ondelete="CASCADE"), + index=True, ) user_id = db.Column(db.Text, db.ForeignKey("users.external_id"), index=True) accurate = db.Column(db.Boolean) @@ -605,6 +607,7 @@ class PipelineRunResultVote(BaseMixin, db.Model): ) user = relationship("User", backref=backref("votes", passive_deletes=True)) + # from . import event_listeners # noqa E402 # del event_listeners diff --git a/store/neurostore/resources/__init__.py b/store/neurostore/resources/__init__.py index 9ff44169..dabe4a01 100644 --- a/store/neurostore/resources/__init__.py +++ b/store/neurostore/resources/__init__.py @@ -22,6 +22,7 @@ PipelineRunResultsView, PipelineRunResultVotesView, ) + __all__ = [ "StudysetsView", "AnnotationsView", diff --git a/store/neurostore/resources/pipeline.py b/store/neurostore/resources/pipeline.py index 828f16da..c5d3d62f 100644 --- a/store/neurostore/resources/pipeline.py +++ b/store/neurostore/resources/pipeline.py @@ -1,9 +1,22 @@ from flask import request, jsonify -from neurostore.models.data import Pipeline, PipelineConfig, PipelineRun, PipelineRunResult, PipelineRunResultVote -from neurostore.schemas.pipeline import PipelineSchema, PipelineConfigSchema, PipelineRunSchema, PipelineRunResultSchema, PipelineRunResultVoteSchema +from neurostore.models.data import ( + Pipeline, + PipelineConfig, + PipelineRun, + PipelineRunResult, + PipelineRunResultVote, +) +from neurostore.schemas.pipeline import ( + PipelineSchema, + PipelineConfigSchema, + PipelineRunSchema, + PipelineRunResultSchema, + PipelineRunResultVoteSchema, +) from neurostore.database import db from .base import ObjectView, ListView + class PipelinesView(ObjectView, ListView): model = Pipeline schema = PipelineSchema @@ -34,7 +47,7 @@ def delete(self, id): pipeline = self.model.query.get(id) db.session.delete(pipeline) db.session.commit() - return '', 204 + return "", 204 class PipelineConfigsView(ObjectView, ListView): @@ -67,7 +80,7 @@ def delete(self, id): pipeline_config = self.model.query.get(id) db.session.delete(pipeline_config) db.session.commit() - return '', 204 + return "", 204 class PipelineRunsView(ObjectView, ListView): @@ -100,7 +113,7 @@ def delete(self, pipeline_run_id): pipeline_run = self.model.query.get(pipeline_run_id) db.session.delete(pipeline_run) db.session.commit() - return '', 204 + return "", 204 class PipelineRunResultsView(ObjectView, ListView): @@ -133,7 +146,7 @@ def delete(self, pipeline_run_result_id): pipeline_run_result = self.model.query.get(pipeline_run_result_id) db.session.delete(pipeline_run_result) db.session.commit() - return '', 204 + return "", 204 class PipelineRunResultVotesView(ObjectView, ListView): @@ -166,4 +179,4 @@ def delete(self, pipeline_run_result_vote_id): pipeline_run_result_vote = self.model.query.get(pipeline_run_result_vote_id) db.session.delete(pipeline_run_result_vote) db.session.commit() - return '', 204 + return "", 204 diff --git a/store/neurostore/schemas/pipeline.py b/store/neurostore/schemas/pipeline.py index e3d2a186..f1ea8a93 100644 --- a/store/neurostore/schemas/pipeline.py +++ b/store/neurostore/schemas/pipeline.py @@ -1,5 +1,12 @@ from marshmallow import Schema, fields, post_load -from neurostore.models.data import Pipeline, PipelineConfig, PipelineRun, PipelineRunResult, PipelineRunResultVote +from neurostore.models.data import ( + Pipeline, + PipelineConfig, + PipelineRun, + PipelineRunResult, + PipelineRunResultVote, +) + class PipelineSchema(Schema): id = fields.String(dump_only=True) diff --git a/store/neurostore/tests/api/test_pipeline_resources.py b/store/neurostore/tests/api/test_pipeline_resources.py index ed42964c..136f9172 100644 --- a/store/neurostore/tests/api/test_pipeline_resources.py +++ b/store/neurostore/tests/api/test_pipeline_resources.py @@ -1,9 +1,23 @@ import pytest from flask import url_for -from neurostore.models.data import Pipeline, PipelineConfig, PipelineRun, PipelineRunResult, PipelineRunResultVote, BaseStudy -from neurostore.schemas.pipeline import PipelineSchema, PipelineConfigSchema, PipelineRunSchema, PipelineRunResultSchema, PipelineRunResultVoteSchema +from neurostore.models.data import ( + Pipeline, + PipelineConfig, + PipelineRun, + PipelineRunResult, + PipelineRunResultVote, + BaseStudy, +) +from neurostore.schemas.pipeline import ( + PipelineSchema, + PipelineConfigSchema, + PipelineRunSchema, + PipelineRunResultSchema, + PipelineRunResultVoteSchema, +) from neurostore.database import db + @pytest.fixture def pipeline(session, pipeline_payload): pipeline = Pipeline(**pipeline_payload) @@ -11,6 +25,7 @@ def pipeline(session, pipeline_payload): session.commit() return pipeline + @pytest.fixture def pipeline_config(session, pipeline_config_payload): pipeline_config = PipelineConfig(**pipeline_config_payload) @@ -18,6 +33,7 @@ def pipeline_config(session, pipeline_config_payload): session.commit() return pipeline_config + @pytest.fixture def pipeline_run(session, pipeline_run_payload): pipeline_run = PipelineRun(**pipeline_run_payload) @@ -25,6 +41,7 @@ def pipeline_run(session, pipeline_run_payload): session.commit() return pipeline_run + @pytest.fixture def pipeline_run_result(session, pipeline_run_result_payload): pipeline_run_result = PipelineRunResult(**pipeline_run_result_payload) @@ -42,24 +59,23 @@ def pipeline_payload(): "study_dependent": True, "ace_compatible": False, "pubget_compatible": True, - "derived_from": "Base Pipeline" + "derived_from": "Base Pipeline", } + @pytest.fixture def pipeline_config_payload(pipeline): return { "pipeline_id": pipeline.id, "config": {"param1": "value1", "param2": "value2"}, - "config_hash": "abc123" + "config_hash": "abc123", } + @pytest.fixture def pipeline_run_payload(pipeline, pipeline_config): - return { - "pipeline_id": pipeline.id, - "config_id": pipeline_config.id, - "run_index": 1 - } + return {"pipeline_id": pipeline.id, "config_id": pipeline_config.id, "run_index": 1} + @pytest.fixture def pipeline_run_result_payload(pipeline_run): @@ -71,135 +87,157 @@ def pipeline_run_result_payload(pipeline_run): "base_study_id": base_study.id, "date_executed": "2023-01-01T00:00:00Z", "data": {"result": "success"}, - "file_inputs": {"input1": "file1"} + "file_inputs": {"input1": "file1"}, } def test_create_pipeline(auth_client, pipeline_payload): - response = auth_client.post('/api/pipelines/', data=pipeline_payload) + response = auth_client.post("/api/pipelines/", data=pipeline_payload) assert response.status_code == 201 data = response.json() assert data["name"] == pipeline_payload["name"] + def test_get_pipeline(auth_client, pipeline_payload, session): pipeline = Pipeline(**pipeline_payload) db.session.add(pipeline) db.session.commit() - response = auth_client.get(f'/api/pipelines/{pipeline.id}') + response = auth_client.get(f"/api/pipelines/{pipeline.id}") assert response.status_code == 200 data = response.json() assert data["name"] == pipeline_payload["name"] + def test_update_pipeline(auth_client, pipeline_payload, session): pipeline = Pipeline(**pipeline_payload) db.session.add(pipeline) db.session.commit() updated_payload = {"name": "Updated Pipeline"} - response = auth_client.put(f'/api/pipelines/{pipeline.id}', data=updated_payload) + response = auth_client.put(f"/api/pipelines/{pipeline.id}", data=updated_payload) assert response.status_code == 200 data = response.json() assert data["name"] == "Updated Pipeline" + def test_delete_pipeline(auth_client, pipeline_payload): pipeline = Pipeline(**pipeline_payload) db.session.add(pipeline) db.session.commit() - response = auth_client.delete(f'/api/pipelines/{pipeline.id}') + response = auth_client.delete(f"/api/pipelines/{pipeline.id}") assert response.status_code == 204 def test_create_pipeline_config(auth_client, pipeline_config_payload, session): - response = auth_client.post('/api/pipeline-configs/', data=pipeline_config_payload) + response = auth_client.post("/api/pipeline-configs/", data=pipeline_config_payload) assert response.status_code == 201 data = response.json() assert data["config"] == pipeline_config_payload["config"] + def test_get_pipeline_config(auth_client, pipeline_config_payload, session): pipeline_config = PipelineConfig(**pipeline_config_payload) db.session.add(pipeline_config) db.session.commit() - response = auth_client.get(f'/api/pipeline-configs/{pipeline_config.id}') + response = auth_client.get(f"/api/pipeline-configs/{pipeline_config.id}") assert response.status_code == 200 data = response.json() assert data["config"] == pipeline_config_payload["config"] + def test_update_pipeline_config(auth_client, pipeline_config_payload, session): pipeline_config = PipelineConfig(**pipeline_config_payload) db.session.add(pipeline_config) db.session.commit() updated_payload = {"config": {"param1": "new_value"}} - response = auth_client.put(f'/api/pipeline-configs/{pipeline_config.id}', data=updated_payload) + response = auth_client.put( + f"/api/pipeline-configs/{pipeline_config.id}", data=updated_payload + ) assert response.status_code == 200 data = response.json() assert data["config"] == {"param1": "new_value"} + def test_delete_pipeline_config(auth_client, pipeline_config_payload, session): pipeline_config = PipelineConfig(**pipeline_config_payload) db.session.add(pipeline_config) db.session.commit() - response = auth_client.delete(f'/api/pipeline-configs/{pipeline_config.id}') + response = auth_client.delete(f"/api/pipeline-configs/{pipeline_config.id}") assert response.status_code == 204 + def test_create_pipeline_run(auth_client, pipeline_run_payload, session): - response = auth_client.post('/api/pipeline-runs/', data=pipeline_run_payload) + response = auth_client.post("/api/pipeline-runs/", data=pipeline_run_payload) assert response.status_code == 201 data = response.json() assert data["pipeline_id"] == pipeline_run_payload["pipeline_id"] + def test_get_pipeline_run(auth_client, pipeline_run_payload, session): pipeline_run = PipelineRun(**pipeline_run_payload) db.session.add(pipeline_run) db.session.commit() - response = auth_client.get(f'/api/pipeline-runs/{pipeline_run.id}') + response = auth_client.get(f"/api/pipeline-runs/{pipeline_run.id}") assert response.status_code == 200 data = response.json() assert data["pipeline_id"] == pipeline_run_payload["pipeline_id"] + def test_update_pipeline_run(auth_client, pipeline_run_payload, session): pipeline_run = PipelineRun(**pipeline_run_payload) db.session.add(pipeline_run) db.session.commit() updated_payload = {"run_index": 2} - response = auth_client.put(f'/api/pipeline-runs/{pipeline_run.id}', data=updated_payload) + response = auth_client.put( + f"/api/pipeline-runs/{pipeline_run.id}", data=updated_payload + ) assert response.status_code == 200 data = response.json() assert data["run_index"] == 2 + def test_delete_pipeline_run(auth_client, pipeline_run_payload, session): pipeline_run = PipelineRun(**pipeline_run_payload) db.session.add(pipeline_run) db.session.commit() - response = auth_client.delete(f'/api/pipeline-runs/{pipeline_run.id}') + response = auth_client.delete(f"/api/pipeline-runs/{pipeline_run.id}") assert response.status_code == 204 + def test_create_pipeline_run_result(auth_client, pipeline_run_result_payload, session): - response = auth_client.post('/api/pipeline-run-results/', data=pipeline_run_result_payload) + response = auth_client.post( + "/api/pipeline-run-results/", data=pipeline_run_result_payload + ) assert response.status_code == 201 data = response.json() assert data["run_id"] == pipeline_run_result_payload["run_id"] + def test_get_pipeline_run_result(auth_client, pipeline_run_result_payload, session): pipeline_run_result = PipelineRunResult(**pipeline_run_result_payload) db.session.add(pipeline_run_result) db.session.commit() - response = auth_client.get(f'/api/pipeline-run-results/{pipeline_run_result.id}') + response = auth_client.get(f"/api/pipeline-run-results/{pipeline_run_result.id}") assert response.status_code == 200 data = response.json() assert data["run_id"] == pipeline_run_result_payload["run_id"] + def test_update_pipeline_run_result(auth_client, pipeline_run_result_payload, session): pipeline_run_result = PipelineRunResult(**pipeline_run_result_payload) db.session.add(pipeline_run_result) db.session.commit() updated_payload = {"data": {"result": "failure"}} - response = auth_client.put(f'/api/pipeline-run-results/{pipeline_run_result.id}', data=updated_payload) + response = auth_client.put( + f"/api/pipeline-run-results/{pipeline_run_result.id}", data=updated_payload + ) assert response.status_code == 200 data = response.json() assert data["data"] == {"result": "failure"} + def test_delete_pipeline_run_result(auth_client, pipeline_run_result_payload, session): pipeline_run_result = PipelineRunResult(**pipeline_run_result_payload) db.session.add(pipeline_run_result) db.session.commit() - response = auth_client.delete(f'/api/pipeline-run-results/{pipeline_run_result.id}') + response = auth_client.delete(f"/api/pipeline-run-results/{pipeline_run_result.id}") assert response.status_code == 204 diff --git a/store/neurostore/tests/conftest.py b/store/neurostore/tests/conftest.py index b292e2b3..aff5ad89 100644 --- a/store/neurostore/tests/conftest.py +++ b/store/neurostore/tests/conftest.py @@ -602,8 +602,8 @@ def create_demographic_features(session, ingest_neurosynth, tmp_path): "derived_from": None, "arguments": { "parallel": 1, - "inputs": ['text'], - "input_sources": ['pubget'], + "inputs": ["text"], + "input_sources": ["pubget"], }, } with open(output_dir / "pipeline_info.json", "w") as f: diff --git a/store/neurostore/tests/test_models.py b/store/neurostore/tests/test_models.py index 08553906..9305f095 100644 --- a/store/neurostore/tests/test_models.py +++ b/store/neurostore/tests/test_models.py @@ -46,6 +46,7 @@ def test_Image(): def test_Studyset(): Studyset() + def test_Pipeline(): Pipeline() diff --git a/store/neurostore/tests/test_schemas.py b/store/neurostore/tests/test_schemas.py index 094fcf02..6d477ece 100644 --- a/store/neurostore/tests/test_schemas.py +++ b/store/neurostore/tests/test_schemas.py @@ -41,9 +41,23 @@ def test_compare_dataset_with_snapshot(ingest_neurosynth): assert marshmallow_ss == quick_ss + import pytest -from neurostore.schemas.pipeline import PipelineSchema, PipelineConfigSchema, PipelineRunSchema, PipelineRunResultSchema, PipelineRunResultVoteSchema -from neurostore.models.data import Pipeline, PipelineConfig, PipelineRun, PipelineRunResult, PipelineRunResultVote +from neurostore.schemas.pipeline import ( + PipelineSchema, + PipelineConfigSchema, + PipelineRunSchema, + PipelineRunResultSchema, + PipelineRunResultVoteSchema, +) +from neurostore.models.data import ( + Pipeline, + PipelineConfig, + PipelineRun, + PipelineRunResult, + PipelineRunResultVote, +) + def test_PipelineSchema(): payload = { @@ -53,7 +67,7 @@ def test_PipelineSchema(): "study_dependent": True, "ace_compatible": False, "pubget_compatible": True, - "derived_from": "Base Pipeline" + "derived_from": "Base Pipeline", } schema = PipelineSchema() result = schema.load(payload) @@ -65,11 +79,12 @@ def test_PipelineSchema(): assert result.pubget_compatible is True assert result.derived_from == "Base Pipeline" + def test_PipelineConfigSchema(): payload = { "pipeline_id": "123", "config": {"param1": "value1", "param2": "value2"}, - "config_hash": "abc123" + "config_hash": "abc123", } schema = PipelineConfigSchema() result = schema.load(payload) @@ -77,25 +92,23 @@ def test_PipelineConfigSchema(): assert result.config == {"param1": "value1", "param2": "value2"} assert result.config_hash == "abc123" + def test_PipelineRunSchema(): - payload = { - "pipeline_id": "123", - "config_id": "456", - "run_index": 1 - } + payload = {"pipeline_id": "123", "config_id": "456", "run_index": 1} schema = PipelineRunSchema() result = schema.load(payload) assert result.pipeline_id == "123" assert result.config_id == "456" assert result.run_index == 1 + def test_PipelineRunResultSchema(): payload = { "run_id": "123", "base_study_id": "456", "date_executed": "2023-01-01T00:00:00Z", "data": {"result": "success"}, - "file_inputs": {"input1": "file1"} + "file_inputs": {"input1": "file1"}, } schema = PipelineRunResultSchema() result = schema.load(payload) @@ -105,12 +118,9 @@ def test_PipelineRunResultSchema(): assert result.data == {"result": "success"} assert result.file_inputs == {"input1": "file1"} + def test_PipelineRunResultVoteSchema(): - payload = { - "run_result_id": "123", - "user_id": "456", - "accurate": True - } + payload = {"run_result_id": "123", "user_id": "456", "accurate": True} schema = PipelineRunResultVoteSchema() result = schema.load(payload) assert result.run_result_id == "123"