Skip to content

Commit

Permalink
🎨 make relevant methods async
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed May 10, 2024
1 parent 22d984c commit c7c2692
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions aries_cloudagent/vc/ld_proofs/document_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
for url, filename in StaticCacheJsonLdDownloader.CONTEXT_FILE_MAPPING.items()
}

def load(self, url: str, options: Optional[Dict] = None):
async def load(self, url: str, options: Optional[Dict] = None):
"""Load a jsonld document from URL.
Prioritize local static cache before attempting to download from the URL.
Expand All @@ -74,10 +74,10 @@ def load(self, url: str, options: Optional[Dict] = None):
return cached

logger.debug("Context %s not in static cache, resolving from URL.", url)
return self._live_load(url, options)
return await self._live_load(url, options)

def _live_load(self, url: str, options: Optional[Dict] = None):
doc, link_header = self.documents_downloader.download(url, options)
async def _live_load(self, url: str, options: Optional[Dict] = None):
doc, link_header = await self.documents_downloader.download(url, options)
return self.document_parser.parse(doc, link_header)


Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/vc/ld_proofs/document_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ async def _load_did_document(self, did: str, options: dict):

return document

def _load_http_document(self, url: str, options: dict):
document = self.requests_loader(url, options)
async def _load_http_document(self, url: str, options: dict):
document = await self.requests_loader(url, options)

return document

Expand All @@ -62,7 +62,7 @@ async def _load_async(self, url: str, options: dict):
if url.startswith("did:"):
document = await self._load_did_document(url, options)
elif url.startswith("http://") or url.startswith("https://"):
document = self._load_http_document(url, options)
document = await self._load_http_document(url, options)
else:
raise LinkedDataProofException(
"Unrecognized url format. Must start with "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
)


def test_load_cache_hit():
async def test_load_cache_hit():
downloader = Mock()
context_loader = StaticCacheJsonLdDownloader(document_downloader=downloader)

context_loader.load("https://www.w3.org/2018/credentials/v1")
await context_loader.load("https://www.w3.org/2018/credentials/v1")
downloader.download.assert_not_called()


def test_load_cache_miss_triggers_download():
async def test_load_cache_miss_triggers_download():
downloader = Mock()
downloader.download = Mock(return_value=(None, None))
context_loader = StaticCacheJsonLdDownloader(document_downloader=downloader)

context_loader.load("https://www.w3.org/2018/very_unlikely_name/v1")
await context_loader.load("https://www.w3.org/2018/very_unlikely_name/v1")
downloader.download.assert_called()

0 comments on commit c7c2692

Please sign in to comment.