MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / mock_hello

Method mock_hello

test/pymongo_mocks.py:185–246  ·  view source on GitHub ↗

Return mock hello response (a dict) and round trip time.

(self, host)

Source from the content-addressed store, hash-verified

183 self.mock_max_write_batch_sizes[host] = size
184
185 def mock_hello(self, host):
186 """Return mock hello response (a dict) and round trip time."""
187 if host in self.mock_wire_versions:
188 min_wire_version, max_wire_version = self.mock_wire_versions[host]
189 else:
190 min_wire_version = common.MIN_SUPPORTED_WIRE_VERSION
191 max_wire_version = common.MAX_SUPPORTED_WIRE_VERSION
192
193 max_write_batch_size = self.mock_max_write_batch_sizes.get(
194 host, common.MAX_WRITE_BATCH_SIZE
195 )
196
197 rtt = self.mock_rtts.get(host, 0)
198
199 # host is like 'a:1'.
200 if host in self.mock_down_hosts:
201 raise NetworkTimeout("mock timeout")
202
203 elif host in self.mock_standalones:
204 response = {
205 "ok": 1,
206 HelloCompat.LEGACY_CMD: True,
207 "minWireVersion": min_wire_version,
208 "maxWireVersion": max_wire_version,
209 "maxWriteBatchSize": max_write_batch_size,
210 }
211 elif host in self.mock_members:
212 primary = host == self.mock_primary
213
214 # Simulate a replica set member.
215 response = {
216 "ok": 1,
217 HelloCompat.LEGACY_CMD: primary,
218 "secondary": not primary,
219 "setName": "rs",
220 "hosts": self.mock_hello_hosts,
221 "minWireVersion": min_wire_version,
222 "maxWireVersion": max_wire_version,
223 "maxWriteBatchSize": max_write_batch_size,
224 }
225
226 if self.mock_primary:
227 response["primary"] = self.mock_primary
228
229 if host in self.mock_arbiters:
230 response["arbiterOnly"] = True
231 response["secondary"] = False
232 elif host in self.mock_mongoses:
233 response = {
234 "ok": 1,
235 HelloCompat.LEGACY_CMD: True,
236 "minWireVersion": min_wire_version,
237 "maxWireVersion": max_wire_version,
238 "msg": "isdbgrid",
239 "maxWriteBatchSize": max_write_batch_size,
240 }
241 else:
242 # In test_internal_ips(), we try to connect to a host listed

Callers 1

_check_onceMethod · 0.45

Calls 3

NetworkTimeoutClass · 0.90
AutoReconnectClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected