From a764ea192a234574f541fe09c666368663a7c853 Mon Sep 17 00:00:00 2001 From: James Kent Date: Wed, 2 Sep 2026 13:32:45 -0500 Subject: [PATCH] pass the method references in addition to the text --- compose_runner/run.py | 11 ++++++- compose_runner/tests/test_run.py | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/compose_runner/run.py b/compose_runner/run.py index 5f0694d..46a787b 100644 --- a/compose_runner/run.py +++ b/compose_runner/run.py @@ -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={}, diff --git a/compose_runner/tests/test_run.py b/compose_runner/tests/test_run.py index 04828e7..e088933 100644 --- a/compose_runner/tests/test_run.py +++ b/compose_runner/tests/test_run.py @@ -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(