Skip to content

Commit

Permalink
Fix nightly CI builds (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx authored Sep 18, 2024
1 parent 47a00ec commit 9c2cd7b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 67 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/no-cheat.yml

This file was deleted.

4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,3 @@
Dependency updates:

* Updated pytest requirement from ~=8.1.0 to ~=8.3.3 ([#31](https://github.com/databrickslabs/pytester/pull/31)).

## 0.0.0

Initial release
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Python Testing for Databricks

[![python](https://img.shields.io/badge/python-3.10,%203.11,%203.12-green)](https://github.com/databrickslabs/pytester/actions/workflows/push.yml)
[![lines of code](https://tokei.rs/b1/github/databrickslabs/pytester)]([https://github.com/databrickslabs/pytester](https://github.com/databrickslabs/pytester))


<!-- TOC -->
* [Python Testing for Databricks](#python-testing-for-databricks)
* [Ecosystem](#ecosystem)
Expand Down Expand Up @@ -61,6 +65,17 @@
* [Project Support](#project-support)
<!-- TOC -->

## Installation

Add a `databricks-labs-pytester` dependency to your `pyproject.toml` file (or legacy `requirements.txt` file). You can
also install it directly from the command line:

```shell
pip install databricks-labs-pytester
```

[[back to top](#python-testing-for-databricks)]

## Ecosystem

Built on top of [Databricks SDK for Python](https://github.com/databricks/databricks-sdk-py), this library is part of the Databricks Labs Python ecosystem, which includes the following projects:
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ classifiers = [
]

dependencies = [
"databricks-sdk~=0.30",
"databricks-labs-lsql~=0.10",
"pytest~=8.3.3",
"databricks-sdk>=0.30",
"databricks-labs-lsql>=0.10",
"pytest>=8.3",
]

[project.entry-points.pytest11]
Expand Down
57 changes: 30 additions & 27 deletions src/databricks/labs/pytester/fixtures/permissions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
from databricks.sdk.errors import InvalidParameterValue
from databricks.sdk.service import sql, iam
from databricks.sdk.service import iam
from databricks.sdk.service.iam import PermissionLevel
from databricks.sdk.service.sql import GetResponse
from databricks.sdk.service.sql import GetResponse, ObjectTypePlural, AccessControl
from databricks.sdk.service.sql import PermissionLevel as RedashPermissionLevel

from databricks.labs.pytester.fixtures.baseline import factory

Expand Down Expand Up @@ -31,18 +32,18 @@ def __repr__(self):


class _RedashPermissionsChange:
def __init__(self, object_id: str, before: list[sql.AccessControl], after: list[sql.AccessControl]):
def __init__(self, object_id: str, before: list[AccessControl], after: list[AccessControl]):
self.object_id = object_id
self.before = before
self.after = after

@staticmethod
def _principal(acr: sql.AccessControl) -> str:
def _principal(acr: AccessControl) -> str:
if acr.user_name is not None:
return f"user_name {acr.user_name}"
return f"group_name {acr.group_name}"

def _list(self, acl: list[sql.AccessControl]):
def _list(self, acl: list[AccessControl]):
return ", ".join(f"{self._principal(_)} {_.permission_level.value}" for _ in acl)

def __repr__(self):
Expand Down Expand Up @@ -132,11 +133,11 @@ def remove(change: _PermissionsChange):

def _make_redash_permissions_factory(name, resource_type, levels, id_retriever):
def _non_inherited(acl: GetResponse):
out: list[sql.AccessControl] = []
out: list[AccessControl] = []
assert acl.access_control_list is not None
for access_control in acl.access_control_list:
out.append(
sql.AccessControl(
AccessControl(
permission_level=access_control.permission_level,
group_name=access_control.group_name,
user_name=access_control.user_name,
Expand All @@ -148,10 +149,10 @@ def _make_permissions(ws):
def create(
*,
object_id: str,
permission_level: sql.PermissionLevel | None = None,
permission_level: RedashPermissionLevel | None = None,
group_name: str | None = None,
user_name: str | None = None,
access_control_list: list[sql.AccessControl] | None = None,
access_control_list: list[AccessControl] | None = None,
):
nothing_specified = permission_level is None and access_control_list is None
both_specified = permission_level is not None and access_control_list is not None
Expand All @@ -172,14 +173,14 @@ def create(
access_control_list = []
if group_name is not None:
access_control_list.append(
sql.AccessControl(
AccessControl(
group_name=group_name,
permission_level=permission_level,
)
)
if user_name is not None:
access_control_list.append(
sql.AccessControl(
AccessControl(
user_name=user_name,
permission_level=permission_level,
)
Expand All @@ -190,7 +191,9 @@ def create(

def remove(change: _RedashPermissionsChange):
ws.dbsql_permissions.set(
sql.ObjectTypePlural(resource_type), change.object_id, access_control_list=change.before
ObjectTypePlural(resource_type),
change.object_id,
access_control_list=change.before,
)

yield from factory(f"{name} permissions", create, remove)
Expand Down Expand Up @@ -371,38 +374,38 @@ def _path(ws, path):
make_dashboard_permissions = pytest.fixture(
_make_redash_permissions_factory(
"dashboard",
"dashboards",
ObjectTypePlural.DASHBOARDS,
[
PermissionLevel.CAN_EDIT,
PermissionLevel.CAN_RUN,
PermissionLevel.CAN_MANAGE,
PermissionLevel.CAN_VIEW,
RedashPermissionLevel.CAN_EDIT,
RedashPermissionLevel.CAN_RUN,
RedashPermissionLevel.CAN_MANAGE,
RedashPermissionLevel.CAN_VIEW,
],
_simple,
)
)
make_alert_permissions = pytest.fixture(
_make_redash_permissions_factory(
"alert",
"alerts",
ObjectTypePlural.ALERTS,
[
PermissionLevel.CAN_EDIT,
PermissionLevel.CAN_RUN,
PermissionLevel.CAN_MANAGE,
PermissionLevel.CAN_VIEW,
RedashPermissionLevel.CAN_EDIT,
RedashPermissionLevel.CAN_RUN,
RedashPermissionLevel.CAN_MANAGE,
RedashPermissionLevel.CAN_VIEW,
],
_simple,
)
)
make_query_permissions = pytest.fixture(
_make_redash_permissions_factory(
"query",
"queries",
ObjectTypePlural.QUERIES,
[
PermissionLevel.CAN_EDIT,
PermissionLevel.CAN_RUN,
PermissionLevel.CAN_MANAGE,
PermissionLevel.CAN_VIEW,
RedashPermissionLevel.CAN_EDIT,
RedashPermissionLevel.CAN_RUN,
RedashPermissionLevel.CAN_MANAGE,
RedashPermissionLevel.CAN_VIEW,
],
_simple,
)
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/fixtures/test_permissions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from databricks.sdk.service.iam import PermissionLevel
from databricks.sdk.service.sql import PermissionLevel as SqlPermissionLevel

from databricks.labs.pytester.fixtures.permissions import make_cluster_permissions, make_query_permissions
from databricks.labs.pytester.fixtures.unwrap import call_stateful
Expand All @@ -18,7 +19,7 @@ def test_make_query_permissions_no_args():
ctx, query_permissions = call_stateful(
make_query_permissions,
object_id="dummy",
permission_level=PermissionLevel.CAN_MANAGE,
permission_level=SqlPermissionLevel.CAN_MANAGE,
)
assert ctx is not None
assert query_permissions is not None

0 comments on commit 9c2cd7b

Please sign in to comment.