Skip to content

Commit ad2148a

Browse files
cjhowlandryjones
authored andcommitted
fix: remove layer of endpoint nesting
Signed-off-by: Char Howland <char@indicio.tech>
1 parent 04a929c commit ad2148a

3 files changed

Lines changed: 49 additions & 43 deletions

File tree

aries_cloudagent/ledger/base.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,15 @@ async def _construct_attr_json(
9898
if not routing_keys:
9999
routing_keys = []
100100

101-
endpoint_dict = {"endpoint": endpoint}
102-
103101
if all_exist_endpoints:
104-
all_exist_endpoints[endpoint_type.indy] = endpoint_dict
105-
endpoint_dict["routingKeys"] = routing_keys
106-
attr_json = json.dumps({"endpoint": all_exist_endpoints})
102+
all_exist_endpoints[endpoint_type.indy] = endpoint
103+
all_exist_endpoints["routingKeys"] = routing_keys
104+
attr_json = json.dumps(all_exist_endpoints)
107105

108106
else:
109-
endpoint_val = {endpoint_type.indy: endpoint_dict}
107+
endpoint_dict = {endpoint_type.indy: endpoint}
110108
endpoint_dict["routingKeys"] = routing_keys
111-
attr_json = json.dumps({"endpoint": endpoint_val})
109+
attr_json = json.dumps(endpoint_dict)
112110

113111
return attr_json
114112

aries_cloudagent/ledger/tests/test_indy.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,18 +2308,34 @@ async def test_construct_attr_json_with_routing_keys(self, mock_close, mock_open
23082308
attr_json = await ledger._construct_attr_json(
23092309
"https://url",
23102310
EndpointType.ENDPOINT,
2311-
all_exist_endpoints={"Endpoint": "https://endpoint"},
23122311
routing_keys=["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
23132312
)
23142313
assert attr_json == json.dumps(
23152314
{
2316-
"endpoint": {
2317-
"Endpoint": "https://endpoint",
2318-
"endpoint": {
2319-
"endpoint": "https://url",
2320-
"routingKeys": ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
2321-
},
2322-
}
2315+
"endpoint": "https://url",
2316+
"routingKeys": ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
2317+
}
2318+
)
2319+
2320+
@async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open")
2321+
@async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close")
2322+
@pytest.mark.asyncio
2323+
async def test_construct_attr_json_with_routing_keys_all_exist_endpoints(
2324+
self, mock_close, mock_open
2325+
):
2326+
ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile)
2327+
async with ledger:
2328+
attr_json = await ledger._construct_attr_json(
2329+
"https://url",
2330+
EndpointType.ENDPOINT,
2331+
all_exist_endpoints={"profile": "https://endpoint/profile"},
2332+
routing_keys=["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
2333+
)
2334+
assert attr_json == json.dumps(
2335+
{
2336+
"profile": "https://endpoint/profile",
2337+
"endpoint": "https://url",
2338+
"routingKeys": ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
23232339
}
23242340
)
23252341

aries_cloudagent/ledger/tests/test_indy_vdr.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -612,51 +612,43 @@ async def test_update_endpoint_for_did(
612612
"all_exist_endpoints, routing_keys, result",
613613
[
614614
(
615-
{"Endpoint": "https://endpoint"},
615+
{"profile": "https://endpoint/profile"},
616616
["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
617617
{
618-
"endpoint": {
619-
"Endpoint": "https://endpoint",
620-
"endpoint": {
621-
"endpoint": "https://url",
622-
"routingKeys": [
623-
"3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"
624-
],
625-
},
626-
}
618+
"profile": "https://endpoint/profile",
619+
"endpoint": "https://url",
620+
"routingKeys": ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
627621
},
628622
),
629623
(
630-
{"Endpoint": "https://endpoint"},
624+
{"profile": "https://endpoint/profile"},
631625
None,
632626
{
633-
"endpoint": {
634-
"Endpoint": "https://endpoint",
635-
"endpoint": {"endpoint": "https://url", "routingKeys": []},
636-
}
627+
"profile": "https://endpoint/profile",
628+
"endpoint": "https://url",
629+
"routingKeys": [],
637630
},
638631
),
639632
(
640633
None,
641634
["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
642635
{
643-
"endpoint": {
644-
"endpoint": {
645-
"endpoint": "https://url",
646-
"routingKeys": [
647-
"3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"
648-
],
649-
}
650-
}
636+
"endpoint": "https://url",
637+
"routingKeys": ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
651638
},
652639
),
640+
(None, None, {"endpoint": "https://url", "routingKeys": []}),
653641
(
654-
None,
655-
None,
656642
{
657-
"endpoint": {
658-
"endpoint": {"endpoint": "https://url", "routingKeys": []}
659-
}
643+
"profile": "https://endpoint/profile",
644+
"spec_divergent_endpoint": "https://endpoint",
645+
},
646+
["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
647+
{
648+
"profile": "https://endpoint/profile",
649+
"spec_divergent_endpoint": "https://endpoint",
650+
"endpoint": "https://url",
651+
"routingKeys": ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"],
660652
},
661653
),
662654
],

0 commit comments

Comments
 (0)