def test_storage_source_replace(self, hook_mock): hook_mock.return_value.create_build.return_value = TEST_CREATE_BODY current_body = { # [START howto_operator_gcp_cloud_build_source_gcs_url] "source": {"storageSource": "gs://bucket-name/object-name.tar.gz"}, # [END howto_operator_gcp_cloud_build_source_gcs_url] "steps": [ { "name": "gcr.io/cloud-builders/docker", "args": ["build", "-t", "gcr.io/$PROJECT_ID/docker-image", "."], } ], "images": ["gcr.io/$PROJECT_ID/docker-image"], } operator = CloudBuildCreateOperator( body=current_body, project_id=TEST_PROJECT_ID, task_id="task-id" ) operator.execute({}) expected_result = { # [START howto_operator_gcp_cloud_build_source_gcs_dict] "source": {"storageSource": {"bucket": "bucket-name", "object": "object-name.tar.gz"}}, # [END howto_operator_gcp_cloud_build_source_gcs_dict] "steps": [ { "name": "gcr.io/cloud-builders/docker", "args": ["build", "-t", "gcr.io/$PROJECT_ID/docker-image", "."], } ], "images": ["gcr.io/$PROJECT_ID/docker-image"], } hook_mock.create_build(body=expected_result, project_id=TEST_PROJECT_ID)
def test_minimal_green_path(self, mock_hook): mock_hook.return_value.create_build.return_value = TEST_CREATE_BODY operator = CloudBuildCreateOperator(body=TEST_CREATE_BODY, project_id=TEST_PROJECT_ID, task_id="task-id") result = operator.execute({}) self.assertIs(result, TEST_CREATE_BODY)
def test_repo_source_replace(self, hook_mock): hook_mock.return_value.create_build.return_value = TEST_CREATE_BODY current_body = { # [START howto_operator_gcp_cloud_build_source_repo_url] "source": { "repoSource": "https://source.developers.google.com/p/airflow-project/r/airflow-repo" }, # [END howto_operator_gcp_cloud_build_source_repo_url] "steps": [{ "name": "gcr.io/cloud-builders/docker", "args": ["build", "-t", "gcr.io/$PROJECT_ID/docker-image", "."], }], "images": ["gcr.io/$PROJECT_ID/docker-image"], } operator = CloudBuildCreateOperator(body=current_body, project_id=TEST_PROJECT_ID, task_id="task-id") return_value = operator.execute({}) expected_body = { # [START howto_operator_gcp_cloud_build_source_repo_dict] "source": { "repoSource": { "projectId": "airflow-project", "repoName": "airflow-repo", "branchName": "master", } }, # [END howto_operator_gcp_cloud_build_source_repo_dict] "steps": [{ "name": "gcr.io/cloud-builders/docker", "args": ["build", "-t", "gcr.io/$PROJECT_ID/docker-image", "."], }], "images": ["gcr.io/$PROJECT_ID/docker-image"], } hook_mock.return_value.create_build.assert_called_once_with( body=expected_body, project_id=TEST_PROJECT_ID) self.assertEqual(return_value, TEST_CREATE_BODY)