Skip to content

Commit

Permalink
fix(node): Node.node_id() return invalid address to list elements
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Nov 7, 2023
1 parent edd6d90 commit 6828f61
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/common/providers/address_resolver/path_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def get_child(
f"Invalid attribute '{self.path}'. Valid attributes are '{list(entity.keys())}'."
) from ex
else:
try:
int(self.path)
raise NotFoundException(
"'myList.0' is an invalid syntax for accessing items in a list. Use 'myList[0]' instead"
) from ex
except ValueError:
pass
raise NotFoundException(f"Invalid index '{self.path}'. Valid indices are < {len(entity)}.") from ex

return result, self.path
2 changes: 2 additions & 0 deletions src/common/tree/tree_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def node_id(self):
return self.uid
if not self.storage_contained and not self.is_array():
return self.uid
if self.parent.is_array():
return f"{self.parent.node_id}[{self.key}]"
return ".".join((self.parent.node_id, self.key))

def path(self):
Expand Down
2 changes: 1 addition & 1 deletion src/tests/bdd/document/add_contained.feature
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ Feature: Explorer - Add contained node
Then the response status should be "OK"
And the response should contain
"""
{"uid": "1.meAgain.1.meAgain.0"}
{"uid": "1.meAgain[1].meAgain[0]"}
"""
6 changes: 5 additions & 1 deletion src/tests/bdd/document/add_document.feature
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ Feature: Add document with document_service
}
"""
Then the response status should be "OK"
And the response should contain
"""
{"uid": "11.phases[1]"}
"""
Given i access the resource url "/api/documents/data-source-name/root_package/EntityPackage/operation1?depth=3"
When I make a "GET" request
Then the response status should be "OK"
Expand Down Expand Up @@ -449,7 +453,7 @@ Feature: Add document with document_service
And the response should contain
"""
{
"uid": "11.phases.0.containedResults.0"
"uid": "11.phases[0].containedResults[0]"
}
"""
# todo update document add use case such that id contains bracket notation for lists: 11.phases[0].containedResults[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Feature: Add document with optional attributes
And the response should contain
"""
{
"uid": "workComputerId.letterKeys.0"
"uid": "workComputerId.letterKeys[0]"
}
"""
Given i access the resource url "/api/documents/data-source-name/$workComputerId.letterKeys"
Expand Down
2 changes: 1 addition & 1 deletion src/tests/bdd/document/update_list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Feature: Add document with optional attributes
And the response should contain
"""
{
"uid": "workComputerId.letterKeys.0"
"uid": "workComputerId.letterKeys[0]"
}
"""
Given i access the resource url "/api/documents/data-source-name/$workComputerId.letterKeys"
Expand Down
2 changes: 1 addition & 1 deletion src/tests/unit/common/tree/test_tree_node_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def test_node_id(self):
self.assertEqual(nested_2.node_id, "1.nested.nested")
self.assertEqual(reference.node_id, "1.nested.nested.reference")
self.assertEqual(list_node.node_id, "1.list")
self.assertEqual(item_1.node_id, "1.list.0")
self.assertEqual(item_1.node_id, "1.list[0]")

def test_search(self):
document_1 = {
Expand Down

0 comments on commit 6828f61

Please sign in to comment.