Skip to content

Commit

Permalink
dbio.mongo: allow for DB URL with query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
RayPlante committed Feb 5, 2024
1 parent 99bef01 commit e1d04a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion python/nistoar/midas/dbio/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from nistoar.base.config import ConfigurationException, merge_config

_dburl_re = re.compile(r"^mongodb://(\w+(:\S+)?@)?\w+(\.\w+)*(:\d+)?/\w+$")
_dburl_re = re.compile(r"^mongodb://(\w+(:\S+)?@)?\w+(\.\w+)*(:\d+)?/\w+(\?\w.*)?$")

class MongoDBClient(base.DBClient):
"""
Expand Down
31 changes: 12 additions & 19 deletions python/tests/nistoar/midas/dbio/test_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def tearDown(self):
client.get_database = client.get_default_database
db = client.get_database()
for coll in [base.GROUPS_COLL, base.PEOPLE_COLL, base.DMP_PROJECTS, base.DRAFT_PROJECTS,
"nextnum", "about", "action_log", "history"]:
"nextnum", "about", "prov_action_log", "history"]:
if coll in db.list_collection_names():
db.drop_collection(coll)

Expand Down Expand Up @@ -346,31 +346,25 @@ def test_select_records(self):
self.assertEqual(recs[0].id, id)

def test_action_log_io(self):
self.assertEqual(self.cli.native['action_log'].count_documents({}), 0)
self.cli._save_action_data(
{'subject': 'goob:gurn', 'foo': 'bar', 'timestamp': 8})
acts = [r for r in self.cli.native['action_log'].find(
{}, {'_id': False})]
self.assertEqual(self.cli.native['prov_action_log'].count_documents({}), 0)
self.cli._save_action_data({'subject': 'goob:gurn', 'foo': 'bar', 'timestamp': 8})
acts = [r for r in self.cli.native['prov_action_log'].find({}, {'_id': False})]
self.assertEqual(len(acts), 1)
self.assertEqual(
acts[0], {'subject': 'goob:gurn', 'foo': 'bar', 'timestamp': 8})

self.cli._save_action_data(
{'subject': 'goob:gurn', 'bob': 'alice', 'timestamp': 5})
acts = [r for r in self.cli.native['action_log'].find(
{}, {'_id': False})]
self.cli._save_action_data({'subject': 'goob:gurn', 'bob': 'alice', 'timestamp': 5})
acts = [r for r in self.cli.native['prov_action_log'].find({}, {'_id': False})]
self.assertEqual(len(acts), 2)
self.assertEqual(
acts[0], {'subject': 'goob:gurn', 'foo': 'bar', 'timestamp': 8})
self.assertEqual(
acts[1], {'subject': 'goob:gurn', 'bob': 'alice', 'timestamp': 5})

self.assertEqual(self.cli.native['action_log'].count_documents(
{'subject': 'grp0001'}), 0)
self.assertEqual(self.cli.native['prov_action_log'].count_documents({'subject': 'grp0001'}), 0)
self.cli._save_action_data({'subject': 'grp0001', 'dylan': 'bob'})
self.assertEqual(self.cli.native['action_log'].count_documents({}), 3)
acts = [r for r in self.cli.native['action_log'].find(
{'subject': 'grp0001'}, {'_id': False})]
self.assertEqual(self.cli.native['prov_action_log'].count_documents({}), 3)
acts = [r for r in self.cli.native['prov_action_log'].find({'subject': 'grp0001'}, {'_id': False})]
self.assertEqual(len(acts), 1)
self.assertEqual(acts[0], {'subject': 'grp0001', 'dylan': 'bob'})

Expand All @@ -386,11 +380,10 @@ def test_action_log_io(self):
self.assertEqual(acts[0], {'subject': 'grp0001', 'dylan': 'bob'})

self.cli._delete_actions_for("grp0001")
self.assertEqual(self.cli.native['action_log'].count_documents({}), 2)
self.assertEqual(self.cli.native['action_log'].count_documents(
{'subject': 'grp0001'}), 0)
self.assertEqual(self.cli.native['prov_action_log'].count_documents({}), 2)
self.assertEqual(self.cli.native['prov_action_log'].count_documents({'subject': 'grp0001'}), 0)
self.cli._delete_actions_for("goob:gurn")
self.assertEqual(self.cli.native['action_log'].count_documents({}), 0)
self.assertEqual(self.cli.native['prov_action_log'].count_documents({}), 0)

self.assertEqual(self.cli._select_actions_for("goob:gurn"), [])
self.assertEqual(self.cli._select_actions_for("grp0001"), [])
Expand Down

0 comments on commit e1d04a6

Please sign in to comment.