Skip to content

Commit

Permalink
test for the functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
stenczelt committed Jun 13, 2024
1 parent 15dea3d commit 230ae8d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lark = "^1.1.9"
mongomock = "^4.1.2"
pytest = "^8.2.2"
pytest-cov = "^5.0.0"
pytest-mock = "^3.14.0"

[tool.poetry.extras]
tests = ["mongomock", "pytest", "pytest-cov"]
Expand Down
27 changes: 27 additions & 0 deletions tests/test_mongodb_srv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Tests for supporting `mongodb+srv://` URIs"""

from pytest import fixture

from abcd import ABCD
from abcd.backends.atoms_pymongo import MongoDatabase


@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

# 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")

0 comments on commit 230ae8d

Please sign in to comment.