Skip to content

Commit 930d953

Browse files
committed
fixes a minor bug in dts_validator.client.get_resource_recursively() and bumps version to 0.2.3
1 parent 2a54401 commit 930d953

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

dts_validator/client.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,10 @@ def get_one_resource(self):
184184
collections = self.collections()
185185
random.shuffle(collections)
186186
for collection in collections:
187-
resource = get_resource_recursively(collection, self)
187+
resource = get_resource_recursively(collection, self)
188188
if resource:
189189
return resource
190-
else:
191-
return None
190+
return None
192191

193192
def navigation(
194193
self,
@@ -270,20 +269,21 @@ def document(
270269
else:
271270
return (None, response)
272271

273-
def get_resource_recursively(collection : DTS_Collection, dts_client : DTS_API) -> DTS_Resource:
274-
# get the full metadata from the API
275-
collection = dts_client.collections(id=collection.id)
276-
277-
if isinstance(collection, DTS_Resource):
278-
return collection
279-
else:
280-
for child in collection.children:
281-
if isinstance(child, DTS_Resource):
282-
resource = child
283-
continue
284-
else:
285-
return get_resource_recursively(child, dts_client)
286-
return resource
272+
def get_resource_recursively(
273+
collection: DTS_Collection, dts_client: DTS_API
274+
) -> Optional[DTS_Resource]:
275+
"""Walk collection members until a DTS Resource (readable document) is found."""
276+
node = dts_client.collections(id=collection.id)
277+
# collections(id=...) always returns DTS_Collection; Resource replies set @type in JSON.
278+
if node._json.get("@type") == "Resource":
279+
return DTS_Resource(node._json)
280+
for child in node.children:
281+
if isinstance(child, DTS_Resource):
282+
return child
283+
found = get_resource_recursively(child, dts_client)
284+
if found is not None:
285+
return found
286+
return None
287287

288288
# TODO: rewrite using new objects
289289
def get_collections_recursively(collection, dts_client):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "dts-validator"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
description = "DTS validator: a suite of tests for testing & validating implementations of the DTS API"
55
authors = ["Matteo Romanello <matteo.romanello@gmail.com>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)