25
25
26
26
import pytest
27
27
28
- from pymongo import AsyncMongoClient , MongoClient
28
+ from pymongo import AsyncMongoClient
29
29
from pymongo .driver_info import DriverInfo
30
30
from pymongo .monitoring import ConnectionClosedEvent
31
31
@@ -67,7 +67,7 @@ def respond(r):
67
67
if "ismaster" in r :
68
68
# then this is a handshake request
69
69
self .handshake_req = r
70
- return r .reply (OpMsgReply (minWireVersion = 0 , maxWireVersion = 13 ))
70
+ return r .reply (OpMsgReply (maxWireVersion = 13 ))
71
71
72
72
self .server .autoresponds (respond )
73
73
self .server .run ()
@@ -124,79 +124,71 @@ async def check_metadata_added(
124
124
self .assertEqual (metadata , new_metadata )
125
125
126
126
async def test_append_metadata (self ):
127
- client = AsyncMongoClient (
127
+ client = await self . async_rs_or_single_client (
128
128
"mongodb://" + self .server .address_string ,
129
129
maxIdleTimeMS = 1 ,
130
130
driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
131
131
)
132
132
await self .check_metadata_added (client , "framework" , "2.0" , "Framework Platform" )
133
- await client .close ()
134
133
135
134
async def test_append_metadata_platform_none (self ):
136
- client = AsyncMongoClient (
135
+ client = await self . async_rs_or_single_client (
137
136
"mongodb://" + self .server .address_string ,
138
137
maxIdleTimeMS = 1 ,
139
138
driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
140
139
)
141
140
await self .check_metadata_added (client , "framework" , "2.0" , None )
142
- await client .close ()
143
141
144
142
async def test_append_metadata_version_none (self ):
145
- client = AsyncMongoClient (
143
+ client = await self . async_rs_or_single_client (
146
144
"mongodb://" + self .server .address_string ,
147
145
maxIdleTimeMS = 1 ,
148
146
driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
149
147
)
150
148
await self .check_metadata_added (client , "framework" , None , "Framework Platform" )
151
- await client .close ()
152
149
153
150
async def test_append_metadata_platform_version_none (self ):
154
- client = AsyncMongoClient (
151
+ client = await self . async_rs_or_single_client (
155
152
"mongodb://" + self .server .address_string ,
156
153
maxIdleTimeMS = 1 ,
157
154
driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
158
155
)
159
156
await self .check_metadata_added (client , "framework" , None , None )
160
- await client .close ()
161
157
162
158
async def test_multiple_successive_metadata_updates (self ):
163
- client = AsyncMongoClient (
159
+ client = await self . async_rs_or_single_client (
164
160
"mongodb://" + self .server .address_string , maxIdleTimeMS = 1 , connect = False
165
161
)
166
162
client .append_metadata (DriverInfo ("library" , "1.2" , "Library Platform" ))
167
163
await self .check_metadata_added (client , "framework" , "2.0" , "Framework Platform" )
168
- await client .close ()
169
164
170
165
async def test_multiple_successive_metadata_updates_platform_none (self ):
171
- client = AsyncMongoClient (
166
+ client = await self . async_rs_or_single_client (
172
167
"mongodb://" + self .server .address_string ,
173
168
maxIdleTimeMS = 1 ,
174
169
)
175
170
client .append_metadata (DriverInfo ("library" , "1.2" , "Library Platform" ))
176
171
await self .check_metadata_added (client , "framework" , "2.0" , None )
177
- await client .close ()
178
172
179
173
async def test_multiple_successive_metadata_updates_version_none (self ):
180
- client = AsyncMongoClient (
174
+ client = await self . async_rs_or_single_client (
181
175
"mongodb://" + self .server .address_string ,
182
176
maxIdleTimeMS = 1 ,
183
177
)
184
178
client .append_metadata (DriverInfo ("library" , "1.2" , "Library Platform" ))
185
179
await self .check_metadata_added (client , "framework" , None , "Framework Platform" )
186
- await client .close ()
187
180
188
181
async def test_multiple_successive_metadata_updates_platform_version_none (self ):
189
- client = AsyncMongoClient (
182
+ client = await self . async_rs_or_single_client (
190
183
"mongodb://" + self .server .address_string ,
191
184
maxIdleTimeMS = 1 ,
192
185
)
193
186
client .append_metadata (DriverInfo ("library" , "1.2" , "Library Platform" ))
194
187
await self .check_metadata_added (client , "framework" , None , None )
195
- await client .close ()
196
188
197
189
async def test_doesnt_update_established_connections (self ):
198
190
listener = CMAPListener ()
199
- client = AsyncMongoClient (
191
+ client = await self . async_rs_or_single_client (
200
192
"mongodb://" + self .server .address_string ,
201
193
maxIdleTimeMS = 1 ,
202
194
driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
@@ -218,8 +210,6 @@ async def test_doesnt_update_established_connections(self):
218
210
self .assertIsNone (self .handshake_req )
219
211
self .assertEqual (listener .event_count (ConnectionClosedEvent ), 0 )
220
212
221
- await client .close ()
222
-
223
213
224
214
if __name__ == "__main__" :
225
215
unittest .main ()
0 commit comments