Skip to content

Commit

Permalink
MOTOR-735 Versioned API connection examples for ecosystem docs (#126)
Browse files Browse the repository at this point in the history
* MOTOR-699 Update PyMongo dependency to 3.12
  • Loading branch information
prashantmital committed Jul 22, 2021
1 parent d6ed164 commit b0a79e1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
with open("README.rst") as readme:
long_description = readme.read()

pymongo_ver = ">=3.11,<4"
pymongo_ver = ">=3.12,<4"

install_requires = ["pymongo" + pymongo_ver]

Expand Down
31 changes: 31 additions & 0 deletions test/asyncio_tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pymongo.errors import ConnectionFailure, OperationFailure
from pymongo.read_concern import ReadConcern
from pymongo.read_preferences import ReadPreference
from pymongo.server_api import ServerApi

from test import env
from test.asyncio_tests import AsyncIOTestCase, asyncio_test
Expand Down Expand Up @@ -1107,3 +1108,33 @@ async def test_causal_consistency(self):
async for item in items.find({'end': None}, session=s2):
print(item)
# End Causal Consistency Example 2

@env.require_version_min(4, 7)
@asyncio_test
async def test_versioned_api(self):
# Versioned API examples
# Use connect=False to reduce overhead as client is not used to run
# any operations.
AsyncIOMotorClient = lambda _, server_api: self.asyncio_client(
server_api=server_api, connect=False)
uri = None

# Start Versioned API Example 1
from pymongo.server_api import ServerApi
client = AsyncIOMotorClient(uri, server_api=ServerApi("1"))
# End Versioned API Example 1

# Start Versioned API Example 2
client = AsyncIOMotorClient(
uri, server_api=ServerApi("1", strict=True))
# End Versioned API Example 2

# Start Versioned API Example 3
client = AsyncIOMotorClient(
uri, server_api=ServerApi("1", strict=False))
# End Versioned API Example 3

# Start Versioned API Example 4
client = AsyncIOMotorClient(
uri, server_api=ServerApi("1", deprecation_errors=True))
# End Versioned API Example 4

0 comments on commit b0a79e1

Please sign in to comment.