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
10 changes: 8 additions & 2 deletions robosystems_client/clients/ledger_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@
# ``ReportDownloadFormat`` enum names used as query variables.
_DOWNLOAD_FORMAT_ALIASES = {
"holon-jsonld": "HOLON_JSONLD",
"holon-jsonld-lineage": "HOLON_JSONLD_LINEAGE",
"xbrl-2.1": "XBRL_2_1",
"tavi": "TAVI",
}
Expand Down Expand Up @@ -3782,8 +3783,12 @@ def download_report_bundle(
format: Serialization flavor — ``"holon-jsonld"`` (default, the
dataset-form scene/boundary/projection holon, which carries
the whole report and is stamped at publish), ``"tavi"`` (the
Project Tavi compiled model), or ``"xbrl-2.1"``. The enum names ``"TAVI"`` /
``"HOLON_JSONLD"`` / ``"XBRL_2_1"`` are also accepted.
Project Tavi compiled model), ``"xbrl-2.1"``, or
``"holon-jsonld-lineage"`` (the holon with its ``#lineage`` graph:
the ledger lines, entries and events behind every frozen figure,
for this graph's own members). The enum names ``"TAVI"`` /
``"HOLON_JSONLD"`` / ``"HOLON_JSONLD_LINEAGE"`` / ``"XBRL_2_1"``
are also accepted.
to: Optional file path to write the bytes to. When set, the
returned ``ReportBundleDownload.path`` points at the
written file.
Expand Down Expand Up @@ -3830,6 +3835,7 @@ def download_report_bundle(
default_ext = {
"XBRL_2_1": "zip",
"HOLON_JSONLD": "holon.jsonld",
"HOLON_JSONLD_LINEAGE": "lineage.holon.jsonld",
}.get(gql_format, "tavi.json")
filename = (
_parse_filename(artifact.headers.get("content-disposition", ""))
Expand Down
22 changes: 22 additions & 0 deletions tests/test_ledger_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3252,6 +3252,28 @@ def test_default_download_is_the_holon(self, mock_client_cls, mock_config, graph
# The bytes come from following the presigned URL.
assert mock_client.get.call_args.args[0].startswith("https://s3.example.com/")

@patch("robosystems_client.clients.ledger_client.httpx.Client")
def test_lineage_download_takes_the_short_alias(
self, mock_client_cls, mock_config, graph_id
):
"""``holon-jsonld-lineage`` names the lineage holon; with no filename from
the server it lands as ``.lineage.holon.jsonld``, never ``.tavi.json``."""
artifact = self._mock_artifact(b'{"@graph": []}', "")
artifact.headers = {}
self._patch_httpx(mock_client_cls, artifact)
with patch.object(
LedgerClient,
"_query",
return_value=self._gql_data("application/ld+json", "holon-jsonld-lineage", gen=3),
) as mock_query:
result = LedgerClient(mock_config).download_report_bundle(
graph_id, "rpt_01", format="holon-jsonld-lineage"
)

assert mock_query.call_args.args[2]["format"] == "HOLON_JSONLD_LINEAGE"
assert result.format == "holon-jsonld-lineage"
assert result.filename == "rpt_01-g3.lineage.holon.jsonld"

@patch("robosystems_client.clients.ledger_client.httpx.Client")
def test_xbrl_download_follows_presigned_url(
self, mock_client_cls, mock_config, graph_id
Expand Down
Loading