forked from libAtoms/abcd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add MongoDB srv support (libAtoms#115)
* support for mongodb + srv URIs * test for the functionality * fix unexpected test behaviour
- Loading branch information
Showing
4 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Tests for supporting `mongodb+srv://` URIs""" | ||
|
||
from pytest import fixture | ||
|
||
from abcd import ABCD | ||
|
||
|
||
@fixture | ||
def mongo_srv(mocker): | ||
# mongomock does not pick up what we need, so this is a bespoke mocker | ||
mock_client = mocker.MagicMock() | ||
mocker.patch("abcd.backends.atoms_pymongo.MongoClient", mock_client) | ||
return mock_client | ||
|
||
|
||
def test_init_mongodb_srv(mongo_srv): | ||
# client can be created with a mongodb+srv:// URI | ||
|
||
# apparently mongomock breaks if this import is outside | ||
from abcd.backends.atoms_pymongo import MongoDatabase | ||
|
||
# regression test | ||
uri = "mongodb+srv://user:[email protected]/?key=value" | ||
|
||
# create the client | ||
abcd = ABCD.from_url(uri) | ||
|
||
assert isinstance(abcd, MongoDatabase) | ||
mongo_srv.assert_called_once_with(host=uri, authSource="admin") |