Skip to content

Commit f8ff3bd

Browse files
Convert pipeline code to use fixtures. (#166)
1 parent 08d79a9 commit f8ff3bd

File tree

3 files changed

+14
-41
lines changed

3 files changed

+14
-41
lines changed

src/databricks/labs/ucx/providers/mixins/fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def create(
250250
permission_level=permission_level,
251251
)
252252
]
253-
ws.permissions.set(resource_type, object_id, access_control_list=access_control_list)
253+
ws.permissions.update(resource_type, object_id, access_control_list=access_control_list)
254254
return _PermissionsChange(object_id, initial, access_control_list)
255255

256256
def remove(change: _PermissionsChange):
@@ -452,7 +452,7 @@ def create(**kwargs):
452452

453453
@pytest.fixture
454454
def make_pipeline(ws, make_random, make_notebook):
455-
def create(**kwargs):
455+
def create(**kwargs) -> pipelines.CreatePipelineResponse:
456456
if "name" not in kwargs:
457457
kwargs["name"] = f"sdk-{make_random(4)}"
458458
if "libraries" not in kwargs:

tests/integration/conftest.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
from databricks.sdk.service.jobs import CreateResponse
1515
from databricks.sdk.service.ml import CreateExperimentResponse, ModelDatabricks
1616
from databricks.sdk.service.ml import PermissionLevel as ModelPermissionLevel
17-
from databricks.sdk.service.pipelines import (
18-
CreatePipelineResponse,
19-
NotebookLibrary,
20-
PipelineLibrary,
21-
)
2217
from databricks.sdk.service.sql import (
2318
CreateWarehouseRequestWarehouseType,
2419
GetWarehouseResponse,
@@ -47,9 +42,7 @@
4742

4843
NUM_TEST_GROUPS = int(os.environ.get("NUM_TEST_GROUPS", 5))
4944
NUM_TEST_INSTANCE_PROFILES = int(os.environ.get("NUM_TEST_INSTANCE_PROFILES", 3))
50-
NUM_TEST_CLUSTERS = int(os.environ.get("NUM_TEST_CLUSTERS", 3))
5145
NUM_TEST_CLUSTER_POLICIES = int(os.environ.get("NUM_TEST_CLUSTER_POLICIES", 3))
52-
NUM_TEST_PIPELINES = int(os.environ.get("NUM_TEST_PIPELINES", 3))
5346
NUM_TEST_JOBS = int(os.environ.get("NUM_TEST_JOBS", 3))
5447
NUM_TEST_EXPERIMENTS = int(os.environ.get("NUM_TEST_EXPERIMENTS", 3))
5548
NUM_TEST_MODELS = int(os.environ.get("NUM_TEST_MODELS", 3))
@@ -262,36 +255,6 @@ def instance_profiles(env: EnvironmentInfo, ws: WorkspaceClient) -> list[Instanc
262255
logger.debug("Test instance profiles deleted")
263256

264257

265-
@pytest.fixture
266-
def pipelines(env: EnvironmentInfo, ws: WorkspaceClient) -> list[CreatePipelineResponse]:
267-
logger.debug("Creating test DLT pipelines")
268-
269-
test_pipelines: list[CreatePipelineResponse] = [
270-
ws.pipelines.create(
271-
name=f"{env.test_uid}-test-{i}",
272-
continuous=False,
273-
development=True,
274-
libraries=[PipelineLibrary(notebook=NotebookLibrary(path="/Workspace/sample-notebook"))],
275-
)
276-
for i in range(NUM_TEST_PIPELINES)
277-
]
278-
279-
_set_random_permissions(
280-
test_pipelines,
281-
"pipeline_id",
282-
RequestObjectType.PIPELINES,
283-
env,
284-
ws,
285-
permission_levels=[PermissionLevel.CAN_VIEW, PermissionLevel.CAN_RUN, PermissionLevel.CAN_MANAGE],
286-
)
287-
288-
yield test_pipelines
289-
290-
logger.debug("Deleting test instance pools")
291-
executables = [partial(ws.pipelines.delete, p.pipeline_id) for p in test_pipelines]
292-
Threader(executables).run()
293-
294-
295258
@pytest.fixture
296259
def jobs(env: EnvironmentInfo, ws: WorkspaceClient) -> list[CreateResponse]:
297260
logger.debug("Creating test jobs")
@@ -531,7 +494,6 @@ def workspace_objects(ws: WorkspaceClient, env: EnvironmentInfo) -> WorkspaceObj
531494
@pytest.fixture
532495
def verifiable_objects(
533496
cluster_policies,
534-
pipelines,
535497
jobs,
536498
experiments,
537499
models,
@@ -543,7 +505,6 @@ def verifiable_objects(
543505
(workspace_objects, "workspace_objects", None),
544506
(tokens, "tokens", RequestObjectType.AUTHORIZATION),
545507
(cluster_policies, "policy_id", RequestObjectType.CLUSTER_POLICIES),
546-
(pipelines, "pipeline_id", RequestObjectType.PIPELINES),
547508
(jobs, "job_id", RequestObjectType.JOBS),
548509
(experiments, "experiment_id", RequestObjectType.EXPERIMENTS),
549510
(models, "id", RequestObjectType.REGISTERED_MODELS),

tests/integration/test_e2e.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def test_e2e(
134134
make_instance_pool_permissions,
135135
make_cluster,
136136
make_cluster_permissions,
137+
make_pipeline,
138+
make_pipeline_permissions,
137139
make_secret_scope,
138140
make_secret_scope_acl,
139141
):
@@ -160,6 +162,16 @@ def test_e2e(
160162
([cluster], "cluster_id", RequestObjectType.CLUSTERS),
161163
)
162164

165+
pipeline = make_pipeline()
166+
make_pipeline_permissions(
167+
object_id=pipeline.pipeline_id,
168+
permission_level=random.choice([PermissionLevel.CAN_VIEW, PermissionLevel.CAN_RUN, PermissionLevel.CAN_MANAGE]),
169+
group_name=ws_group.display_name,
170+
)
171+
verifiable_objects.append(
172+
([pipeline], "pipeline_id", RequestObjectType.PIPELINES),
173+
)
174+
163175
scope = make_secret_scope()
164176
make_secret_scope_acl(scope=scope, principal=ws_group.display_name, permission=workspace.AclPermission.WRITE)
165177
verifiable_objects.append(([scope], "secret_scopes", None))

0 commit comments

Comments
 (0)