def test_tls_fails(): """Make sure clients cannot connect when cert verification fails.""" certs = example_tls_certs() with ConstantFlightServer(tls_certificates=certs["certificates"]) as s: # Ensure client doesn't connect when certificate verification # fails (this is a slow test since gRPC does retry a few times) client = FlightServerBase(('localhost', s.port), tls_root_certs=certs["root_cert"]) # gRPC error messages change based on version, so don't look # for a particular error with pytest.raises(flight.FlightUnavailableError): client.do_get(flight.Ticket(b'ints'))
def test_flight_server_location_argument(): locations = [ None, 'grpc://localhost:0', ('localhost', find_free_port()), ] for location in locations: with FlightServerBase(location) as server: assert isinstance(server, FlightServerBase)
def test_middleware_mapping(): """Test that middleware records methods correctly.""" server_middleware = RecordingServerMiddlewareFactory() client_middleware = RecordingClientMiddlewareFactory() with FlightServerBase(middleware={"test": server_middleware}) as server: client = FlightClient( ('localhost', server.port), middleware=[client_middleware] ) descriptor = flight.FlightDescriptor.for_command(b"") with pytest.raises(NotImplementedError): list(client.list_flights()) with pytest.raises(NotImplementedError): client.get_flight_info(descriptor) with pytest.raises(NotImplementedError): client.get_schema(descriptor) with pytest.raises(NotImplementedError): client.do_get(flight.Ticket(b"")) with pytest.raises(NotImplementedError): writer, _ = client.do_put(descriptor, pa.schema([])) writer.close() with pytest.raises(NotImplementedError): list(client.do_action(flight.Action(b"", b""))) with pytest.raises(NotImplementedError): list(client.list_actions()) with pytest.raises(NotImplementedError): writer, _ = client.do_exchange(descriptor) writer.close() expected = [ flight.FlightMethod.LIST_FLIGHTS, flight.FlightMethod.GET_FLIGHT_INFO, flight.FlightMethod.GET_SCHEMA, flight.FlightMethod.DO_GET, flight.FlightMethod.DO_PUT, flight.FlightMethod.DO_ACTION, flight.FlightMethod.LIST_ACTIONS, flight.FlightMethod.DO_EXCHANGE, ] assert server_middleware.methods == expected assert client_middleware.methods == expected
def serve(): global server time.sleep(0.5) server = FlightServerBase(location) server.serve()
def test_server_exit_reraises_exception(): with pytest.raises(ValueError): with FlightServerBase(): raise ValueError()