-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MOTOR-735 Versioned API connection examples for ecosystem docs #126
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote this to mimic the PyMongo PR - mongodb/mongo-python-driver@048f54d There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's to reduce the overhead of the test. Since the test doesn't need to actually use the MongoClient there's no point in starting all the monitor threads. Let's keep it and add a comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to bump this here since 3.11 doesn't have
pymongo.server_api
. One less ticket!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Can you link MOTOR-699 in the commit message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do! Thanks for pulling up the ticket.