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

Method _test_unacknowledged_ops

test/test_session.py:781–829  ·  view source on GitHub ↗
(self, client, *ops)

Source from the content-addressed store, hash-verified

779 )
780
781 def _test_unacknowledged_ops(self, client, *ops):
782 listener = client.options.event_listeners[0]
783
784 for f, args, kw in ops:
785 with client.start_session() as s:
786 listener.reset()
787 # In case "f" modifies its inputs.
788 args = copy.copy(args)
789 kw = copy.copy(kw)
790 kw["session"] = s
791 with self.assertRaises(
792 ConfigurationError, msg=f"{f.__name__} did not raise ConfigurationError"
793 ):
794 f(*args, **kw)
795 if f.__name__ == "create_collection":
796 # create_collection runs listCollections first.
797 event = listener.started_events.pop(0)
798 self.assertEqual("listCollections", event.command_name)
799 self.assertIn(
800 "lsid",
801 event.command,
802 f"{f.__name__} sent no lsid with {event.command_name}",
803 )
804
805 # Should not run any command before raising an error.
806 self.assertFalse(listener.started_events, f"{f.__name__} sent command")
807
808 self.assertTrue(s.has_ended)
809
810 # Unacknowledged write without a session does not send an lsid.
811 for f, args, kw in ops:
812 listener.reset()
813 f(*args, **kw)
814 self.assertGreaterEqual(len(listener.started_events), 1)
815
816 if f.__name__ == "create_collection":
817 # create_collection runs listCollections first.
818 event = listener.started_events.pop(0)
819 self.assertEqual("listCollections", event.command_name)
820 self.assertIn(
821 "lsid",
822 event.command,
823 f"{f.__name__} sent no lsid with {event.command_name}",
824 )
825
826 for event in listener.started_events:
827 self.assertNotIn(
828 "lsid", event.command, f"{f.__name__} sent lsid with {event.command_name}"
829 )
830
831 def test_unacknowledged_writes(self):
832 # Ensure the collection exists.

Callers 1

Calls 4

copyMethod · 0.80
start_sessionMethod · 0.45
resetMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected