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

Method test_encoding_1_2

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

Source from the content-addressed store, hash-verified

179 self.assertIsInstance(dbref, dict)
180
181 def test_encoding_1_2(self):
182 doc: Any
183 for doc in [
184 # 1, Encoding DBRefs with basic fields:
185 {"$ref": "coll0", "$id": ObjectId("60a6fe9a54f4180c86309efa")},
186 {"$ref": "coll0", "$id": 1},
187 {"$ref": "coll0", "$id": None},
188 {"$ref": "coll0", "$id": 1, "$db": "db0"},
189 # 2, Encoding DBRefs with extra, optional fields:
190 {"$ref": "coll0", "$id": 1, "$db": "db0", "foo": "bar"},
191 {"$ref": "coll0", "$id": 1, "foo": True, "bar": False},
192 {"$ref": "coll0", "$id": 1, "meta": {"foo": 1, "bar": 2}},
193 {"$ref": "coll0", "$id": 1, "$foo": "bar"},
194 {"$ref": "coll0", "$id": 1, "foo.bar": 0},
195 ]:
196 with self.subTest(doc=doc):
197 # Decode the test input to a DBRef via a BSON roundtrip.
198 encoded_doc = encode({"dbref": doc})
199 decoded = decode(encoded_doc)
200 dbref = decoded["dbref"]
201 self.assertIsInstance(dbref, DBRef)
202 # Encode the DBRef.
203 encoded_dbref = encode(decoded)
204 self.assertEqual(encoded_dbref, encoded_doc)
205 # Ensure extra fields are present.
206 for extra in set(doc.keys()) - {"$ref", "$id", "$db"}:
207 self.assertEqual(getattr(dbref, extra), doc[extra])
208
209 def test_encoding_3(self):
210 for doc in [

Callers

nothing calls this directly

Calls 4

ObjectIdClass · 0.90
encodeFunction · 0.90
decodeFunction · 0.90
keysMethod · 0.80

Tested by

no test coverage detected