Skip to content

Commit aa8322e

Browse files
authored
PYTHON-2048 Add test case for better error behavior (#1606)
1 parent 5f372ba commit aa8322e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2024-present MongoDB, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Test errors that come from a standalone shard."""
16+
from __future__ import annotations
17+
18+
import unittest
19+
20+
from mockupdb import MockupDB, going
21+
22+
from pymongo import MongoClient
23+
from pymongo.errors import OperationFailure
24+
25+
26+
class TestStandaloneShard(unittest.TestCase):
27+
# See PYTHON-2048 and SERVER-44591.
28+
def test_bulk_txn_error_message(self):
29+
server = MockupDB(auto_ismaster={"maxWireVersion": 8})
30+
server.run()
31+
self.addCleanup(server.stop)
32+
client = MongoClient(server.uri)
33+
self.addCleanup(client.close)
34+
35+
with self.assertRaisesRegex(
36+
OperationFailure, "This MongoDB deployment does not support retryable writes"
37+
):
38+
with going(client.db.collection.insert_many, [{}, {}]):
39+
request = server.receives()
40+
request.reply(
41+
{
42+
"n": 0,
43+
"ok": 1.0,
44+
"writeErrors": [
45+
{
46+
"code": 20,
47+
"codeName": "IllegalOperation",
48+
"errmsg": "Transaction numbers are only allowed on a replica set member or mongos",
49+
"index": 0,
50+
}
51+
],
52+
}
53+
)
54+
55+
56+
if __name__ == "__main__":
57+
unittest.main()

0 commit comments

Comments
 (0)