Skip to content

Commit 2bc9b2b

Browse files
authored
tests: Added a unit test that checks the arguments that the PipelineJob.submit method passes to gcs_utils.create_gcs_bucket_for_pipeline_artifacts_if_it_does_not_exist (#1547)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-aiplatform/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕
1 parent 76a3f59 commit 2bc9b2b

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tests/unit/aiplatform/test_pipeline_jobs.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
_TEST_PIPELINE_JOB_DISPLAY_NAME = "sample-pipeline-job-display-name"
5454
_TEST_PIPELINE_JOB_ID = "sample-test-pipeline-202111111"
5555
_TEST_GCS_BUCKET_NAME = "my-bucket"
56+
_TEST_GCS_OUTPUT_DIRECTORY = f"gs://{_TEST_GCS_BUCKET_NAME}/output_artifacts/"
5657
_TEST_CREDENTIALS = auth_credentials.AnonymousCredentials()
5758
_TEST_SERVICE_ACCOUNT = "[email protected]"
5859

@@ -249,7 +250,7 @@ def mock_create_gcs_bucket_for_pipeline_artifacts_if_it_does_not_exist(
249250

250251
with mock.patch(
251252
"google.cloud.aiplatform.utils.gcs_utils.create_gcs_bucket_for_pipeline_artifacts_if_it_does_not_exist",
252-
new=mock_create_gcs_bucket_for_pipeline_artifacts_if_it_does_not_exist,
253+
wraps=mock_create_gcs_bucket_for_pipeline_artifacts_if_it_does_not_exist,
253254
) as mock_context:
254255
yield mock_context
255256

@@ -1097,6 +1098,44 @@ def test_submit_call_pipeline_service_pipeline_job_create(
10971098
gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED
10981099
)
10991100

1101+
@pytest.mark.parametrize(
1102+
"job_spec",
1103+
[_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB],
1104+
)
1105+
def test_submit_call_gcs_utils_get_or_create_with_correct_arguments(
1106+
self,
1107+
mock_pipeline_service_create,
1108+
mock_pipeline_service_get,
1109+
mock_pipeline_bucket_exists,
1110+
job_spec,
1111+
mock_load_yaml_and_json,
1112+
):
1113+
job = pipeline_jobs.PipelineJob(
1114+
display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME,
1115+
template_path=_TEST_TEMPLATE_PATH,
1116+
job_id=_TEST_PIPELINE_JOB_ID,
1117+
parameter_values=_TEST_PIPELINE_PARAMETER_VALUES,
1118+
enable_caching=True,
1119+
project=_TEST_PROJECT,
1120+
pipeline_root=_TEST_GCS_OUTPUT_DIRECTORY,
1121+
location=_TEST_LOCATION,
1122+
credentials=_TEST_CREDENTIALS,
1123+
)
1124+
1125+
job.submit(
1126+
service_account=_TEST_SERVICE_ACCOUNT,
1127+
network=_TEST_NETWORK,
1128+
create_request_timeout=None,
1129+
)
1130+
1131+
mock_pipeline_bucket_exists.assert_called_once_with(
1132+
output_artifacts_gcs_dir=_TEST_GCS_OUTPUT_DIRECTORY,
1133+
service_account=_TEST_SERVICE_ACCOUNT,
1134+
project=_TEST_PROJECT,
1135+
location=_TEST_LOCATION,
1136+
credentials=_TEST_CREDENTIALS,
1137+
)
1138+
11001139
@pytest.mark.parametrize(
11011140
"job_spec",
11021141
[_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB],

0 commit comments

Comments
 (0)