Skip to content

Commit 46aa9b5

Browse files
authored
feat: Add metadata SDK sample for delete method. (#1530)
* feat: Add metadata SDK sample for delete method. * add test fixtures. * fix lint errors
1 parent 34bbd0a commit 46aa9b5

7 files changed

+214
-0
lines changed

samples/model-builder/conftest.py

+34
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,12 @@ def mock_artifact():
527527
yield mock
528528

529529

530+
@pytest.fixture
531+
def mock_context():
532+
mock = MagicMock(aiplatform.Context)
533+
yield mock
534+
535+
530536
@pytest.fixture
531537
def mock_experiment():
532538
mock = MagicMock(aiplatform.Experiment)
@@ -613,13 +619,41 @@ def mock_artifact_get(mock_artifact):
613619
yield mock_artifact_get
614620

615621

622+
@pytest.fixture
623+
def mock_context_get(mock_context):
624+
with patch.object(aiplatform.Context, "get") as mock_context_get:
625+
mock_context_get.return_value = mock_context
626+
yield mock_context_get
627+
628+
616629
@pytest.fixture
617630
def mock_pipeline_job_create(mock_pipeline_job):
618631
with patch.object(aiplatform, "PipelineJob") as mock_pipeline_job_create:
619632
mock_pipeline_job_create.return_value = mock_pipeline_job
620633
yield mock_pipeline_job_create
621634

622635

636+
@pytest.fixture
637+
def mock_artifact_delete():
638+
with patch.object(aiplatform.Artifact, "delete") as mock_artifact_delete:
639+
mock_artifact_delete.return_value = None
640+
yield mock_artifact_delete
641+
642+
643+
@pytest.fixture
644+
def mock_execution_delete():
645+
with patch.object(aiplatform.Execution, "delete") as mock_execution_delete:
646+
mock_execution_delete.return_value = None
647+
yield mock_execution_delete
648+
649+
650+
@pytest.fixture
651+
def mock_context_delete():
652+
with patch.object(aiplatform.Context, "delete") as mock_context_delete:
653+
mock_context_delete.return_value = None
654+
yield mock_context_delete
655+
656+
623657
@pytest.fixture
624658
def mock_pipeline_job_submit(mock_pipeline_job):
625659
with patch.object(mock_pipeline_job, "submit") as mock_pipeline_job_submit:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.cloud import aiplatform
16+
17+
18+
# [START aiplatform_sdk_delete_artifact_sample]
19+
def delete_artifact_sample(
20+
artifact_id: str,
21+
project: str,
22+
location: str,
23+
):
24+
artifact = aiplatform.Artifact.get(
25+
resource_id=artifact_id, project=project, location=location
26+
)
27+
artifact.delete()
28+
29+
# [END aiplatform_sdk_delete_artifact_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import delete_artifact_sample
16+
17+
import test_constants
18+
19+
20+
def test_delete_artifact_sample(mock_artifact, mock_artifact_get):
21+
delete_artifact_sample.delete_artifact_sample(
22+
artifact_id=test_constants.RESOURCE_ID,
23+
project=test_constants.PROJECT,
24+
location=test_constants.LOCATION,
25+
)
26+
27+
mock_artifact_get.assert_called_with(
28+
resource_id=test_constants.RESOURCE_ID,
29+
project=test_constants.PROJECT,
30+
location=test_constants.LOCATION,
31+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.cloud import aiplatform
16+
17+
18+
# [START aiplatform_sdk_delete_context_sample]
19+
def delete_context_sample(
20+
context_id: str,
21+
project: str,
22+
location: str,
23+
):
24+
context = aiplatform.Context.get(
25+
resource_id=context_id, project=project, location=location
26+
)
27+
context.delete()
28+
29+
# [END aiplatform_sdk_delete_context_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import delete_context_sample
16+
17+
import test_constants
18+
19+
20+
def test_delete_context_sample(mock_context_get):
21+
delete_context_sample.delete_context_sample(
22+
context_id=test_constants.RESOURCE_ID,
23+
project=test_constants.PROJECT,
24+
location=test_constants.LOCATION,
25+
)
26+
27+
mock_context_get.assert_called_with(
28+
resource_id=test_constants.RESOURCE_ID,
29+
project=test_constants.PROJECT,
30+
location=test_constants.LOCATION,
31+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.cloud import aiplatform
16+
17+
18+
# [START aiplatform_sdk_delete_execution_sample]
19+
def delete_execution_sample(
20+
execution_id: str,
21+
project: str,
22+
location: str,
23+
):
24+
execution = aiplatform.Execution.get(
25+
resource_id=execution_id, project=project, location=location
26+
)
27+
execution.delete()
28+
29+
# [END aiplatform_sdk_delete_execution_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import delete_execution_sample
16+
17+
import test_constants
18+
19+
20+
def test_delete_execution_sample(mock_execution, mock_execution_get):
21+
delete_execution_sample.delete_execution_sample(
22+
execution_id=test_constants.RESOURCE_ID,
23+
project=test_constants.PROJECT,
24+
location=test_constants.LOCATION,
25+
)
26+
27+
mock_execution_get.assert_called_with(
28+
resource_id=test_constants.RESOURCE_ID,
29+
project=test_constants.PROJECT,
30+
location=test_constants.LOCATION,
31+
)

0 commit comments

Comments
 (0)