MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / test_decoding_1_2_3

Method test_decoding_1_2_3

test/test_dbref.py:133–162  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

131# https://github.com/mongodb/specifications/blob/master/source/dbref/dbref.md#test-plan
132class TestDBRefSpec(unittest.TestCase):
133 def test_decoding_1_2_3(self):
134 doc: Any
135 for doc in [
136 # 1, Valid documents MUST be decoded to a DBRef:
137 {"$ref": "coll0", "$id": ObjectId("60a6fe9a54f4180c86309efa")},
138 {"$ref": "coll0", "$id": 1},
139 {"$ref": "coll0", "$id": None},
140 {"$ref": "coll0", "$id": 1, "$db": "db0"},
141 # 2, Valid documents with extra fields:
142 {"$ref": "coll0", "$id": 1, "$db": "db0", "foo": "bar"},
143 {"$ref": "coll0", "$id": 1, "foo": True, "bar": False},
144 {"$ref": "coll0", "$id": 1, "meta": {"foo": 1, "bar": 2}},
145 {"$ref": "coll0", "$id": 1, "$foo": "bar"},
146 {"$ref": "coll0", "$id": 1, "foo.bar": 0},
147 # 3, Valid documents with out of order fields:
148 {"$id": 1, "$ref": "coll0"},
149 {"$db": "db0", "$ref": "coll0", "$id": 1},
150 {"foo": 1, "$id": 1, "$ref": "coll0"},
151 {"foo": 1, "$ref": "coll0", "$id": 1, "$db": "db0"},
152 {"foo": 1, "$ref": "coll0", "$id": 1, "$db": "db0", "bar": 1},
153 ]:
154 with self.subTest(doc=doc):
155 decoded = decode(encode({"dbref": doc}))
156 dbref = decoded["dbref"]
157 self.assertIsInstance(dbref, DBRef)
158 self.assertEqual(dbref.collection, doc["$ref"])
159 self.assertEqual(dbref.id, doc["$id"])
160 self.assertEqual(dbref.database, doc.get("$db"))
161 for extra in set(doc.keys()) - {"$ref", "$id", "$db"}:
162 self.assertEqual(getattr(dbref, extra), doc[extra])
163
164 def test_decoding_4_5(self):
165 for doc in [

Callers

nothing calls this directly

Calls 5

ObjectIdClass · 0.90
decodeFunction · 0.90
encodeFunction · 0.90
keysMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected