PYTHON-4300 Forward comment argument in list_search_indexes (#1569)
This commit is contained in:
parent
bce047dfc9
commit
44e47304ff
@ -2372,6 +2372,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
|
||||
pipeline,
|
||||
kwargs,
|
||||
explicit_session=session is not None,
|
||||
comment=comment,
|
||||
user_fields={"cursor": {"firstBatch": 1}},
|
||||
)
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ sys.path[0:0] = [""]
|
||||
|
||||
from test import IntegrationTest, unittest
|
||||
from test.unified_format import generate_test_classes
|
||||
from test.utils import AllowListEventListener
|
||||
from test.utils import AllowListEventListener, EventListener
|
||||
|
||||
from pymongo import MongoClient
|
||||
from pymongo.errors import OperationFailure
|
||||
@ -63,7 +63,9 @@ class TestCreateSearchIndex(IntegrationTest):
|
||||
self.assertIn("arbitraryOption", listener.events[0].command["indexes"][0])
|
||||
|
||||
|
||||
class TestSearchIndexProse(unittest.TestCase):
|
||||
class SearchIndexIntegrationBase(unittest.TestCase):
|
||||
db_name = "test_search_index_base"
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
super().setUpClass()
|
||||
@ -72,9 +74,12 @@ class TestSearchIndexProse(unittest.TestCase):
|
||||
url = os.environ.get("MONGODB_URI")
|
||||
username = os.environ["DB_USER"]
|
||||
password = os.environ["DB_PASSWORD"]
|
||||
cls.client = MongoClient(url, username=username, password=password)
|
||||
cls.listener = listener = EventListener()
|
||||
cls.client = MongoClient(
|
||||
url, username=username, password=password, event_listeners=[listener]
|
||||
)
|
||||
cls.client.drop_database(_NAME)
|
||||
cls.db = cls.client.test_search_index_prose
|
||||
cls.db = cls.client[cls.db_name]
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
@ -94,6 +99,34 @@ class TestSearchIndexProse(unittest.TestCase):
|
||||
break
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
class TestSearchIndexIntegration(SearchIndexIntegrationBase):
|
||||
db_name = "test_search_index"
|
||||
|
||||
def test_comment_field(self):
|
||||
# Create a collection with the "create" command using a randomly generated name (referred to as ``coll0``).
|
||||
coll0 = self.db[f"col{uuid.uuid4()}"]
|
||||
coll0.insert_one({})
|
||||
|
||||
# Create a new search index on ``coll0`` that implicitly passes its type.
|
||||
search_definition = {"mappings": {"dynamic": False}}
|
||||
self.listener.reset()
|
||||
implicit_search_resp = coll0.create_search_index(
|
||||
model={"name": _NAME + "-implicit", "definition": search_definition}, comment="foo"
|
||||
)
|
||||
event = self.listener.events[0]
|
||||
self.assertEqual(event.command["comment"], "foo")
|
||||
|
||||
# Get the index definition.
|
||||
self.listener.reset()
|
||||
coll0.list_search_indexes(name=implicit_search_resp, comment="foo").next()
|
||||
event = self.listener.events[0]
|
||||
self.assertEqual(event.command["comment"], "foo")
|
||||
|
||||
|
||||
class TestSearchIndexProse(SearchIndexIntegrationBase):
|
||||
db_name = "test_search_index_prose"
|
||||
|
||||
def test_case_1(self):
|
||||
"""Driver can successfully create and list search indexes."""
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user