Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
Copy link
Contributor Author

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!

Copy link
Member

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?

Copy link
Contributor Author

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.


install_requires = ["pymongo" + pymongo_ver]

Expand Down
29 changes: 29 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,31 @@ 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
def test_versioned_api(self):
# Versioned API examples
AsyncIOMotorClient = lambda _, server_api: self.asyncio_client(
server_api=server_api, connect=False)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
But I have no idea why we set connect=False? Can we remove it?

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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