MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / test_case_6

Method test_case_6

test/test_index_management.py:273–298  ·  view source on GitHub ↗

Driver can successfully create and list search indexes with non-default readConcern and writeConcern.

(self)

Source from the content-addressed store, hash-verified

271 coll0.drop_search_index("foo")
272
273 def test_case_6(self):
274 """Driver can successfully create and list search indexes with non-default readConcern and writeConcern."""
275 # Create a collection with the "create" command using a randomly generated name (referred to as ``coll0``).
276 coll0 = self.db[f"col{uuid.uuid4()}"]
277 coll0.insert_one({})
278
279 # Apply a write concern ``WriteConcern(w=1)`` and a read concern with ``ReadConcern(level="majority")`` to ``coll0``.
280 coll0 = coll0.with_options(
281 write_concern=WriteConcern(w="1"), read_concern=ReadConcern(level="majority")
282 )
283
284 # Create a new search index on ``coll0`` with the ``createSearchIndex`` helper.
285 name = "test-search-index-case6"
286 model = {"name": name, "definition": {"mappings": {"dynamic": False}}}
287 resp = coll0.create_search_index(model)
288
289 # Assert that the command returns the name of the index: ``"test-search-index-case6"``.
290 self.assertEqual(resp, name)
291
292 # Run ``coll0.listSearchIndexes()`` repeatedly every 5 seconds until the following condition is satisfied and store the value in a variable ``index``:
293 # - An index with the ``name`` of ``test-search-index-case6`` is present and the index has a field ``queryable`` with a value of ``true``.
294 index = self.wait_for_ready(coll0, name)
295
296 # Assert that ``index`` has a property ``latestDefinition`` whose value is ``{ 'mappings': { 'dynamic': false } }``
297 self.assertIn("latestDefinition", index)
298 self.assertEqual(index["latestDefinition"], model["definition"])
299
300 def test_case_7(self):
301 """Driver handles index types."""

Callers

nothing calls this directly

Calls 6

WriteConcernClass · 0.90
ReadConcernClass · 0.90
insert_oneMethod · 0.45
with_optionsMethod · 0.45
create_search_indexMethod · 0.45
wait_for_readyMethod · 0.45

Tested by

no test coverage detected