Skip to content

Commit 76319a4

Browse files
larsgeorge-dbnfx
andauthored
Replace jobs test with fixture based one. (#167)
Co-authored-by: Serge Smertin <[email protected]>
1 parent f8ff3bd commit 76319a4

File tree

2 files changed

+14
-33
lines changed

2 files changed

+14
-33
lines changed

tests/integration/conftest.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from databricks.sdk.core import Config, DatabricksError
1212
from databricks.sdk.service.compute import CreatePolicyResponse
1313
from databricks.sdk.service.iam import AccessControlRequest, PermissionLevel
14-
from databricks.sdk.service.jobs import CreateResponse
1514
from databricks.sdk.service.ml import CreateExperimentResponse, ModelDatabricks
1615
from databricks.sdk.service.ml import PermissionLevel as ModelPermissionLevel
1716
from databricks.sdk.service.sql import (
@@ -30,8 +29,6 @@
3029
EnvironmentInfo,
3130
InstanceProfile,
3231
WorkspaceObjects,
33-
_get_basic_job_cluster,
34-
_get_basic_task,
3532
_set_random_permissions,
3633
)
3734

@@ -43,7 +40,6 @@
4340
NUM_TEST_GROUPS = int(os.environ.get("NUM_TEST_GROUPS", 5))
4441
NUM_TEST_INSTANCE_PROFILES = int(os.environ.get("NUM_TEST_INSTANCE_PROFILES", 3))
4542
NUM_TEST_CLUSTER_POLICIES = int(os.environ.get("NUM_TEST_CLUSTER_POLICIES", 3))
46-
NUM_TEST_JOBS = int(os.environ.get("NUM_TEST_JOBS", 3))
4743
NUM_TEST_EXPERIMENTS = int(os.environ.get("NUM_TEST_EXPERIMENTS", 3))
4844
NUM_TEST_MODELS = int(os.environ.get("NUM_TEST_MODELS", 3))
4945
NUM_TEST_WAREHOUSES = int(os.environ.get("NUM_TEST_WAREHOUSES", 3))
@@ -255,33 +251,6 @@ def instance_profiles(env: EnvironmentInfo, ws: WorkspaceClient) -> list[Instanc
255251
logger.debug("Test instance profiles deleted")
256252

257253

258-
@pytest.fixture
259-
def jobs(env: EnvironmentInfo, ws: WorkspaceClient) -> list[CreateResponse]:
260-
logger.debug("Creating test jobs")
261-
262-
test_jobs: list[CreateResponse] = [
263-
ws.jobs.create(
264-
name=f"{env.test_uid}-test-{i}", job_clusters=[_get_basic_job_cluster()], tasks=[_get_basic_task()]
265-
)
266-
for i in range(NUM_TEST_JOBS)
267-
]
268-
269-
_set_random_permissions(
270-
test_jobs,
271-
"job_id",
272-
RequestObjectType.JOBS,
273-
env,
274-
ws,
275-
permission_levels=[PermissionLevel.CAN_VIEW, PermissionLevel.CAN_MANAGE_RUN, PermissionLevel.CAN_MANAGE],
276-
)
277-
278-
yield test_jobs
279-
280-
logger.debug("Deleting test jobs")
281-
executables = [partial(ws.jobs.delete, j.job_id) for j in test_jobs]
282-
Threader(executables).run()
283-
284-
285254
@pytest.fixture
286255
def cluster_policies(env: EnvironmentInfo, ws: WorkspaceClient) -> list[CreatePolicyResponse]:
287256
logger.debug("Creating test cluster policies")
@@ -494,7 +463,6 @@ def workspace_objects(ws: WorkspaceClient, env: EnvironmentInfo) -> WorkspaceObj
494463
@pytest.fixture
495464
def verifiable_objects(
496465
cluster_policies,
497-
jobs,
498466
experiments,
499467
models,
500468
warehouses,
@@ -505,7 +473,6 @@ def verifiable_objects(
505473
(workspace_objects, "workspace_objects", None),
506474
(tokens, "tokens", RequestObjectType.AUTHORIZATION),
507475
(cluster_policies, "policy_id", RequestObjectType.CLUSTER_POLICIES),
508-
(jobs, "job_id", RequestObjectType.JOBS),
509476
(experiments, "experiment_id", RequestObjectType.EXPERIMENTS),
510477
(models, "id", RequestObjectType.REGISTERED_MODELS),
511478
(warehouses, "id", RequestObjectType.SQL_WAREHOUSES),

tests/integration/test_e2e.py

Lines changed: 14 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_job,
138+
make_job_permissions,
137139
make_pipeline,
138140
make_pipeline_permissions,
139141
make_secret_scope,
@@ -162,6 +164,18 @@ def test_e2e(
162164
([cluster], "cluster_id", RequestObjectType.CLUSTERS),
163165
)
164166

167+
job = make_job()
168+
make_job_permissions(
169+
object_id=job.job_id,
170+
permission_level=random.choice(
171+
[PermissionLevel.CAN_VIEW, PermissionLevel.CAN_MANAGE_RUN, PermissionLevel.CAN_MANAGE]
172+
),
173+
group_name=ws_group.display_name,
174+
)
175+
verifiable_objects.append(
176+
([job], "job_id", RequestObjectType.JOBS),
177+
)
178+
165179
pipeline = make_pipeline()
166180
make_pipeline_permissions(
167181
object_id=pipeline.pipeline_id,

0 commit comments

Comments
 (0)