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

Method test_uuid

test/test_json_util.py:418–465  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

416 self.assertEqual(json_util.loads(legacy_jsn), expected)
417
418 def test_uuid(self):
419 doc = {"uuid": uuid.UUID("f47ac10b-58cc-4372-a567-0e02b2c3d479")}
420 uuid_legacy_opts = LEGACY_JSON_OPTIONS.with_options(
421 uuid_representation=UuidRepresentation.PYTHON_LEGACY
422 )
423 self.round_trip(doc, json_options=uuid_legacy_opts)
424 self.assertEqual(
425 '{"uuid": {"$uuid": "f47ac10b58cc4372a5670e02b2c3d479"}}',
426 json_util.dumps(doc, json_options=LEGACY_JSON_OPTIONS),
427 )
428 self.assertEqual(
429 '{"uuid": {"$binary": "9HrBC1jMQ3KlZw4CssPUeQ==", "$type": "03"}}',
430 json_util.dumps(
431 doc,
432 json_options=STRICT_JSON_OPTIONS.with_options(
433 uuid_representation=UuidRepresentation.PYTHON_LEGACY
434 ),
435 ),
436 )
437 self.assertEqual(
438 '{"uuid": {"$binary": "9HrBC1jMQ3KlZw4CssPUeQ==", "$type": "04"}}',
439 json_util.dumps(
440 doc,
441 json_options=JSONOptions(
442 strict_uuid=True, json_mode=JSONMode.LEGACY, uuid_representation=STANDARD
443 ),
444 ),
445 )
446 self.assertEqual(
447 doc,
448 json_util.loads(
449 '{"uuid": {"$binary": "9HrBC1jMQ3KlZw4CssPUeQ==", "$type": "03"}}',
450 json_options=uuid_legacy_opts,
451 ),
452 )
453 for uuid_representation in set(ALL_UUID_REPRESENTATIONS) - {UuidRepresentation.UNSPECIFIED}:
454 options = JSONOptions(
455 strict_uuid=True, json_mode=JSONMode.LEGACY, uuid_representation=uuid_representation
456 )
457 self.round_trip(doc, json_options=options)
458 # Ignore UUID representation when decoding BSON binary subtype 4.
459 self.assertEqual(
460 doc,
461 json_util.loads(
462 '{"uuid": {"$binary": "9HrBC1jMQ3KlZw4CssPUeQ==", "$type": "04"}}',
463 json_options=options,
464 ),
465 )
466
467 def test_uuid_uuid_rep_unspecified(self):
468 _uuid = uuid.uuid4()

Callers

nothing calls this directly

Calls 3

round_tripMethod · 0.95
JSONOptionsClass · 0.90
with_optionsMethod · 0.45

Tested by

no test coverage detected