Skip to content

Commit

Permalink
Fixed nightly tests (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx authored Mar 21, 2024
1 parent 20f3509 commit 0e9ac6a
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions tests/integration/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,44 @@
return "PASSED"
"""

PERMISSION_DENIED_EXECUTE = """

UNKNOWN_ERROR = """
from databricks.labs.lsql.backends import RuntimeBackend
from databricks.sdk.errors import PermissionDenied
from databricks.sdk.errors import Unknown
backend = RuntimeBackend()
try:
current_user = backend.fetch("SELECT current_user()")
backend.execute(f"GRANT CREATE EXTERNAL LOCATION ON METASTORE TO {current_user}")
grants = backend.fetch("SHOW GRANTS ON METASTORE")
return "FAILED"
except PermissionDenied:
except Unknown:
return "PASSED"
"""

UNKNOWN_ERROR = """

@pytest.mark.xfail
def test_runtime_backend_works_maps_permission_denied(ws):
product_info = ProductInfo.for_testing(SqlBackend)
installation = Installation.assume_user_home(ws, product_info.product_name())
with WheelsV2(installation, product_info) as wheels:
wsfs_wheel = wheels.upload_to_wsfs()

commands = CommandExecutor(ws.clusters, ws.command_execution, lambda: ws.config.cluster_id)
commands.install_notebook_library(f"/Workspace{wsfs_wheel}")

permission_denied_query = """
from databricks.labs.lsql.backends import RuntimeBackend
from databricks.sdk.errors import Unknown
from databricks.sdk.errors import PermissionDenied
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
me = w.current_user.me()
backend = RuntimeBackend()
try:
grants = backend.fetch("SHOW GRANTS ON METASTORE")
backend.execute(f"GRANT CREATE SCHEMA ON CATALOG main TO `{me.groups[0].display}`;")
return "FAILED"
except Unknown:
except PermissionDenied:
return "PASSED"
"""
result = commands.run(permission_denied_query)
assert result == "PASSED"


@pytest.mark.parametrize(
Expand All @@ -104,7 +120,6 @@
INCORRECT_TABLE_FETCH,
SYNTAX_ERROR_EXECUTE,
SYNTAX_ERROR_FETCH,
PERMISSION_DENIED_EXECUTE,
UNKNOWN_ERROR,
],
)
Expand Down

0 comments on commit 0e9ac6a

Please sign in to comment.