Skip to content

Commit c8a3bc2

Browse files
committed
reduce the number of warnings emitted
1 parent 7058f31 commit c8a3bc2

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

compose/backend/neurosynth_compose/tests/request_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ def _make_request(
8585
kwargs["files"] = data
8686
kwargs["headers"].pop("Content-Type", None)
8787
else:
88-
kwargs["data"] = data
88+
payload = data
89+
if json_dump and isinstance(payload, (dict, list)):
90+
payload = json.dumps(payload)
91+
if isinstance(payload, str):
92+
payload = payload.encode("utf-8")
93+
kwargs["content"] = payload
8994
response = request_function(route, **kwargs)
9095
return ResponseWrapper(response)
9196

store/backend/neurostore/tests/api/test_pipeline_resources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def test_config_pipeline_study_results(
443443
if expected_count > 0:
444444
# Get the config from the database using config_id
445445
config_id = data["results"][0]["config_id"]
446-
pipeline_config = PipelineConfig.query.get(config_id)
446+
pipeline_config = db.session.get(PipelineConfig, config_id)
447447
assert pipeline_config is not None
448448

449449
# Check the value using the config from database
@@ -473,7 +473,7 @@ def test_combined_filters(auth_client, result1, result2, result3):
473473
result = data["results"][0]
474474
assert result["result_data"]["string_field"] == "test value"
475475
# Validate against database config
476-
pipeline_config = PipelineConfig.query.get(result["config_id"])
476+
pipeline_config = db.session.get(PipelineConfig, result["config_id"])
477477
assert pipeline_config is not None
478478
assert pipeline_config.config_args["extraction_model"] == "gpt-4"
479479

store/backend/neurostore/tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ def session(db):
267267
yield session
268268

269269
cache.clear()
270-
try:
270+
txn = session.get_transaction()
271+
if txn is not None and txn.is_active:
271272
session.rollback()
272-
except: # noqa
273-
pass
274273
session.close()
275-
transaction.rollback()
274+
if transaction.is_active:
275+
transaction.rollback()
276276
connection.close()
277277

278278

store/backend/neurostore/tests/request_utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,24 @@ def _make_request(
6363

6464
return request_function(route, **kwargs)
6565
else:
66-
return request_function(route, json=data, headers=headers, params=params)
66+
kwargs = {"headers": headers, "params": params}
67+
68+
if data is not None:
69+
if (
70+
content_type.startswith("application/json")
71+
and json_dump
72+
and isinstance(data, (dict, list))
73+
):
74+
kwargs["json"] = data
75+
else:
76+
payload = data
77+
if json_dump and isinstance(data, (dict, list)):
78+
payload = json.dumps(data)
79+
if isinstance(payload, str):
80+
payload = payload.encode("utf-8")
81+
kwargs["content"] = payload
82+
83+
return request_function(route, **kwargs)
6784

6885
get = partialmethod(_make_request, "get")
6986
post = partialmethod(_make_request, "post")

0 commit comments

Comments
 (0)