|
1 | 1 | import json
|
2 | 2 | import os
|
3 |
| -from typing import Callable |
4 | 3 | from unittest.mock import Mock, patch
|
5 | 4 |
|
6 | 5 | import jwt
|
7 | 6 | import pytest
|
8 |
| -import yaml |
9 |
| -from msrest import Deserializer |
10 | 7 | from pytest_mock import MockFixture
|
11 | 8 |
|
12 |
| -from azure.ai.ml import MLClient, load_job |
| 9 | +from azure.ai.ml import load_job |
13 | 10 | from azure.ai.ml._azure_environments import _get_aml_resource_id_from_metadata, _resource_to_scopes
|
14 | 11 | from azure.ai.ml._restclient.v2023_04_01_preview import models
|
15 | 12 | from azure.ai.ml._scope_dependent_operations import OperationConfig, OperationScope
|
16 |
| -from azure.ai.ml.constants._common import AZUREML_PRIVATE_FEATURES_ENV_VAR, AzureMLResourceType |
| 13 | +from azure.ai.ml.constants._common import AZUREML_PRIVATE_FEATURES_ENV_VAR, AzureMLResourceType, GitProperties |
17 | 14 | from azure.ai.ml.entities._builders import Command
|
18 |
| -from azure.ai.ml.entities._job.automl.automl_job import AutoMLJob |
19 |
| -from azure.ai.ml.entities._job.automl.training_settings import TrainingSettings |
20 | 15 | from azure.ai.ml.entities._job.job import Job
|
21 |
| -from azure.ai.ml.entities._job.sweep.sweep_job import SweepJob |
22 |
| -from azure.ai.ml.exceptions import ValidationException |
23 | 16 | from azure.ai.ml.operations import DatastoreOperations, EnvironmentOperations, JobOperations, WorkspaceOperations
|
24 | 17 | from azure.ai.ml.operations._code_operations import CodeOperations
|
25 | 18 | from azure.ai.ml.operations._job_ops_helper import get_git_properties
|
26 |
| -from azure.ai.ml.operations._run_history_constants import RunHistoryConstants |
27 | 19 | from azure.ai.ml.operations._run_operations import RunOperations
|
28 | 20 | from azure.core.credentials import AccessToken
|
29 |
| -from azure.core.exceptions import HttpResponseError |
30 | 21 | from azure.identity import DefaultAzureCredential
|
31 | 22 |
|
32 |
| -from .test_vcr_utils import before_record_cb, vcr_header_filters |
33 |
| - |
34 | 23 |
|
35 | 24 | @pytest.fixture
|
36 | 25 | def mock_datastore_operation(
|
@@ -298,6 +287,64 @@ def test_job_create_skip_validation(self, mock_method, mock_job_operation: JobOp
|
298 | 287 | mock_job_operation.create_or_update(job=job)
|
299 | 288 | mock_thing.assert_called_once()
|
300 | 289 |
|
| 290 | + @patch("azure.ai.ml.operations._job_operations.get_git_properties") |
| 291 | + @patch.object(Job, "_from_rest_object") |
| 292 | + def test_create_or_update_removes_git_props_if_pat_in_repo_url( |
| 293 | + self, mock_method, mock_get_git_properties, mock_job_operation: JobOperations |
| 294 | + ) -> None: |
| 295 | + mock_method.return_value = Command(component=None) |
| 296 | + |
| 297 | + mock_get_git_properties.return_value = { |
| 298 | + GitProperties.PROP_MLFLOW_GIT_REPO_URL: "https://example@mock-repo-url", |
| 299 | + GitProperties.PROP_MLFLOW_GIT_BRANCH: "mock-branch", |
| 300 | + GitProperties.PROP_MLFLOW_GIT_COMMIT: "mock-commit", |
| 301 | + GitProperties.PROP_DIRTY: "True", |
| 302 | + } |
| 303 | + |
| 304 | + job = load_job("./tests/test_configs/command_job/simple_train_test.yml") |
| 305 | + with patch.object(JobOperations, "_validate") as mock_thing, patch.object( |
| 306 | + JobOperations, "_resolve_arm_id_or_upload_dependencies" |
| 307 | + ): |
| 308 | + mock_job_operation.create_or_update(job=job) |
| 309 | + mock_get_git_properties.assert_called_once() |
| 310 | + assert ( |
| 311 | + GitProperties.PROP_MLFLOW_GIT_REPO_URL not in job.properties |
| 312 | + ), "repoURL key should not exist in job.properties" |
| 313 | + assert ( |
| 314 | + GitProperties.PROP_MLFLOW_GIT_BRANCH not in job.properties |
| 315 | + ), "branch key should not exist in job.properties" |
| 316 | + assert ( |
| 317 | + GitProperties.PROP_MLFLOW_GIT_COMMIT not in job.properties |
| 318 | + ), "commit key should not exist in job.properties" |
| 319 | + assert GitProperties.PROP_DIRTY not in job.properties, "dirty key should not exist in job.properties" |
| 320 | + |
| 321 | + @patch("azure.ai.ml.operations._job_operations.get_git_properties") |
| 322 | + @patch.object(Job, "_from_rest_object") |
| 323 | + def test_create_or_update_includes_git_props_if_no_pat_in_repo_url( |
| 324 | + self, mock_method, mock_get_git_properties, mock_job_operation: JobOperations |
| 325 | + ) -> None: |
| 326 | + mock_method.return_value = Command(component=None) |
| 327 | + |
| 328 | + mock_get_git_properties.return_value = { |
| 329 | + GitProperties.PROP_MLFLOW_GIT_REPO_URL: "https://mock-repo-url", |
| 330 | + GitProperties.PROP_MLFLOW_GIT_BRANCH: "mock-branch", |
| 331 | + GitProperties.PROP_MLFLOW_GIT_COMMIT: "mock-commit", |
| 332 | + GitProperties.PROP_DIRTY: "True", |
| 333 | + } |
| 334 | + |
| 335 | + job = load_job("./tests/test_configs/command_job/simple_train_test.yml") |
| 336 | + with patch.object(JobOperations, "_validate") as mock_thing, patch.object( |
| 337 | + JobOperations, "_resolve_arm_id_or_upload_dependencies" |
| 338 | + ): |
| 339 | + mock_job_operation.create_or_update(job=job) |
| 340 | + mock_get_git_properties.assert_called_once() |
| 341 | + assert ( |
| 342 | + GitProperties.PROP_MLFLOW_GIT_REPO_URL in job.properties |
| 343 | + ), "repoURL key should exist in job.properties" |
| 344 | + assert GitProperties.PROP_MLFLOW_GIT_BRANCH in job.properties, "branch key should exist in job.properties" |
| 345 | + assert GitProperties.PROP_MLFLOW_GIT_COMMIT in job.properties, "commit key should exist in job.properties" |
| 346 | + assert GitProperties.PROP_DIRTY in job.properties, "dirty key should exist in job.properties" |
| 347 | + |
301 | 348 | def test_download_with_none(self, mock_job_operation: JobOperations) -> None:
|
302 | 349 | with pytest.raises(Exception) as ex:
|
303 | 350 | mock_job_operation.download(None)
|
|
0 commit comments