Skip to content

Commit

Permalink
PYTHON-2048 Add test case for better error behavior (#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneHarvey authored Apr 17, 2024
1 parent 5f372ba commit aa8322e
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/mockupdb/test_standalone_shard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2024-present MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test errors that come from a standalone shard."""
from __future__ import annotations

import unittest

from mockupdb import MockupDB, going

from pymongo import MongoClient
from pymongo.errors import OperationFailure


class TestStandaloneShard(unittest.TestCase):
# See PYTHON-2048 and SERVER-44591.
def test_bulk_txn_error_message(self):
server = MockupDB(auto_ismaster={"maxWireVersion": 8})
server.run()
self.addCleanup(server.stop)
client = MongoClient(server.uri)
self.addCleanup(client.close)

with self.assertRaisesRegex(
OperationFailure, "This MongoDB deployment does not support retryable writes"
):
with going(client.db.collection.insert_many, [{}, {}]):
request = server.receives()
request.reply(
{
"n": 0,
"ok": 1.0,
"writeErrors": [
{
"code": 20,
"codeName": "IllegalOperation",
"errmsg": "Transaction numbers are only allowed on a replica set member or mongos",
"index": 0,
}
],
}
)


if __name__ == "__main__":
unittest.main()

0 comments on commit aa8322e

Please sign in to comment.