test: update custom-data api related tests according rpc_list_custom_data output

This commit is contained in:
Axel-CH
2025-03-18 00:50:03 -04:00
parent 83a8651d41
commit 578ba9ea4a
+31 -38
View File
@@ -835,11 +835,11 @@ def test_api_custom_data_single_trade(botclient, fee):
res_cust_data = response_json[0]["custom_data"] res_cust_data = response_json[0]["custom_data"]
expected_data_td_1 = [ expected_data_td_1 = [
{"ft_trade_id": 1, "cd_key": "test_str", "cd_type": "str", "cd_value": "test_value"}, {"key": "test_str", "type": "str", "cd_value": "test_value", "value": "test_value"},
{"ft_trade_id": 1, "cd_key": "test_int", "cd_type": "int", "cd_value": "1"}, {"key": "test_int", "type": "int", "cd_value": "1", "value": 1},
{"ft_trade_id": 1, "cd_key": "test_float", "cd_type": "float", "cd_value": "1.54"}, {"key": "test_float", "type": "float", "cd_value": "1.54", "value": 1.54},
{"ft_trade_id": 1, "cd_key": "test_bool", "cd_type": "bool", "cd_value": "True"}, {"key": "test_bool", "type": "bool", "cd_value": "True", "value": True},
{"ft_trade_id": 1, "cd_key": "test_dict", "cd_type": "dict", "cd_value": '{"test": "vl"}'}, {"key": "test_dict", "type": "dict", "cd_value": '{"test": "vl"}', "value": {"test": "vl"}},
] ]
# Ensure response contains exactly the expected number of entries # Ensure response contains exactly the expected number of entries
@@ -851,22 +851,21 @@ def test_api_custom_data_single_trade(botclient, fee):
for expected in expected_data_td_1: for expected in expected_data_td_1:
matched_item = None matched_item = None
for item in res_cust_data: for item in res_cust_data:
if item["cd_key"] == expected["cd_key"]: if item["key"] == expected["key"]:
matched_item = item matched_item = item
break break
assert matched_item is not None, ( assert matched_item is not None, (
f"\nError: Missing expected entry for key '{expected['cd_key']}'\n" f"\nError: Missing expected entry for key '{expected['key']}'\nExpected: {expected}\n"
f"Expected: {expected}\n"
) )
# Validate individual fields and print only incorrect values # Validate individual fields and print only incorrect values
mismatches = [] mismatches = []
for field in ["ft_trade_id", "cd_type", "cd_value"]: for field in ["key", "type", "cd_value", "value"]:
if matched_item[field] != expected[field]: if matched_item[field] != expected[field]:
mismatches.append(f"{field}: Expected {expected[field]}, Got {matched_item[field]}") mismatches.append(f"{field}: Expected {expected[field]}, Got {matched_item[field]}")
assert not mismatches, f"\nError in entry '{expected['cd_key']}':\n" + "\n".join(mismatches) assert not mismatches, f"\nError in entry '{expected['key']}':\n" + "\n".join(mismatches)
# CASE 2 Checking specific existing key custom data of trade 1 # CASE 2 Checking specific existing key custom data of trade 1
rc = client_get(client, f"{BASE_URI}/trades/1/custom-data?key=test_dict") rc = client_get(client, f"{BASE_URI}/trades/1/custom-data?key=test_dict")
@@ -933,48 +932,42 @@ def test_api_custom_data_multiple_open_trades(botclient, fee):
expected_custom_data = { expected_custom_data = {
1: [ 1: [
{ {
"id": 1, "key": "test_str",
"ft_trade_id": 1, "type": "str",
"cd_key": "test_str",
"cd_type": "str",
"cd_value": "test_value_t1", "cd_value": "test_value_t1",
"value": "test_value_t1",
}, },
{ {
"id": 2, "key": "test_float",
"ft_trade_id": 1, "type": "float",
"cd_key": "test_float",
"cd_type": "float",
"cd_value": "1.54", "cd_value": "1.54",
"value": 1.54,
}, },
{ {
"id": 3, "key": "test_dict",
"ft_trade_id": 1, "type": "dict",
"cd_key": "test_dict",
"cd_type": "dict",
"cd_value": '{"test_t1": "vl_t1"}', "cd_value": '{"test_t1": "vl_t1"}',
"value": {"test_t1": "vl_t1"},
}, },
], ],
4: [ 4: [
{ {
"id": 4, "key": "test_str",
"ft_trade_id": 4, "type": "str",
"cd_key": "test_str",
"cd_type": "str",
"cd_value": "test_value_t2", "cd_value": "test_value_t2",
"value": "test_value_t2",
}, },
{ {
"id": 5, "key": "test_float",
"ft_trade_id": 4, "type": "float",
"cd_key": "test_float",
"cd_type": "float",
"cd_value": "1.55", "cd_value": "1.55",
"value": 1.55,
}, },
{ {
"id": 6, "key": "test_dict",
"ft_trade_id": 4, "type": "dict",
"cd_key": "test_dict",
"cd_type": "dict",
"cd_value": '{"test_t2": "vl_t2"}', "cd_value": '{"test_t2": "vl_t2"}',
"value": {"test_t2": "vl_t2"},
}, },
], ],
} }
@@ -995,19 +988,19 @@ def test_api_custom_data_multiple_open_trades(botclient, fee):
for expected in expected_data: for expected in expected_data:
matched_item = None matched_item = None
for item in custom_data_list: for item in custom_data_list:
if item["cd_key"] == expected["cd_key"]: if item["key"] == expected["key"]:
matched_item = item matched_item = item
break break
assert matched_item is not None, ( assert matched_item is not None, (
f"\nError: For trade_id {trade_id}, \ f"\nError: For trade_id {trade_id}, \
missing expected entry for key '{expected['cd_key']}'\n" missing expected entry for key '{expected['key']}'\n"
f"Expected: {expected}\n" f"Expected: {expected}\n"
) )
# Validate key fields. # Validate key fields.
mismatches = [] mismatches = []
for field in ["id", "ft_trade_id", "cd_key", "cd_type", "cd_value"]: for field in ["key", "type", "cd_value", "value"]:
if matched_item[field] != expected[field]: if matched_item[field] != expected[field]:
mismatches.append( mismatches.append(
f"{field}: Expected {expected[field]}, Got {matched_item[field]}" f"{field}: Expected {expected[field]}, Got {matched_item[field]}"
@@ -1018,7 +1011,7 @@ def test_api_custom_data_multiple_open_trades(botclient, fee):
mismatches.append(f"Missing field: {field}") mismatches.append(f"Missing field: {field}")
assert not mismatches, ( assert not mismatches, (
f"\nError in entry '{expected['cd_key']}' for trade_id {trade_id}:\n" f"\nError in entry '{expected['key']}' for trade_id {trade_id}:\n"
+ "\n".join(mismatches) + "\n".join(mismatches)
) )