Skip to content

Commit f5df21a

Browse files
committed
Handle nested dicts for covnersion
1 parent 585bd33 commit f5df21a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/picketapi/helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ def snake_to_camel(name: str) -> str:
88

99

1010
def snake_to_camel_keys(d: dict) -> dict:
11-
return {snake_to_camel(k): v for k, v in d.items()}
11+
return {
12+
snake_to_camel(k): v if type(v) is not dict else snake_to_camel_keys(v)
13+
for k, v in d.items()
14+
}

tests/test_helpers.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_is_successful_status_code_false():
1212
def test_snake_to_camel():
1313
assert helpers.snake_to_camel("snake_to_camel") == "snakeToCamel"
1414
assert helpers.snake_to_camel("wallet_address") == "walletAddress"
15-
assert helpers.snake_to_camel("contract_address") == "contractAddress"
15+
assert helpers.snake_to_camel("contractAddress") == "contractAddress"
1616
assert helpers.snake_to_camel("token_ids") == "tokenIds"
1717

1818

@@ -22,3 +22,26 @@ def test_snake_to_camel_keys():
2222
"snakeToCamel": "snake_to_camel",
2323
"walletAddress": "wallet_address",
2424
}
25+
26+
27+
def test_snake_to_camel_keys_nested():
28+
d = {
29+
"snake_to_camel": "snake_to_camel",
30+
"walletAddress": "wallet_address",
31+
"nested": {
32+
"nest_one": "value",
33+
"nest_two": {
34+
"nest_three": "value",
35+
},
36+
},
37+
}
38+
assert helpers.snake_to_camel_keys(d) == {
39+
"snakeToCamel": "snake_to_camel",
40+
"walletAddress": "wallet_address",
41+
"nested": {
42+
"nestOne": "value",
43+
"nestTwo": {
44+
"nestThree": "value",
45+
},
46+
},
47+
}

0 commit comments

Comments
 (0)