|
24 | 24 | from pymongo.errors import ConnectionFailure, OperationFailure
|
25 | 25 | from pymongo.read_concern import ReadConcern
|
26 | 26 | from pymongo.read_preferences import ReadPreference
|
| 27 | +from pymongo.server_api import ServerApi |
27 | 28 | from pymongo.write_concern import WriteConcern
|
28 | 29 |
|
29 | 30 | from test import client_context, unittest, IntegrationTest
|
@@ -1108,5 +1109,34 @@ def test_causal_consistency(self):
|
1108 | 1109 | # End Causal Consistency Example 2
|
1109 | 1110 |
|
1110 | 1111 |
|
| 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 | + |
1111 | 1141 | if __name__ == "__main__":
|
1112 | 1142 | unittest.main()
|
0 commit comments