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

Method test_uuid_queries

test/test_client.py:2181–2207  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2179 self.assertEqual(client.pymongo_test.test.codec_options.uuid_representation, CSHARP_LEGACY)
2180
2181 def test_uuid_queries(self):
2182 db = client_context.client.pymongo_test
2183 coll = db.test
2184 coll.drop()
2185
2186 uu = uuid.uuid4()
2187 coll.insert_one({"uuid": Binary(uu.bytes, 3)})
2188 self.assertEqual(1, coll.count_documents({}))
2189
2190 # Test regular UUID queries (using subtype 4).
2191 coll = db.get_collection(
2192 "test", CodecOptions(uuid_representation=UuidRepresentation.STANDARD)
2193 )
2194 self.assertEqual(0, coll.count_documents({"uuid": uu}))
2195 coll.insert_one({"uuid": uu})
2196 self.assertEqual(2, coll.count_documents({}))
2197 docs = coll.find({"uuid": uu}).to_list()
2198 self.assertEqual(1, len(docs))
2199 self.assertEqual(uu, docs[0]["uuid"])
2200
2201 # Test both.
2202 uu_legacy = Binary.from_uuid(uu, UuidRepresentation.PYTHON_LEGACY)
2203 predicate = {"uuid": {"$in": [uu, uu_legacy]}}
2204 self.assertEqual(2, coll.count_documents(predicate))
2205 docs = coll.find(predicate).to_list()
2206 self.assertEqual(2, len(docs))
2207 coll.drop()
2208
2209
2210class TestExhaustCursor(IntegrationTest):

Callers

nothing calls this directly

Calls 9

BinaryClass · 0.90
CodecOptionsClass · 0.90
from_uuidMethod · 0.80
dropMethod · 0.45
insert_oneMethod · 0.45
count_documentsMethod · 0.45
get_collectionMethod · 0.45
to_listMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected