@@ -319,9 +319,7 @@ async def test_session_tx_type(fake_pool):
319319))
320320@pytest .mark .parametrize ("run_type" , ("auto" , "unmanaged" , "managed" ))
321321@mark_async_test
322- async def test_session_run_with_parameters (
323- fake_pool , parameters , run_type , mocker
324- ):
322+ async def test_session_run_with_parameters (fake_pool , parameters , run_type ):
325323 async with AsyncSession (fake_pool , SessionConfig ()) as session :
326324 if run_type == "auto" :
327325 await session .run ("RETURN $x" , ** parameters )
@@ -337,12 +335,59 @@ async def work(tx):
337335
338336 assert len (fake_pool .acquired_connection_mocks ) == 1
339337 connection_mock = fake_pool .acquired_connection_mocks [0 ]
340- assert connection_mock .run .called_once ()
338+ connection_mock .run .assert_called_once ()
341339 call = connection_mock .run .call_args
342340 assert call .args [0 ] == "RETURN $x"
343341 assert call .kwargs ["parameters" ] == parameters
344342
345343
344+ @pytest .mark .parametrize (
345+ ("params" , "kw_params" , "expected_params" ),
346+ (
347+ ({"x" : 1 }, {}, {"x" : 1 }),
348+ ({}, {"x" : 1 }, {"x" : 1 }),
349+ ({"x" : 1 }, {"y" : 2 }, {"x" : 1 , "y" : 2 }),
350+ ({"x" : 1 }, {"x" : 2 }, {"x" : 2 }),
351+ ({"x" : 1 }, {"x" : 2 }, {"x" : 2 }),
352+ ({"x" : 1 , "y" : 3 }, {"x" : 2 }, {"x" : 2 , "y" : 3 }),
353+ ({"x" : 1 }, {"x" : 2 , "y" : 3 }, {"x" : 2 , "y" : 3 }),
354+ # potentially internally used keyword arguments
355+ ({}, {"timeout" : 2 }, {"timeout" : 2 }),
356+ ({"timeout" : 2 }, {}, {"timeout" : 2 }),
357+ ({}, {"imp_user" : "hans" }, {"imp_user" : "hans" }),
358+ ({"imp_user" : "hans" }, {}, {"imp_user" : "hans" }),
359+ ({}, {"db" : "neo4j" }, {"db" : "neo4j" }),
360+ ({"db" : "neo4j" }, {}, {"db" : "neo4j" }),
361+ ({}, {"database" : "neo4j" }, {"database" : "neo4j" }),
362+ ({"database" : "neo4j" }, {}, {"database" : "neo4j" }),
363+ )
364+ )
365+ @pytest .mark .parametrize ("run_type" , ("auto" , "unmanaged" , "managed" ))
366+ @mark_async_test
367+ async def test_session_run_parameter_precedence (
368+ fake_pool , params , kw_params , expected_params , run_type
369+ ):
370+ async with AsyncSession (fake_pool , SessionConfig ()) as session :
371+ if run_type == "auto" :
372+ await session .run ("RETURN $x" , params , ** kw_params )
373+ elif run_type == "unmanaged" :
374+ tx = await session .begin_transaction ()
375+ await tx .run ("RETURN $x" , params , ** kw_params )
376+ elif run_type == "managed" :
377+ async def work (tx ):
378+ await tx .run ("RETURN $x" , params , ** kw_params )
379+ await session .execute_write (work )
380+ else :
381+ raise ValueError (run_type )
382+
383+ assert len (fake_pool .acquired_connection_mocks ) == 1
384+ connection_mock = fake_pool .acquired_connection_mocks [0 ]
385+ connection_mock .run .assert_called_once ()
386+ call = connection_mock .run .call_args
387+ assert call .args [0 ] == "RETURN $x"
388+ assert call .kwargs ["parameters" ] == expected_params
389+
390+
346391@pytest .mark .parametrize ("db" , (None , "adb" ))
347392@pytest .mark .parametrize ("routing" , (True , False ))
348393# no home db resolution when connected to Neo4j 4.3 or earlier
@@ -446,7 +491,7 @@ async def bmm_gat_all_bookmarks():
446491
447492 assert len (fake_pool .acquired_connection_mocks ) == 1
448493 connection_mock = fake_pool .acquired_connection_mocks [0 ]
449- assert connection_mock .run .called_once ()
494+ connection_mock .run .assert_called_once ()
450495 connection_run_call_kwargs = connection_mock .run .call_args .kwargs
451496 assert (set (connection_run_call_kwargs ["bookmarks" ])
452497 == {"all" , "bookmarks" , * (additional_session_bookmarks or [])})
0 commit comments