Skip to content

Commit 8d50a6d

Browse files
author
Threepwood-7
committed
CI-168 accept deterministic transfer add items
1 parent 321c9fe commit 8d50a6d

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

scripts/deterministic-two-client-transfer.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,15 @@ def add_transfer(base_url: str, api_key: str, link: str, transfer_hash: str) ->
920920
json_body={"link": link, "paused": False, "categoryId": 0},
921921
request_timeout_seconds=30.0,
922922
)
923-
item = rest_smoke.require_transfer_add_result(result, transfer_hash)
924-
return {"response": rest_smoke.compact_http_result(result), "item": item}
923+
summary = rest_smoke.compact_http_result(result)
924+
payload = response_payload(result, 200)
925+
rows = (payload.get("items") or payload.get("results")) if isinstance(payload, dict) else None
926+
if not isinstance(rows, list) or not rows:
927+
raise AssertionError(summary)
928+
item = rows[0]
929+
if not isinstance(item, dict) or item.get("ok") is not True or str(item.get("hash") or "").lower() != transfer_hash.lower():
930+
raise AssertionError(summary)
931+
return {"response": summary, "item": item}
925932

926933

927934
def read_preferences_snapshot(config_dir: Path) -> dict[str, object]:

tests/python/test_deterministic_two_client_transfer.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,37 @@ def fake_wait_for(resolve, *_args):
12211221
assert calls.count(("GET", "/api/v1/status")) == 2
12221222

12231223

1224+
def test_add_transfer_accepts_bulk_items_response_without_contract_gate(monkeypatch) -> None:
1225+
module = load_suite_module()
1226+
expected_hash = "9eced47df2edfbd72f29f93447d60b7b"
1227+
item = {"hash": expected_hash.upper(), "name": "deterministic-two-client-transfer.bin", "ok": True}
1228+
response = {
1229+
"status": 200,
1230+
"content_type": "application/json; charset=utf-8",
1231+
"json": {"items": [item]},
1232+
"raw_json": {"data": {"items": [item]}, "meta": {"apiVersion": "v1"}},
1233+
}
1234+
calls: list[tuple[str, str, dict[str, object]]] = []
1235+
1236+
def fake_http_request(_base_url, path, *, method="GET", json_body=None, **_kwargs):
1237+
calls.append((method, path, dict(json_body or {})))
1238+
return response
1239+
1240+
monkeypatch.setattr(module.rest_smoke, "http_request", fake_http_request)
1241+
monkeypatch.setattr(module.rest_smoke, "compact_http_result", lambda result: {"status": result["status"], "json": result["json"]})
1242+
1243+
result = module.add_transfer("http://127.0.0.1:4711", "key", "ed2k://|file|a|1|9ECED47DF2EDFBD72F29F93447D60B7B|/", expected_hash)
1244+
1245+
assert result["item"] == item
1246+
assert calls == [
1247+
(
1248+
"POST",
1249+
"/api/v1/transfers",
1250+
{"link": "ed2k://|file|a|1|9ECED47DF2EDFBD72F29F93447D60B7B|/", "paused": False, "categoryId": 0},
1251+
)
1252+
]
1253+
1254+
12241255
def test_wait_for_completed_file_timeout_carries_diagnostic_observations(tmp_path: Path) -> None:
12251256
module = load_suite_module()
12261257
snapshots = [{"transfer": {"status": 200, "json": {"state": "downloading"}}}]

0 commit comments

Comments
 (0)