Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compose_runner/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,16 @@ def upload_results(self):
resource_path="/meta-analysis-results/{id}",
path_params={"id": self.result_id},
header_params={"Content-Type": "multipart/form-data"},
post_params=[("method_description", self.meta_results.description_)],
# NiMARE leaves bibtex_ empty when the description cites nothing;
# sending "" would blank out whatever compose already stored.
post_params=[
(name, value)
for name, value in (
("method_description", self.meta_results.description_),
("method_references", self.meta_results.bibtex_),
)
if value
],
files=files,
auth_settings=["upload_key"],
collection_formats={},
Expand Down
56 changes: 56 additions & 0 deletions compose_runner/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,62 @@ def meta_analysis_results_post(self, result_init):
assert __version__ != "unknown"


def _capture_upload_params(description, bibtex):
"""Run upload_results against a fake client and return its post_params."""
captured = {}

class FakeApiClient:
def param_serialize(self, **kwargs):
captured.update(kwargs)
return ()

def call_api(self):
return type("Response", (), {"read": lambda self: None})()

def response_deserialize(self, response_data, response_types_map):
return type("Deserialized", (), {"data": "result"})()

class FakeComposeApi:
api_client = FakeApiClient()

runner = Runner(meta_analysis_id="meta-id", environment="production")
runner.compose_api = FakeComposeApi()
runner.result_id = "result-id"
runner.meta_results = type(
"FakeMetaResult",
(),
{
"maps": {},
"tables": {},
"description_": description,
"bibtex_": bibtex,
},
)()

runner.upload_results()

return captured["post_params"]


def test_upload_results_sends_method_description_and_references():
"""The description and the BibTeX it cites go up as form fields."""
assert _capture_upload_params(
"An ALE meta-analysis was performed.",
"@article{Salo2023,\n title = {NiMARE},\n}\n",
) == [
("method_description", "An ALE meta-analysis was performed."),
("method_references", "@article{Salo2023,\n title = {NiMARE},\n}\n"),
]


def test_upload_results_omits_empty_method_fields():
"""NiMARE reports no BibTeX when the description cites nothing; sending
"" would blank out what compose already stored."""
assert _capture_upload_params("An ALE meta-analysis was performed.", "") == [
("method_description", "An ALE meta-analysis was performed.")
]


@pytest.mark.vcr
def test_run_workflow():
runner = Runner(
Expand Down
Loading