Skip to content

Commit 0217c9c

Browse files
committed
address review pt 2
1 parent 8c49277 commit 0217c9c

File tree

4 files changed

+23
-41
lines changed

4 files changed

+23
-41
lines changed

test/asynchronous/test_client_metadata.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import pytest
2727

28-
from pymongo import AsyncMongoClient, MongoClient
28+
from pymongo import AsyncMongoClient
2929
from pymongo.driver_info import DriverInfo
3030
from pymongo.monitoring import ConnectionClosedEvent
3131

@@ -67,7 +67,7 @@ def respond(r):
6767
if "ismaster" in r:
6868
# then this is a handshake request
6969
self.handshake_req = r
70-
return r.reply(OpMsgReply(minWireVersion=0, maxWireVersion=13))
70+
return r.reply(OpMsgReply(maxWireVersion=13))
7171

7272
self.server.autoresponds(respond)
7373
self.server.run()
@@ -124,79 +124,71 @@ async def check_metadata_added(
124124
self.assertEqual(metadata, new_metadata)
125125

126126
async def test_append_metadata(self):
127-
client = AsyncMongoClient(
127+
client = await self.async_rs_or_single_client(
128128
"mongodb://" + self.server.address_string,
129129
maxIdleTimeMS=1,
130130
driver=DriverInfo("library", "1.2", "Library Platform"),
131131
)
132132
await self.check_metadata_added(client, "framework", "2.0", "Framework Platform")
133-
await client.close()
134133

135134
async def test_append_metadata_platform_none(self):
136-
client = AsyncMongoClient(
135+
client = await self.async_rs_or_single_client(
137136
"mongodb://" + self.server.address_string,
138137
maxIdleTimeMS=1,
139138
driver=DriverInfo("library", "1.2", "Library Platform"),
140139
)
141140
await self.check_metadata_added(client, "framework", "2.0", None)
142-
await client.close()
143141

144142
async def test_append_metadata_version_none(self):
145-
client = AsyncMongoClient(
143+
client = await self.async_rs_or_single_client(
146144
"mongodb://" + self.server.address_string,
147145
maxIdleTimeMS=1,
148146
driver=DriverInfo("library", "1.2", "Library Platform"),
149147
)
150148
await self.check_metadata_added(client, "framework", None, "Framework Platform")
151-
await client.close()
152149

153150
async def test_append_metadata_platform_version_none(self):
154-
client = AsyncMongoClient(
151+
client = await self.async_rs_or_single_client(
155152
"mongodb://" + self.server.address_string,
156153
maxIdleTimeMS=1,
157154
driver=DriverInfo("library", "1.2", "Library Platform"),
158155
)
159156
await self.check_metadata_added(client, "framework", None, None)
160-
await client.close()
161157

162158
async def test_multiple_successive_metadata_updates(self):
163-
client = AsyncMongoClient(
159+
client = await self.async_rs_or_single_client(
164160
"mongodb://" + self.server.address_string, maxIdleTimeMS=1, connect=False
165161
)
166162
client.append_metadata(DriverInfo("library", "1.2", "Library Platform"))
167163
await self.check_metadata_added(client, "framework", "2.0", "Framework Platform")
168-
await client.close()
169164

170165
async def test_multiple_successive_metadata_updates_platform_none(self):
171-
client = AsyncMongoClient(
166+
client = await self.async_rs_or_single_client(
172167
"mongodb://" + self.server.address_string,
173168
maxIdleTimeMS=1,
174169
)
175170
client.append_metadata(DriverInfo("library", "1.2", "Library Platform"))
176171
await self.check_metadata_added(client, "framework", "2.0", None)
177-
await client.close()
178172

179173
async def test_multiple_successive_metadata_updates_version_none(self):
180-
client = AsyncMongoClient(
174+
client = await self.async_rs_or_single_client(
181175
"mongodb://" + self.server.address_string,
182176
maxIdleTimeMS=1,
183177
)
184178
client.append_metadata(DriverInfo("library", "1.2", "Library Platform"))
185179
await self.check_metadata_added(client, "framework", None, "Framework Platform")
186-
await client.close()
187180

188181
async def test_multiple_successive_metadata_updates_platform_version_none(self):
189-
client = AsyncMongoClient(
182+
client = await self.async_rs_or_single_client(
190183
"mongodb://" + self.server.address_string,
191184
maxIdleTimeMS=1,
192185
)
193186
client.append_metadata(DriverInfo("library", "1.2", "Library Platform"))
194187
await self.check_metadata_added(client, "framework", None, None)
195-
await client.close()
196188

197189
async def test_doesnt_update_established_connections(self):
198190
listener = CMAPListener()
199-
client = AsyncMongoClient(
191+
client = await self.async_rs_or_single_client(
200192
"mongodb://" + self.server.address_string,
201193
maxIdleTimeMS=1,
202194
driver=DriverInfo("library", "1.2", "Library Platform"),
@@ -218,8 +210,6 @@ async def test_doesnt_update_established_connections(self):
218210
self.assertIsNone(self.handshake_req)
219211
self.assertEqual(listener.event_count(ConnectionClosedEvent), 0)
220212

221-
await client.close()
222-
223213

224214
if __name__ == "__main__":
225215
unittest.main()

test/asynchronous/unified_format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ async def run_entity_operation(self, spec):
931931
)
932932
else:
933933
arguments = {}
934+
934935
if isinstance(target, AsyncMongoClient):
935936
method_name = f"_clientOperation_{opname}"
936937
elif isinstance(target, AsyncDatabase):

test/test_client_metadata.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def respond(r):
6767
if "ismaster" in r:
6868
# then this is a handshake request
6969
self.handshake_req = r
70-
return r.reply(OpMsgReply(minWireVersion=0, maxWireVersion=13))
70+
return r.reply(OpMsgReply(maxWireVersion=13))
7171

7272
self.server.autoresponds(respond)
7373
self.server.run()
@@ -124,79 +124,71 @@ def check_metadata_added(
124124
self.assertEqual(metadata, new_metadata)
125125

126126
def test_append_metadata(self):
127-
client = MongoClient(
127+
client = self.rs_or_single_client(
128128
"mongodb://" + self.server.address_string,
129129
maxIdleTimeMS=1,
130130
driver=DriverInfo("library", "1.2", "Library Platform"),
131131
)
132132
self.check_metadata_added(client, "framework", "2.0", "Framework Platform")
133-
client.close()
134133

135134
def test_append_metadata_platform_none(self):
136-
client = MongoClient(
135+
client = self.rs_or_single_client(
137136
"mongodb://" + self.server.address_string,
138137
maxIdleTimeMS=1,
139138
driver=DriverInfo("library", "1.2", "Library Platform"),
140139
)
141140
self.check_metadata_added(client, "framework", "2.0", None)
142-
client.close()
143141

144142
def test_append_metadata_version_none(self):
145-
client = MongoClient(
143+
client = self.rs_or_single_client(
146144
"mongodb://" + self.server.address_string,
147145
maxIdleTimeMS=1,
148146
driver=DriverInfo("library", "1.2", "Library Platform"),
149147
)
150148
self.check_metadata_added(client, "framework", None, "Framework Platform")
151-
client.close()
152149

153150
def test_append_metadata_platform_version_none(self):
154-
client = MongoClient(
151+
client = self.rs_or_single_client(
155152
"mongodb://" + self.server.address_string,
156153
maxIdleTimeMS=1,
157154
driver=DriverInfo("library", "1.2", "Library Platform"),
158155
)
159156
self.check_metadata_added(client, "framework", None, None)
160-
client.close()
161157

162158
def test_multiple_successive_metadata_updates(self):
163-
client = MongoClient(
159+
client = self.rs_or_single_client(
164160
"mongodb://" + self.server.address_string, maxIdleTimeMS=1, connect=False
165161
)
166162
client.append_metadata(DriverInfo("library", "1.2", "Library Platform"))
167163
self.check_metadata_added(client, "framework", "2.0", "Framework Platform")
168-
client.close()
169164

170165
def test_multiple_successive_metadata_updates_platform_none(self):
171-
client = MongoClient(
166+
client = self.rs_or_single_client(
172167
"mongodb://" + self.server.address_string,
173168
maxIdleTimeMS=1,
174169
)
175170
client.append_metadata(DriverInfo("library", "1.2", "Library Platform"))
176171
self.check_metadata_added(client, "framework", "2.0", None)
177-
client.close()
178172

179173
def test_multiple_successive_metadata_updates_version_none(self):
180-
client = MongoClient(
174+
client = self.rs_or_single_client(
181175
"mongodb://" + self.server.address_string,
182176
maxIdleTimeMS=1,
183177
)
184178
client.append_metadata(DriverInfo("library", "1.2", "Library Platform"))
185179
self.check_metadata_added(client, "framework", None, "Framework Platform")
186-
client.close()
187180

188181
def test_multiple_successive_metadata_updates_platform_version_none(self):
189-
client = MongoClient(
182+
client = self.rs_or_single_client(
190183
"mongodb://" + self.server.address_string,
191184
maxIdleTimeMS=1,
192185
)
193186
client.append_metadata(DriverInfo("library", "1.2", "Library Platform"))
194187
self.check_metadata_added(client, "framework", None, None)
195-
client.close()
196188

197189
def test_doesnt_update_established_connections(self):
198190
listener = CMAPListener()
199-
client = MongoClient(
191+
client = self.rs_or_single_client(
200192
"mongodb://" + self.server.address_string,
201193
maxIdleTimeMS=1,
202194
driver=DriverInfo("library", "1.2", "Library Platform"),
@@ -218,8 +210,6 @@ def test_doesnt_update_established_connections(self):
218210
self.assertIsNone(self.handshake_req)
219211
self.assertEqual(listener.event_count(ConnectionClosedEvent), 0)
220212

221-
client.close()
222-
223213

224214
if __name__ == "__main__":
225215
unittest.main()

test/unified_format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ def run_entity_operation(self, spec):
922922
)
923923
else:
924924
arguments = {}
925+
925926
if isinstance(target, MongoClient):
926927
method_name = f"_clientOperation_{opname}"
927928
elif isinstance(target, Database):

0 commit comments

Comments
 (0)