From 484f4daa2dd06f54b34b60a227c300799379cf8b Mon Sep 17 00:00:00 2001 From: Gusto Date: Thu, 14 Mar 2024 15:33:29 +0200 Subject: [PATCH] Comments for read and write methods in BlobStore --- da/api/common.py | 13 +++++++++++-- da/api/test_flow.py | 11 ++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/da/api/common.py b/da/api/common.py index ecf5845..0a55a7f 100644 --- a/da/api/common.py +++ b/da/api/common.py @@ -22,11 +22,20 @@ class Api: def __init__(self, bs: BlobStore): self.store = bs + """ + Write method should be used by a service that is able to retrieve verified certificates + from the latest Block. Once a certificate is retrieved, api creates a relation between + the blob of an original data, certificate and index for the app_id of the certificate. + """ def write(self, certificate, metadata): - # TODO: Certificate indexing can fail. self.store.add(certificate, metadata) return + """ + Read method should accept only `app_id` and a list of indexes. The returned list of + blobs should be ordered in the same sequence as `indexes` in a request. + If node does not have the blob for some indexes, then it should add None object as an + item. + """ def read(self, app_id, indexes) -> Optional[List[Optional[DABlob]]]: - # Gather requested indexes for the app_id. return self.store.get_multiple(app_id, indexes) diff --git a/da/api/test_flow.py b/da/api/test_flow.py index 477f410..1064643 100644 --- a/da/api/test_flow.py +++ b/da/api/test_flow.py @@ -15,7 +15,7 @@ class MockStore(BlobStore): def populate(self, blob, cert_id: bytes): self.blob_store[cert_id] = blob - # cert, app_id, idx + # Implements `add` method from BlobStore abstract class. def add(self, cert_id: bytes, metadata: Metadata): if metadata.index in self.app_id_store[metadata.app_id]: raise ValueError("index already written") @@ -23,6 +23,7 @@ class MockStore(BlobStore): blob = self.blob_store.pop(cert_id) self.app_id_store[metadata.app_id][metadata.index] = blob + # Implements `get_multiple` method from BlobStore abstract class. def get_multiple(self, app_id, indexes) -> List[Optional[DABlob]]: return [ self.app_id_store[app_id].get(i) for i in indexes @@ -43,9 +44,9 @@ class TestFlow(TestCase): api = Api(mock_store) api.write(cert_id, mock_meta) - blob = api.read(app_id, [idx]) + blobs = api.read(app_id, [idx]) - self.assertEqual([expected_blob], blob) + self.assertEqual([expected_blob], blobs) def test_same_index(self): expected_blob = "hello" @@ -63,7 +64,7 @@ class TestFlow(TestCase): with self.assertRaises(ValueError): api.write(cert_id, mock_meta) - blob = api.read(app_id, [idx]) + blobs = api.read(app_id, [idx]) - self.assertEqual([expected_blob], blob) + self.assertEqual([expected_blob], blobs)