def test_bolt_handshake_error(): handshake = b"\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00" response = b"\x00\x00\x00\x00" supported_versions = Bolt.protocol_handlers().keys() with pytest.raises(BoltHandshakeError) as e: error = BoltHandshakeError( "The Neo4J server does not support communication with this driver. Supported Bolt Protocols {}" .format(supported_versions), address="localhost", request_data=handshake, response_data=response) assert error.address == "localhost" assert error.request_data == handshake assert error.response_data == response raise error e.match( "The Neo4J server does not support communication with this driver. Supported Bolt Protocols " )
def test_class_method_get_handshake(): # python -m pytest tests/unit/io/test_class_bolt.py -s -v -k test_class_method_get_handshake handshake = Bolt.get_handshake() assert handshake == b"\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00"
def test_class_method_protocol_handlers_with_protocol_version( test_input, expected): # python -m pytest tests/unit/io/test_class_bolt.py -s -v -k test_class_method_protocol_handlers_with_protocol_version protocol_handlers = Bolt.protocol_handlers(protocol_version=test_input) assert len(protocol_handlers) == expected
def test_class_method_protocol_handlers_with_invalid_protocol_version(): # python -m pytest tests/unit/io/test_class_bolt.py -s -v -k test_class_method_protocol_handlers_with_invalid_protocol_version with pytest.raises(TypeError): Bolt.protocol_handlers(protocol_version=2)
def test_open_timeout(self): with pytest.raises(ServiceUnavailable): connection = Bolt.open(("localhost", 9999), auth=("test", "test"), timeout=1)
def test_class_method_protocol_handlers(): # python -m pytest tests/unit/io/test_class_bolt.py -s -v -k test_class_method_protocol_handlers protocol_handlers = Bolt.protocol_handlers() assert len(protocol_handlers) == 2
def test_ping_timeout(self): protocol_version = Bolt.ping(("localhost", 9999), timeout=1) assert protocol_version is None
def test_ping(self): protocol_version = Bolt.ping(("localhost", 9999)) assert protocol_version is None
def test_conn_not_timed_out(self): address = ("127.0.0.1", 7687) connection = Bolt(address, FakeSocket(address), protocol_version=1, max_age=999999999) self.assertEqual(connection.timedout(), False)
def opener(address, error_handler): return Bolt.open(address, error_handler=error_handler, auth=("neotest", "neotest"))
def _ping_range(port_range): count = 0 for port in port_range: count += 1 if Bolt.ping((NEO4J_HOST, port)) else 0 return count