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

Method test_metadata

test/test_client.py:335–405  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

333 self.assertEqual(c.read_preference, ReadPreference.NEAREST)
334
335 def test_metadata(self):
336 metadata = copy.deepcopy(_METADATA)
337 if has_c():
338 metadata["driver"]["name"] = "PyMongo|c"
339 else:
340 metadata["driver"]["name"] = "PyMongo"
341 metadata["application"] = {"name": "foobar"}
342 client = self.simple_client("mongodb://foo:27017/?appname=foobar&connect=false")
343 options = client.options
344 self.assertEqual(options.pool_options.metadata, metadata)
345 client = self.simple_client("foo", 27017, appname="foobar", connect=False)
346 options = client.options
347 self.assertEqual(options.pool_options.metadata, metadata)
348 # No error
349 self.simple_client(appname="x" * 128)
350 with self.assertRaises(ValueError):
351 self.simple_client(appname="x" * 129)
352 # Bad "driver" options.
353 self.assertRaises(TypeError, DriverInfo, "Foo", 1, "a")
354 self.assertRaises(TypeError, DriverInfo, version="1", platform="a")
355 self.assertRaises(TypeError, DriverInfo)
356 with self.assertRaises(TypeError):
357 self.simple_client(driver=1)
358 with self.assertRaises(TypeError):
359 self.simple_client(driver="abc")
360 with self.assertRaises(TypeError):
361 self.simple_client(driver=("Foo", "1", "a"))
362 # Test appending to driver info.
363 if has_c():
364 metadata["driver"]["name"] = "PyMongo|c|FooDriver"
365 else:
366 metadata["driver"]["name"] = "PyMongo|FooDriver"
367 metadata["driver"]["version"] = "{}|1.2.3".format(_METADATA["driver"]["version"])
368 client = self.simple_client(
369 "foo",
370 27017,
371 appname="foobar",
372 driver=DriverInfo("FooDriver", "1.2.3", None),
373 connect=False,
374 )
375 options = client.options
376 self.assertEqual(options.pool_options.metadata, metadata)
377 metadata["platform"] = "{}|FooPlatform".format(_METADATA["platform"])
378 client = self.simple_client(
379 "foo",
380 27017,
381 appname="foobar",
382 driver=DriverInfo("FooDriver", "1.2.3", "FooPlatform"),
383 connect=False,
384 )
385 options = client.options
386 self.assertEqual(options.pool_options.metadata, metadata)
387 # Test truncating driver info metadata.
388 client = self.simple_client(
389 driver=DriverInfo(name="s" * _MAX_METADATA_SIZE),
390 connect=False,
391 )
392 options = client.options

Callers

nothing calls this directly

Calls 4

has_cFunction · 0.90
DriverInfoClass · 0.90
encodeMethod · 0.80
simple_clientMethod · 0.45

Tested by

no test coverage detected