| 406 | self.assertEqual('{"ts": {"$timestamp": {"t": 4, "i": 13}}}', res) |
| 407 | |
| 408 | def test_uuid_default(self): |
| 409 | # Cannot directly encode native UUIDs with the default |
| 410 | # uuid_representation. |
| 411 | doc = {"uuid": uuid.UUID("f47ac10b-58cc-4372-a567-0e02b2c3d479")} |
| 412 | with self.assertRaisesRegex(ValueError, "cannot encode native uuid"): |
| 413 | json_util.dumps(doc) |
| 414 | legacy_jsn = '{"uuid": {"$uuid": "f47ac10b58cc4372a5670e02b2c3d479"}}' |
| 415 | expected = {"uuid": Binary(b"\xf4z\xc1\x0bX\xccCr\xa5g\x0e\x02\xb2\xc3\xd4y", 4)} |
| 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")} |