Skip to content

Commit 44e4730

Browse files
authored
PYTHON-4300 Forward comment argument in list_search_indexes (#1569)
1 parent bce047d commit 44e4730

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

pymongo/collection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,7 @@ def list_search_indexes(
23722372
pipeline,
23732373
kwargs,
23742374
explicit_session=session is not None,
2375+
comment=comment,
23752376
user_fields={"cursor": {"firstBatch": 1}},
23762377
)
23772378

test/test_index_management.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from test import IntegrationTest, unittest
2727
from test.unified_format import generate_test_classes
28-
from test.utils import AllowListEventListener
28+
from test.utils import AllowListEventListener, EventListener
2929

3030
from pymongo import MongoClient
3131
from pymongo.errors import OperationFailure
@@ -63,7 +63,9 @@ def test_inputs(self):
6363
self.assertIn("arbitraryOption", listener.events[0].command["indexes"][0])
6464

6565

66-
class TestSearchIndexProse(unittest.TestCase):
66+
class SearchIndexIntegrationBase(unittest.TestCase):
67+
db_name = "test_search_index_base"
68+
6769
@classmethod
6870
def setUpClass(cls) -> None:
6971
super().setUpClass()
@@ -72,9 +74,12 @@ def setUpClass(cls) -> None:
7274
url = os.environ.get("MONGODB_URI")
7375
username = os.environ["DB_USER"]
7476
password = os.environ["DB_PASSWORD"]
75-
cls.client = MongoClient(url, username=username, password=password)
77+
cls.listener = listener = EventListener()
78+
cls.client = MongoClient(
79+
url, username=username, password=password, event_listeners=[listener]
80+
)
7681
cls.client.drop_database(_NAME)
77-
cls.db = cls.client.test_search_index_prose
82+
cls.db = cls.client[cls.db_name]
7883

7984
@classmethod
8085
def tearDownClass(cls):
@@ -94,6 +99,34 @@ def wait_for_ready(self, coll, name=_NAME, predicate=None):
9499
break
95100
time.sleep(5)
96101

102+
103+
class TestSearchIndexIntegration(SearchIndexIntegrationBase):
104+
db_name = "test_search_index"
105+
106+
def test_comment_field(self):
107+
# Create a collection with the "create" command using a randomly generated name (referred to as ``coll0``).
108+
coll0 = self.db[f"col{uuid.uuid4()}"]
109+
coll0.insert_one({})
110+
111+
# Create a new search index on ``coll0`` that implicitly passes its type.
112+
search_definition = {"mappings": {"dynamic": False}}
113+
self.listener.reset()
114+
implicit_search_resp = coll0.create_search_index(
115+
model={"name": _NAME + "-implicit", "definition": search_definition}, comment="foo"
116+
)
117+
event = self.listener.events[0]
118+
self.assertEqual(event.command["comment"], "foo")
119+
120+
# Get the index definition.
121+
self.listener.reset()
122+
coll0.list_search_indexes(name=implicit_search_resp, comment="foo").next()
123+
event = self.listener.events[0]
124+
self.assertEqual(event.command["comment"], "foo")
125+
126+
127+
class TestSearchIndexProse(SearchIndexIntegrationBase):
128+
db_name = "test_search_index_prose"
129+
97130
def test_case_1(self):
98131
"""Driver can successfully create and list search indexes."""
99132

0 commit comments

Comments
 (0)