@@ -68,10 +68,9 @@ def assertServerApi(self, event):
6868 def assertNoServerApi (self , event ):
6969 self .assertNotIn ('apiVersion' , event .command )
7070
71- def assertServerApiOnlyInFirstCommand (self , events ):
72- self .assertServerApi (events [0 ])
73- for event in events [1 :]:
74- self .assertNoServerApi (event )
71+ def assertServerApiInAllCommands (self , events ):
72+ for event in events :
73+ self .assertServerApi (event )
7574
7675 @client_context .require_version_min (4 , 7 )
7776 def test_command_options (self ):
@@ -84,11 +83,7 @@ def test_command_options(self):
8483 self .addCleanup (coll .delete_many , {})
8584 list (coll .find (batch_size = 25 ))
8685 client .admin .command ('ping' )
87- for event in listener .results ['started' ]:
88- if event .command_name == 'getMore' :
89- self .assertNoServerApi (event )
90- else :
91- self .assertServerApi (event )
86+ self .assertServerApiInAllCommands (listener .results ['started' ])
9287
9388 @client_context .require_version_min (4 , 7 )
9489 @client_context .require_transactions
@@ -106,21 +101,7 @@ def test_command_options_txn(self):
106101 coll .insert_many ([{} for _ in range (100 )], session = s )
107102 list (coll .find (batch_size = 25 , session = s ))
108103 client .test .command ('find' , 'test' , session = s )
109- self .assertServerApiOnlyInFirstCommand (listener .results ['started' ])
110-
111- listener .reset ()
112- with client .start_session () as s , s .start_transaction ():
113- list (coll .find (batch_size = 25 , session = s ))
114- coll .insert_many ([{} for _ in range (100 )], session = s )
115- client .test .command ('find' , 'test' , session = s )
116- self .assertServerApiOnlyInFirstCommand (listener .results ['started' ])
117-
118- listener .reset ()
119- with client .start_session () as s , s .start_transaction ():
120- client .test .command ('find' , 'test' , session = s )
121- list (coll .find (batch_size = 25 , session = s ))
122- coll .insert_many ([{} for _ in range (100 )], session = s )
123- self .assertServerApiOnlyInFirstCommand (listener .results ['started' ])
104+ self .assertServerApiInAllCommands (listener .results ['started' ])
124105
125106
126107if __name__ == "__main__" :
0 commit comments