Skip to content

Commit 92ca51e

Browse files
committed
feat: default database and collection for MetadataDbClient
1 parent afaa7f2 commit 92ca51e

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/aind_data_access_api/document_db.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,36 @@ def __exit__(self, exc_type, exc_val, exc_tb):
362362
class MetadataDbClient(Client):
363363
"""Class to manage reading and writing to metadata db"""
364364

365+
def __init__(
366+
self,
367+
host: str,
368+
database: str = "metadata_index",
369+
collection: str = "data_assets",
370+
version: str = "v1",
371+
boto: Optional[BotoSession] = None,
372+
session: Optional[Session] = None,
373+
):
374+
"""
375+
Instantiate a MetadataDbClient.
376+
377+
Parameters
378+
----------
379+
host : str
380+
database : str
381+
collection : str
382+
version : str
383+
boto : Optional[BotoSession]
384+
session : Optional[Session]
385+
"""
386+
super().__init__(
387+
host=host,
388+
database=database,
389+
collection=collection,
390+
version=version,
391+
boto=boto,
392+
session=session,
393+
)
394+
365395
def retrieve_docdb_records(
366396
self,
367397
filter_query: Optional[dict] = None,

tests/test_document_db.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,6 @@ class TestMetadataDbClient(unittest.TestCase):
437437

438438
example_client_args = {
439439
"host": "example.com/",
440-
"database": "metadata_db",
441-
"collection": "data_assets",
442440
}
443441

444442
example_record_list = [
@@ -452,6 +450,26 @@ class TestMetadataDbClient(unittest.TestCase):
452450
for id_num in range(0, 10)
453451
]
454452

453+
def test_metadatadbclient_constructor(self):
454+
"""Tests class constructor"""
455+
client = MetadataDbClient(**self.example_client_args)
456+
457+
self.assertEqual("example.com", client.host)
458+
self.assertEqual("metadata_index", client.database)
459+
self.assertEqual("data_assets", client.collection)
460+
self.assertEqual("v1", client.version)
461+
self.assertEqual(
462+
"https://example.com/v1/metadata_index/data_assets",
463+
client._base_url,
464+
)
465+
466+
client = MetadataDbClient(**self.example_client_args, version="v2")
467+
self.assertEqual("v2", client.version)
468+
self.assertEqual(
469+
"https://example.com/v2/metadata_index/data_assets",
470+
client._base_url,
471+
)
472+
455473
@patch("aind_data_access_api.document_db.Client._find_records")
456474
def test_retrieve_docdb_records(
457475
self,

0 commit comments

Comments
 (0)