-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support setting roles in dbapi and sqlalchemy #212
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
import trino | ||
from tests.integration.conftest import trino_version | ||
from trino import constants | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Does it make sense (and is it accurate?)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hashhar: It is really just a rename of role into roles. There is no new feature being introduced in that commit actually. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the reason why the first commit by itself fails tests. See
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I probably messed up something in my fixup comments locally. All good now. |
||
from trino.exceptions import TrinoQueryError, TrinoUserError, NotSupportedError | ||
from trino.transaction import IsolationLevel | ||
|
||
|
@@ -1045,11 +1046,11 @@ def test_set_role_trino_higher_351(run_trino): | |
cur = trino_connection.cursor() | ||
cur.execute('SHOW TABLES FROM information_schema') | ||
cur.fetchall() | ||
assert cur._request._client_session.role is None | ||
assert cur._request._client_session.roles == {} | ||
|
||
cur.execute("SET ROLE ALL") | ||
cur.fetchall() | ||
assert cur._request._client_session.role == "system=ALL" | ||
assert_role_headers(cur, "system=ALL") | ||
|
||
|
||
@pytest.mark.skipif(trino_version() != '351', reason="Trino 351 returns the role for the current catalog") | ||
|
@@ -1062,11 +1063,28 @@ def test_set_role_trino_351(run_trino): | |
cur = trino_connection.cursor() | ||
cur.execute('SHOW TABLES FROM information_schema') | ||
cur.fetchall() | ||
assert cur._request._client_session.role is None | ||
assert cur._request._client_session.roles == {} | ||
|
||
cur.execute("SET ROLE ALL") | ||
cur.fetchall() | ||
assert cur._request._client_session.role == "tpch=ALL" | ||
assert_role_headers(cur, "tpch=ALL") | ||
|
||
|
||
@pytest.mark.skipif(trino_version() == '351', reason="Newer Trino versions return the system role") | ||
def test_set_role_in_connection_trino_higher_351(run_trino): | ||
_, host, port = run_trino | ||
|
||
trino_connection = trino.dbapi.Connection( | ||
host=host, port=port, user="test", catalog="tpch", roles={"system": "ALL"} | ||
) | ||
cur = trino_connection.cursor() | ||
cur.execute('SHOW TABLES FROM information_schema') | ||
cur.fetchall() | ||
assert_role_headers(cur, "system=ALL") | ||
|
||
|
||
def assert_role_headers(cursor, expected_header): | ||
assert cursor._request.http_headers[constants.HEADER_ROLE] == expected_header | ||
|
||
|
||
def test_prepared_statements(run_trino): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no test for sqlalchemy integration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #212 (comment)