Driver can successfully create multiple indexes in batch.
(self)
| 163 | self.assertEqual(index["latestDefinition"], model["definition"]) |
| 164 | |
| 165 | def test_case_2(self): |
| 166 | """Driver can successfully create multiple indexes in batch.""" |
| 167 | |
| 168 | # Create a collection with the "create" command using a randomly generated name (referred to as ``coll0``). |
| 169 | coll0 = self.db[f"col{uuid.uuid4()}"] |
| 170 | coll0.insert_one({}) |
| 171 | |
| 172 | # Create two new search indexes on ``coll0`` with the ``createSearchIndexes`` helper. |
| 173 | name1 = "test-search-index-1" |
| 174 | name2 = "test-search-index-2" |
| 175 | definition = {"mappings": {"dynamic": False}} |
| 176 | index_definitions: list[dict[str, Any]] = [ |
| 177 | {"name": name1, "definition": definition}, |
| 178 | {"name": name2, "definition": definition}, |
| 179 | ] |
| 180 | coll0.create_search_indexes( |
| 181 | [SearchIndexModel(i["definition"], i["name"]) for i in index_definitions] |
| 182 | ) |
| 183 | |
| 184 | # .Assert that the command returns an array containing the new indexes' names: ``["test-search-index-1", "test-search-index-2"]``. |
| 185 | indices = (coll0.list_search_indexes()).to_list() |
| 186 | names = [i["name"] for i in indices] |
| 187 | self.assertIn(name1, names) |
| 188 | self.assertIn(name2, names) |
| 189 | |
| 190 | # Run ``coll0.listSearchIndexes()`` repeatedly every 5 seconds until the following condition is satisfied. |
| 191 | # An index with the ``name`` of ``test-search-index-1`` is present and index has a field ``queryable`` with the value of ``true``. Store result in ``index1``. |
| 192 | # An index with the ``name`` of ``test-search-index-2`` is present and index has a field ``queryable`` with the value of ``true``. Store result in ``index2``. |
| 193 | index1 = self.wait_for_ready(coll0, name1) |
| 194 | index2 = self.wait_for_ready(coll0, name2) |
| 195 | |
| 196 | # Assert that ``index1`` and ``index2`` have the property ``latestDefinition`` whose value is ``{ "mappings" : { "dynamic" : false } }`` |
| 197 | for index in [index1, index2]: |
| 198 | self.assertIn("latestDefinition", index) |
| 199 | self.assertEqual(index["latestDefinition"], definition) |
| 200 | |
| 201 | def test_case_3(self): |
| 202 | """Driver can successfully drop search indexes.""" |
nothing calls this directly
no test coverage detected