Skip to content
Closed
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
7 changes: 6 additions & 1 deletion compose/backend/neurosynth_compose/tests/request_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ def _make_request(
kwargs["files"] = data
kwargs["headers"].pop("Content-Type", None)
else:
kwargs["data"] = data
payload = data
if json_dump and isinstance(payload, (dict, list)):
payload = json.dumps(payload)
if isinstance(payload, str):
payload = payload.encode("utf-8")
kwargs["content"] = payload
response = request_function(route, **kwargs)
return ResponseWrapper(response)

Expand Down
4 changes: 2 additions & 2 deletions store/backend/neurostore/tests/api/test_pipeline_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def test_config_pipeline_study_results(
if expected_count > 0:
# Get the config from the database using config_id
config_id = data["results"][0]["config_id"]
pipeline_config = PipelineConfig.query.get(config_id)
pipeline_config = db.session.get(PipelineConfig, config_id)
assert pipeline_config is not None

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

Expand Down
8 changes: 4 additions & 4 deletions store/backend/neurostore/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ def session(db):
yield session

cache.clear()
try:
txn = session.get_transaction()
if txn is not None and txn.is_active:
session.rollback()
except: # noqa
pass
session.close()
transaction.rollback()
if transaction.is_active:
transaction.rollback()
connection.close()


Expand Down
19 changes: 18 additions & 1 deletion store/backend/neurostore/tests/request_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,24 @@ def _make_request(

return request_function(route, **kwargs)
else:
return request_function(route, json=data, headers=headers, params=params)
kwargs = {"headers": headers, "params": params}

if data is not None:
if (
content_type.startswith("application/json")
and json_dump
and isinstance(data, (dict, list))
):
kwargs["json"] = data
else:
payload = data
if json_dump and isinstance(data, (dict, list)):
payload = json.dumps(data)
if isinstance(payload, str):
payload = payload.encode("utf-8")
kwargs["content"] = payload

return request_function(route, **kwargs)

get = partialmethod(_make_request, "get")
post = partialmethod(_make_request, "post")
Expand Down
Loading