2424from neo4j .exceptions import (
2525 ServiceUnavailable ,
2626 ConfigurationError ,
27+ DriverError ,
2728)
2829from neo4j ._exceptions import (
2930 BoltHandshakeError ,
@@ -88,27 +89,47 @@ def test_bolt_uri_constructs_bolt_driver(driver_info, test_script):
8889
8990
9091@pytest .mark .parametrize (
91- "test_script, test_expected " ,
92+ "test_script" ,
9293 [
93- # ("v1/empty_explicit_hello_goodbye.script", ServiceUnavailable), # skip: cant close stub server gracefully
94- # ("v2/empty_explicit_hello_goodbye.script", ServiceUnavailable), # skip: cant close stub server gracefully
95- ("v3/empty_explicit_hello_goodbye.script" , None ),
96- ("v4x0/empty_explicit_hello_goodbye.script" , None ),
97- ("v4x1/empty_explicit_hello_goodbye.script" , None ),
94+ "v3/empty_explicit_hello_goodbye.script" ,
95+ "v4x0/empty_explicit_hello_goodbye.script" ,
96+ "v4x1/empty_explicit_hello_goodbye.script" ,
9897 ]
9998)
100- def test_direct_driver_handshake_negotiation (driver_info , test_script , test_expected ):
99+ def test_direct_driver_handshake_negotiation (driver_info , test_script ):
101100 # python -m pytest tests/stub/test_directdriver.py -s -v -k test_direct_driver_handshake_negotiation
102101 with StubCluster (test_script ):
103102 uri = "bolt://localhost:9001"
104- if test_expected :
105- with pytest .raises (test_expected ) as error :
106- driver = GraphDatabase .driver (uri , auth = driver_info ["auth_token" ], ** driver_config )
107- assert isinstance (error .value .__cause__ , BoltHandshakeError )
108- else :
109- driver = GraphDatabase .driver (uri , auth = driver_info ["auth_token" ], ** driver_config )
103+ driver = GraphDatabase .driver (uri , auth = driver_info ["auth_token" ], ** driver_config )
104+ assert isinstance (driver , BoltDriver )
105+ driver .close ()
106+
107+
108+ @pytest .mark .parametrize (
109+ "test_script, test_expected" ,
110+ [
111+ ("v3/return_1_port_9001.script" , "Neo4j/3.0.0" ),
112+ ("v4x0/return_1_port_9001.script" , "Neo4j/4.0.0" ),
113+ ("v4x1/return_1_port_9001_bogus_server.script" , DriverError ),
114+ ]
115+ )
116+ def test_return_1_as_x (driver_info , test_script , test_expected ):
117+ # python -m pytest tests/stub/test_directdriver.py -s -v -k test_return_1_as_x
118+ with StubCluster (test_script ):
119+ uri = "bolt://localhost:9001"
120+ try :
121+ driver = GraphDatabase .driver (uri , auth = driver_info ["auth_token" ], user_agent = "test" )
110122 assert isinstance (driver , BoltDriver )
123+ with driver .session (default_access_mode = READ_ACCESS , fetch_size = - 1 ) as session :
124+ result = session .run ("RETURN 1 AS x" )
125+ value = result .single ().value ()
126+ assert value == 1
127+ summary = result .consume ()
128+ assert summary .server .agent == test_expected
129+ assert summary .server .agent .startswith ("Neo4j" )
111130 driver .close ()
131+ except DriverError as error :
132+ assert isinstance (error , test_expected )
112133
113134
114135def test_direct_driver_with_wrong_port (driver_info ):
@@ -128,7 +149,7 @@ def test_direct_driver_with_wrong_port(driver_info):
128149def test_direct_verify_connectivity (driver_info , test_script , test_expected ):
129150 # python -m pytest tests/stub/test_directdriver.py -s -v -k test_direct_verify_connectivity
130151 with StubCluster (test_script ):
131- uri = "bolt://127.0.0.1 :9001"
152+ uri = "bolt://localhost :9001"
132153 with GraphDatabase .driver (uri , auth = driver_info ["auth_token" ], ** driver_config ) as driver :
133154 assert isinstance (driver , BoltDriver )
134155 assert driver .verify_connectivity (default_access_mode = READ_ACCESS ) == test_expected
0 commit comments