Skip to content

Commit

Permalink
style with black
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkent committed Jan 17, 2025
1 parent 3b6e3e4 commit bc1ccef
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 55 deletions.
10 changes: 7 additions & 3 deletions store/neurostore/ingest/extracted_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion store/neurostore/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
1 change: 1 addition & 0 deletions store/neurostore/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
PipelineRunResultsView,
PipelineRunResultVotesView,
)

__all__ = [
"StudysetsView",
"AnnotationsView",
Expand Down
27 changes: 20 additions & 7 deletions store/neurostore/resources/pipeline.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
9 changes: 8 additions & 1 deletion store/neurostore/schemas/pipeline.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
90 changes: 64 additions & 26 deletions store/neurostore/tests/api/test_pipeline_resources.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
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)
session.add(pipeline)
session.commit()
return pipeline


@pytest.fixture
def pipeline_config(session, pipeline_config_payload):
pipeline_config = PipelineConfig(**pipeline_config_payload)
session.add(pipeline_config)
session.commit()
return pipeline_config


@pytest.fixture
def pipeline_run(session, pipeline_run_payload):
pipeline_run = PipelineRun(**pipeline_run_payload)
session.add(pipeline_run)
session.commit()
return pipeline_run


@pytest.fixture
def pipeline_run_result(session, pipeline_run_result_payload):
pipeline_run_result = PipelineRunResult(**pipeline_run_result_payload)
Expand All @@ -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):
Expand All @@ -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
4 changes: 2 additions & 2 deletions store/neurostore/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions store/neurostore/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_Image():
def test_Studyset():
Studyset()


def test_Pipeline():
Pipeline()

Expand Down
Loading

0 comments on commit bc1ccef

Please sign in to comment.