MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_with_options

Method test_with_options

test/test_database.py:672–710  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

670 self.client.admin.command("configureFailPoint", "maxTimeAlwaysTimeOut", mode="off")
671
672 def test_with_options(self):
673 codec_options = DECIMAL_CODECOPTS
674 read_preference = ReadPreference.SECONDARY_PREFERRED
675 write_concern = WriteConcern(j=True)
676 read_concern = ReadConcern(level="majority")
677
678 # List of all options to compare.
679 allopts = [
680 "name",
681 "client",
682 "codec_options",
683 "read_preference",
684 "write_concern",
685 "read_concern",
686 ]
687
688 db1 = self.client.get_database(
689 "with_options_test",
690 codec_options=codec_options,
691 read_preference=read_preference,
692 write_concern=write_concern,
693 read_concern=read_concern,
694 )
695
696 # Case 1: swap no options
697 db2 = db1.with_options()
698 for opt in allopts:
699 self.assertEqual(getattr(db1, opt), getattr(db2, opt))
700
701 # Case 2: swap all options
702 newopts = {
703 "codec_options": CodecOptions(),
704 "read_preference": ReadPreference.PRIMARY,
705 "write_concern": WriteConcern(w=1),
706 "read_concern": ReadConcern(level="local"),
707 }
708 db2 = db1.with_options(**newopts) # type: ignore[arg-type, call-overload]
709 for opt in newopts:
710 self.assertEqual(getattr(db2, opt), newopts.get(opt, getattr(db1, opt)))
711
712
713class TestDatabaseAggregation(IntegrationTest):

Callers

nothing calls this directly

Calls 6

WriteConcernClass · 0.90
ReadConcernClass · 0.90
CodecOptionsClass · 0.90
get_databaseMethod · 0.45
with_optionsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected