|
33 | 33 | from bson import json_util, EPOCH_AWARE, EPOCH_NAIVE, SON |
34 | 34 | from bson.json_util import (DatetimeRepresentation, |
35 | 35 | STRICT_JSON_OPTIONS) |
36 | | -from bson.binary import (Binary, MD5_SUBTYPE, USER_DEFINED_SUBTYPE, |
37 | | - JAVA_LEGACY, CSHARP_LEGACY, STANDARD) |
| 36 | +from bson.binary import (ALL_UUID_REPRESENTATIONS, Binary, MD5_SUBTYPE, |
| 37 | + USER_DEFINED_SUBTYPE, JAVA_LEGACY, CSHARP_LEGACY, |
| 38 | + STANDARD) |
38 | 39 | from bson.code import Code |
39 | 40 | from bson.dbref import DBRef |
40 | 41 | from bson.int64 import Int64 |
@@ -268,12 +269,14 @@ def test_uuid(self): |
268 | 269 | strict_uuid=True, uuid_representation=STANDARD))) |
269 | 270 | self.assertEqual(doc, json_util.loads( |
270 | 271 | '{"uuid": {"$binary": "9HrBC1jMQ3KlZw4CssPUeQ==", "$type": "03"}}')) |
271 | | - self.assertEqual(doc, json_util.loads( |
272 | | - '{"uuid": {"$binary": "9HrBC1jMQ3KlZw4CssPUeQ==", "$type": "04"}}')) |
273 | | - self.round_trip(doc, json_options=json_util.JSONOptions( |
274 | | - strict_uuid=True, uuid_representation=JAVA_LEGACY)) |
275 | | - self.round_trip(doc, json_options=json_util.JSONOptions( |
276 | | - strict_uuid=True, uuid_representation=CSHARP_LEGACY)) |
| 272 | + for uuid_representation in ALL_UUID_REPRESENTATIONS: |
| 273 | + options = json_util.JSONOptions( |
| 274 | + strict_uuid=True, uuid_representation=uuid_representation) |
| 275 | + self.round_trip(doc, json_options=options) |
| 276 | + # Ignore UUID representation when decoding BSON binary subtype 4. |
| 277 | + self.assertEqual(doc, json_util.loads( |
| 278 | + '{"uuid": {"$binary": "9HrBC1jMQ3KlZw4CssPUeQ==", "$type": ' |
| 279 | + '"04"}}', json_options=options)) |
277 | 280 |
|
278 | 281 | def test_binary(self): |
279 | 282 | if PY3: |
|
0 commit comments