Skip to content

Commit 8906e84

Browse files
committed
PYTHON-4915 - Add guidance on adding _id fields to documents to CRUD spec
1 parent 7286386 commit 8906e84

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/mockupdb/test_id_ordering.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from __future__ import annotations
2+
3+
from test import PyMongoTestCase
4+
5+
import pytest
6+
7+
try:
8+
from mockupdb import MockupDB, OpMsg, going
9+
10+
_HAVE_MOCKUPDB = True
11+
except ImportError:
12+
_HAVE_MOCKUPDB = False
13+
14+
15+
from bson.objectid import ObjectId
16+
17+
pytestmark = pytest.mark.mockupdb
18+
19+
20+
class TestIdOrdering(PyMongoTestCase):
21+
def test_id_ordering(self):
22+
server = MockupDB()
23+
server.autoresponds(
24+
"hello",
25+
isWritablePrimary=True,
26+
msg="isdbgrid",
27+
minWireVersion=0,
28+
maxWireVersion=20,
29+
helloOk=True,
30+
serviceId=ObjectId(),
31+
)
32+
server.run()
33+
self.addCleanup(server.stop)
34+
35+
client = self.simple_client(server.uri, loadBalanced=True)
36+
collection = client.db.coll
37+
with going(collection.insert_one, {"x": 1}):
38+
request = server.receives(OpMsg({"insert": "coll"}))
39+
self.assertEqual("_id", next(iter(request["documents"][0])))
40+
request.reply({"ok": 1})

0 commit comments

Comments
 (0)