Skip to content

Commit ecd5116

Browse files
committed
PYTHON-2710 Version API connection examples for ecosystem docs (#636)
(cherry picked from commit 048f54d)
1 parent a5e8559 commit ecd5116

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/test_examples.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from pymongo.errors import ConnectionFailure, OperationFailure
2525
from pymongo.read_concern import ReadConcern
2626
from pymongo.read_preferences import ReadPreference
27+
from pymongo.server_api import ServerApi
2728
from pymongo.write_concern import WriteConcern
2829

2930
from test import client_context, unittest, IntegrationTest
@@ -1108,5 +1109,34 @@ def test_causal_consistency(self):
11081109
# End Causal Consistency Example 2
11091110

11101111

1112+
class TestVersionedApiExamples(IntegrationTest):
1113+
@client_context.require_version_min(4, 7)
1114+
def test_versioned_api(self):
1115+
# Versioned API examples
1116+
MongoClient = lambda _, server_api: rs_client(
1117+
server_api=server_api, connect=False)
1118+
uri = None
1119+
1120+
# Start Versioned API Example 1
1121+
from pymongo.server_api import ServerApi
1122+
client = MongoClient(uri, server_api=ServerApi("1"))
1123+
# End Versioned API Example 1
1124+
1125+
# Start Versioned API Example 2
1126+
client = MongoClient(
1127+
uri, server_api=ServerApi("1", strict=True))
1128+
# End Versioned API Example 2
1129+
1130+
# Start Versioned API Example 3
1131+
client = MongoClient(
1132+
uri, server_api=ServerApi("1", strict=False))
1133+
# End Versioned API Example 3
1134+
1135+
# Start Versioned API Example 4
1136+
client = MongoClient(
1137+
uri, server_api=ServerApi("1", deprecation_errors=True))
1138+
# End Versioned API Example 4
1139+
1140+
11111141
if __name__ == "__main__":
11121142
unittest.main()

0 commit comments

Comments
 (0)