Skip to content

Commit

Permalink
[FIX] specification_condition update (#644)
Browse files Browse the repository at this point in the history
* fix specification_condition update

* style issues
  • Loading branch information
jdkent authored Dec 12, 2023
1 parent 1741586 commit 0b7a69c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compose/neurosynth_compose/models/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class SpecificationCondition(BaseMixin, db.Model):
)
condition = relationship("Condition", backref=backref("specification_conditions"))
specification = relationship(
"Specification", backref=backref("specification_conditions")
"Specification",
backref=backref("specification_conditions", cascade="all, delete-orphan"),
)
user_id = db.Column(db.Text, db.ForeignKey("users.external_id"))
user = relationship("User", backref=backref("specification_conditions"))
Expand Down
2 changes: 1 addition & 1 deletion compose/neurosynth_compose/resources/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def update_or_create(cls, data, id=None, commit=True):
if cls._attribute_name:
existing_nested = getattr(record, cls._attribute_name, None)

if existing_nested and len(existing_nested) == len(rec_data):
if existing_nested:
_ = [
rd.update({"id": ns.id})
for rd, ns in zip(
Expand Down
56 changes: 56 additions & 0 deletions compose/neurosynth_compose/tests/api/test_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,59 @@ def test_update_condition_weight(session, app, auth_client, user_data):
assert set(get_spec.json[key]) == set(value)
else:
assert get_spec.json[key] == value


def test_other_specification_conditions(session, app, auth_client, user_data):
specification_data = {
"conditions": [True, False],
"corrector": None,
"database_studyset": None,
"estimator": {
"args": {
"**kwargs": {},
"kernel__fwhm": None,
"kernel__sample_size": None,
"n_iters": 10000,
},
"type": "ALESubtraction",
},
"filter": "included",
"type": "CBMA",
"weights": [1, -1],
}

create_spec = auth_client.post("/api/specifications", data=specification_data)

updated_data = {
"type": "CBMA",
"estimator": {
"type": "ALESubtraction",
"args": {
"**kwargs": {},
"kernel__fwhm": None,
"kernel__sample_size": None,
"n_iters": 10000,
},
},
"corrector": None,
"filter": "included",
"conditions": [True],
"database_studyset": "neuroquery",
"weights": [1],
}

assert create_spec.status_code == 200

spec_id = create_spec.json["id"]

update_spec = auth_client.put(f"/api/specifications/{spec_id}", data=updated_data)
assert update_spec.status_code == 200

get_spec = auth_client.get(f"/api/specifications/{spec_id}")
assert get_spec.status_code == 200

for key, value in updated_data.items():
if isinstance(value, list):
assert set(get_spec.json[key]) == set(value)
else:
assert get_spec.json[key] == value

0 comments on commit 0b7a69c

Please sign in to comment.