Example #1
0
def test_presto_fetch_error(monkeypatch):
    monkeypatch.setattr(PrestoRequest.http.Response, "json",
                        get_json_get_error_0)

    req = PrestoRequest(
        host="coordinator",
        port=8080,
        user="******",
        source="test",
        catalog="test",
        schema="test",
        http_scheme="http",
        session_properties={},
    )

    http_resp = PrestoRequest.http.Response()
    http_resp.status_code = 200
    with pytest.raises(presto.exceptions.PrestoUserError) 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"
Example #2
0
def test_presto_connection_error(monkeypatch, error_code, error_type,
                                 error_message):
    monkeypatch.setattr(PrestoRequest.http.Response, "json", lambda x: {})

    req = PrestoRequest(
        host="coordinator",
        port=8080,
        user="******",
        source="test",
        catalog="test",
        schema="test",
        http_scheme="http",
        session_properties={},
    )

    http_resp = PrestoRequest.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)
Example #3
0
def test_presto_initial_request(monkeypatch):
    monkeypatch.setattr(PrestoRequest.http.Response, "json", get_json_post_0)

    req = PrestoRequest(
        host="coordinator",
        port=8080,
        user="******",
        source="test",
        catalog="test",
        schema="test",
        http_scheme="http",
        session_properties={},
    )

    http_resp = PrestoRequest.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"]