Thanks to visit codestin.com
Credit goes to github.com

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
12 changes: 5 additions & 7 deletions sheepdog/utils/transforms/graph_to_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,13 @@ def list_to_comma_string(val, file_format):
Example:
['1','2','3'] -> '1,2,3'
"""

if val is None:
if file_format != "json":
# If a field is empty we must replace it with an empty string for tsv/csv exports and leave it as None for json exports
if file_format == "json":
return val
return ""
if val is None:
return ""

if isinstance(val, list):
val = ",".join((str(x) for x in val))
if isinstance(val, list):
val = ",".join((str(x) for x in val))
return val


Expand Down
1 change: 1 addition & 0 deletions tests/integration/datadict/schemas/dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -6177,6 +6177,7 @@
"id": "case",
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"consent_codes": {"type": "array", "description": "", "items": {"type": "string"}},
"disease_type": {
"type": "string",
"description": "Name of the disease for the case."
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/datadict/submission/data/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"submitter_id": "BLGSP-71-06-00019",
"experiments": {
"submitter_id": "BLGSP-71-experiment-01"
}
}
},
"consent_codes": ["code1", "code2"]
}
14 changes: 14 additions & 0 deletions tests/integration/datadict/submission/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,20 @@ def test_export_all_node_types_and_resubmit_tsv_with_empty_field(
print(json.dumps(json.loads(resp.data), indent=4, sort_keys=True))
assert resp.status_code == 200, resp.data

def test_export_node_with_array_json(
client, pg_driver, cgci_blgsp, require_index_exists_off, submitter
):
post_example_entities_together(client, submitter, extended_data_fnames)
with pg_driver.session_scope() as s:
case = pg_driver.nodes(md.Case).first()
consent_codes = case.props.get("consent_codes", [])
path = "/v0/submission/CGCI/BLGSP/export/?node_label=case&format=json"
r = client.get(path, headers=submitter)
assert r.status_code == 200, r.data
assert r.headers["Content-Disposition"].endswith("json")
js_data = json.loads(r.data)
assert isinstance(js_data["data"][0]["consent_codes"], list)
assert len(js_data["data"][0]["consent_codes"]) == len(consent_codes)

def test_export_all_node_types_json(
client, pg_driver, cgci_blgsp, submitter, require_index_exists_off
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"submitter_id": "BLGSP-71-06-00019",
"experiments": {
"submitter_id": "BLGSP-71-experiment-01"
}
},
"consent_codes": ["code1", "code2"]
}
16 changes: 16 additions & 0 deletions tests/integration/datadictwithobjid/submission/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,22 @@ def test_export_all_node_types(
do_test_export(client, pg_driver, submitter, "experimental_metadata", "tsv")


def test_export_node_with_array_json(
client, pg_driver, cgci_blgsp, require_index_exists_off, submitter
):
post_example_entities_together(client, submitter, extended_data_fnames)
with pg_driver.session_scope() as s:
case = pg_driver.nodes(md.Case).first()
consent_codes = case.props.get("consent_codes", [])
path = "/v0/submission/CGCI/BLGSP/export/?node_label=case&format=json"
r = client.get(path, headers=submitter)
assert r.status_code == 200, r.data
assert r.headers["Content-Disposition"].endswith("json")
js_data = json.loads(r.data)
assert isinstance(js_data["data"][0]["consent_codes"], list)
assert len(js_data["data"][0]["consent_codes"]) == len(consent_codes)


def test_export_all_node_types_json(
client, pg_driver, cgci_blgsp, require_index_exists_off, submitter
):
Expand Down