def test_trino_fetch_error(monkeypatch): monkeypatch.setattr(TrinoRequest.http.Response, "json", get_json_get_error_0) req = TrinoRequest( host="coordinator", port=8080, user="******", source="test", catalog="test", schema="test", http_scheme="http", session_properties={}, ) http_resp = TrinoRequest.http.Response() http_resp.status_code = 200 with pytest.raises(trino.exceptions.TrinoUserError) as exception_info: req.process(http_resp) error = exception_info.value assert error.error_code == 1 assert error.error_name == "SYNTAX_ERROR" assert error.error_type == "USER_ERROR" assert error.error_exception == "com.facebook.presto.sql.analyzer.SemanticException" assert "stack" in error.failure_info assert len(error.failure_info["stack"]) == 25 assert "suppressed" in error.failure_info assert ( error.message == "line 1:15: Schema must be specified when session schema is not set") assert error.error_location == (1, 15) assert error.query_id == "20161116_205844_00002_xtnym"
def test_trino_fetch_error(mock_requests, sample_get_error_response_data): mock_requests.Response.return_value.json.return_value = sample_get_error_response_data req = TrinoRequest( host="coordinator", port=8080, user="******", source="test", catalog="test", schema="test", http_scheme="http", session_properties={}, ) http_resp = TrinoRequest.http.Response() http_resp.status_code = 200 with pytest.raises(trino.exceptions.TrinoUserError) as exception_info: req.process(http_resp) error = exception_info.value assert error.error_code == 1 assert error.error_name == "SYNTAX_ERROR" assert error.error_type == "USER_ERROR" assert error.error_exception == "io.trino.spi.TrinoException" assert "stack" in error.failure_info assert len(error.failure_info["stack"]) == 36 assert "suppressed" in error.failure_info assert ( error.message == "line 1:15: Schema must be specified when session schema is not set") assert error.error_location == (1, 15) assert error.query_id == "20210817_140827_00000_arvdv"
def test_trino_connection_error(monkeypatch, error_code, error_type, error_message): monkeypatch.setattr(TrinoRequest.http.Response, "json", lambda x: {}) req = TrinoRequest( host="coordinator", port=8080, user="******", source="test", catalog="test", schema="test", http_scheme="http", session_properties={}, ) http_resp = TrinoRequest.http.Response() http_resp.status_code = error_code with pytest.raises(error_type) as error: req.process(http_resp) assert error_message in str(error)
def test_trino_initial_request(monkeypatch): monkeypatch.setattr(TrinoRequest.http.Response, "json", get_json_post_0) req = TrinoRequest( host="coordinator", port=8080, user="******", source="test", catalog="test", schema="test", http_scheme="http", session_properties={}, ) http_resp = TrinoRequest.http.Response() http_resp.status_code = 200 status = req.process(http_resp) assert status.next_uri == RESP_DATA_POST_0["nextUri"] assert status.id == RESP_DATA_POST_0["id"]
def test_trino_initial_request(mock_requests, sample_post_response_data): mock_requests.Response.return_value.json.return_value = sample_post_response_data req = TrinoRequest( host="coordinator", port=8080, user="******", source="test", catalog="test", schema="test", http_scheme="http", session_properties={}, ) http_resp = TrinoRequest.http.Response() http_resp.status_code = 200 status = req.process(http_resp) assert status.next_uri == sample_post_response_data["nextUri"] assert status.id == sample_post_response_data["id"]