From f4bfc7bddd08af88acaf9a3cde051dda01c1a9e9 Mon Sep 17 00:00:00 2001 From: kari Barry Date: Thu, 28 Mar 2024 11:54:29 -0400 Subject: [PATCH 1/7] Remove index creation form _init_, declare public method --- suitcase/mongo_normalized/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/suitcase/mongo_normalized/__init__.py b/suitcase/mongo_normalized/__init__.py index af68543..6a2b478 100644 --- a/suitcase/mongo_normalized/__init__.py +++ b/suitcase/mongo_normalized/__init__.py @@ -83,9 +83,8 @@ def __init__( self._asset_registry_db = assets_db self._ignore_duplicates = ignore_duplicates self._resource_uid_unique = resource_uid_unique - self._create_indexes() - def _create_indexes(self): + def create_indexes(self): """ Create indexes on the various collections. From 3db93a5f343b4ebbfa441cc9c54060951cfd09d4 Mon Sep 17 00:00:00 2001 From: kari Barry Date: Fri, 29 Mar 2024 16:12:32 -0400 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F=20Pass=20test=20gud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- suitcase/mongo_normalized/tests/fixtures.py | 8 ++++++-- suitcase/mongo_normalized/tests/tests.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/suitcase/mongo_normalized/tests/fixtures.py b/suitcase/mongo_normalized/tests/fixtures.py index 2fca399..ad3267b 100644 --- a/suitcase/mongo_normalized/tests/fixtures.py +++ b/suitcase/mongo_normalized/tests/fixtures.py @@ -4,6 +4,8 @@ import mongomock import pytest import uuid +from suitcase.mongo_normalized import Serializer + @pytest.fixture() @@ -12,10 +14,12 @@ def inner(): database_name = f'test-{str(uuid.uuid4())}' uri = 'mongodb://localhost:27017/' client = mongomock.MongoClient(uri) - def drop(): client.drop_database(database_name) request.addfinalizer(drop) - return client[database_name] + db = client[database_name] + serializer = Serializer(db, db) + serializer.create_indexes() + return db return inner diff --git a/suitcase/mongo_normalized/tests/tests.py b/suitcase/mongo_normalized/tests/tests.py index 2ba7b5a..af9fec6 100644 --- a/suitcase/mongo_normalized/tests/tests.py +++ b/suitcase/mongo_normalized/tests/tests.py @@ -23,6 +23,7 @@ def test_duplicates(db_factory, example_data): metadatastore_db = db_factory() asset_registry_db = db_factory() serializer = Serializer(metadatastore_db, asset_registry_db) + for item in documents: serializer(*item) for item in documents: From 945cd4420fde2a3a54c6307e5a27ca02a7844b47 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Fri, 29 Mar 2024 16:35:08 -0400 Subject: [PATCH 3/7] Satisfy linter --- suitcase/mongo_normalized/tests/fixtures.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/suitcase/mongo_normalized/tests/fixtures.py b/suitcase/mongo_normalized/tests/fixtures.py index ad3267b..c5ec535 100644 --- a/suitcase/mongo_normalized/tests/fixtures.py +++ b/suitcase/mongo_normalized/tests/fixtures.py @@ -7,19 +7,19 @@ from suitcase.mongo_normalized import Serializer - @pytest.fixture() def db_factory(request): def inner(): database_name = f'test-{str(uuid.uuid4())}' uri = 'mongodb://localhost:27017/' client = mongomock.MongoClient(uri) + db = client[database_name] + serializer = Serializer(db, db) + serializer.create_indexes() + def drop(): client.drop_database(database_name) request.addfinalizer(drop) - db = client[database_name] - serializer = Serializer(db, db) - serializer.create_indexes() return db return inner From 380c758ae644fcec80c9162a57b9b34566b12869 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Fri, 29 Mar 2024 16:38:05 -0400 Subject: [PATCH 4/7] whitespace --- suitcase/mongo_normalized/tests/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/suitcase/mongo_normalized/tests/tests.py b/suitcase/mongo_normalized/tests/tests.py index af9fec6..acdac7f 100644 --- a/suitcase/mongo_normalized/tests/tests.py +++ b/suitcase/mongo_normalized/tests/tests.py @@ -23,7 +23,7 @@ def test_duplicates(db_factory, example_data): metadatastore_db = db_factory() asset_registry_db = db_factory() serializer = Serializer(metadatastore_db, asset_registry_db) - + for item in documents: serializer(*item) for item in documents: From f315c951591f207d9e39be02b978cd3040d786cd Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Fri, 29 Mar 2024 17:05:06 -0400 Subject: [PATCH 5/7] Add fixture without indexes for special tests. --- suitcase/mongo_normalized/tests/fixtures.py | 15 +++++++++++++++ suitcase/mongo_normalized/tests/tests.py | 10 ++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/suitcase/mongo_normalized/tests/fixtures.py b/suitcase/mongo_normalized/tests/fixtures.py index c5ec535..fc7ac8e 100644 --- a/suitcase/mongo_normalized/tests/fixtures.py +++ b/suitcase/mongo_normalized/tests/fixtures.py @@ -7,6 +7,21 @@ from suitcase.mongo_normalized import Serializer +@pytest.fixture() +def db_factory_no_indexes(request): + def inner(): + database_name = f'test-{str(uuid.uuid4())}' + uri = 'mongodb://localhost:27017/' + client = mongomock.MongoClient(uri) + db = client[database_name] + + def drop(): + client.drop_database(database_name) + + request.addfinalizer(drop) + return db + return inner + @pytest.fixture() def db_factory(request): def inner(): diff --git a/suitcase/mongo_normalized/tests/tests.py b/suitcase/mongo_normalized/tests/tests.py index acdac7f..9bfac81 100644 --- a/suitcase/mongo_normalized/tests/tests.py +++ b/suitcase/mongo_normalized/tests/tests.py @@ -205,12 +205,10 @@ def test_index_creation(db_factory): assert indexes["descriptor_-1_time_1"] -def test_resource_uid_unique(db_factory): - db = db_factory() - print(type(db)) - metadatastore_db = db_factory() - asset_registry_db = db_factory() - Serializer(metadatastore_db, asset_registry_db, resource_uid_unique=True) +def test_resource_uid_unique(db_factory_no_indexes): + metadatastore_db = db_factory_no_indexes() + asset_registry_db = db_factory_no_indexes() + Serializer(metadatastore_db, asset_registry_db, resource_uid_unique=True).create_indexes() indexes = asset_registry_db.resource.index_information() assert indexes["uid_1"].get("unique") From 5fd9592538693e1ca06a297bdd19272946ed9db1 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Fri, 29 Mar 2024 17:05:28 -0400 Subject: [PATCH 6/7] whitespace --- suitcase/mongo_normalized/tests/fixtures.py | 1 + 1 file changed, 1 insertion(+) diff --git a/suitcase/mongo_normalized/tests/fixtures.py b/suitcase/mongo_normalized/tests/fixtures.py index fc7ac8e..e0c3103 100644 --- a/suitcase/mongo_normalized/tests/fixtures.py +++ b/suitcase/mongo_normalized/tests/fixtures.py @@ -22,6 +22,7 @@ def drop(): return db return inner + @pytest.fixture() def db_factory(request): def inner(): From dcfac69d283dff3d75f78c47757a6ec2d84551e3 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Mon, 1 Apr 2024 10:13:30 -0400 Subject: [PATCH 7/7] Expose fixture in conftest --- suitcase/mongo_normalized/tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/suitcase/mongo_normalized/tests/conftest.py b/suitcase/mongo_normalized/tests/conftest.py index 6f365cb..e4e5157 100644 --- a/suitcase/mongo_normalized/tests/conftest.py +++ b/suitcase/mongo_normalized/tests/conftest.py @@ -2,4 +2,4 @@ from ophyd.tests.conftest import hw # noqa from suitcase.utils.tests.conftest import ( # noqa example_data, generate_data, plan_type, detector_list, event_type) -from .fixtures import db_factory # noqa +from .fixtures import db_factory, db_factory_no_indexes # noqa