25
25
26
26
from test import IntegrationTest , unittest
27
27
from test .unified_format import generate_test_classes
28
- from test .utils import AllowListEventListener
28
+ from test .utils import AllowListEventListener , EventListener
29
29
30
30
from pymongo import MongoClient
31
31
from pymongo .errors import OperationFailure
@@ -63,7 +63,9 @@ def test_inputs(self):
63
63
self .assertIn ("arbitraryOption" , listener .events [0 ].command ["indexes" ][0 ])
64
64
65
65
66
- class TestSearchIndexProse (unittest .TestCase ):
66
+ class SearchIndexIntegrationBase (unittest .TestCase ):
67
+ db_name = "test_search_index_base"
68
+
67
69
@classmethod
68
70
def setUpClass (cls ) -> None :
69
71
super ().setUpClass ()
@@ -72,9 +74,12 @@ def setUpClass(cls) -> None:
72
74
url = os .environ .get ("MONGODB_URI" )
73
75
username = os .environ ["DB_USER" ]
74
76
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
+ )
76
81
cls .client .drop_database (_NAME )
77
- cls .db = cls .client . test_search_index_prose
82
+ cls .db = cls .client [ cls . db_name ]
78
83
79
84
@classmethod
80
85
def tearDownClass (cls ):
@@ -94,6 +99,34 @@ def wait_for_ready(self, coll, name=_NAME, predicate=None):
94
99
break
95
100
time .sleep (5 )
96
101
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
+
97
130
def test_case_1 (self ):
98
131
"""Driver can successfully create and list search indexes."""
99
132
0 commit comments