Skip to content

Commit 594d8bc

Browse files
nnegreyleahecolebusunkim96gcf-merge-on-green[bot]
authored
automl: video beta samples move from branch to master [(#2753)](GoogleCloudPlatform/python-docs-samples#2753)
* automl: video beta samples move from branch to master * fix test for when create dataset doesn't return an LRO Co-authored-by: Leah E. Cole <[email protected]> Co-authored-by: Bu Sun Kim <[email protected]> Co-authored-by: gcf-merge-on-green[bot] <60162190+gcf-merge-on-green[bot]@users.noreply.github.com>
1 parent ffc01e8 commit 594d8bc

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

samples/beta/delete_dataset.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2020 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+
# http://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+
16+
def delete_dataset(project_id, dataset_id):
17+
"""Delete a dataset."""
18+
# [START automl_delete_dataset_beta]
19+
from google.cloud import automl_v1beta1 as automl
20+
21+
# TODO(developer): Uncomment and set the following variables
22+
# project_id = "YOUR_PROJECT_ID"
23+
# dataset_id = "YOUR_DATASET_ID"
24+
25+
client = automl.AutoMlClient()
26+
# Get the full path of the dataset
27+
dataset_full_id = client.dataset_path(
28+
project_id, "us-central1", dataset_id
29+
)
30+
response = client.delete_dataset(dataset_full_id)
31+
32+
print("Dataset deleted. {}".format(response.result()))
33+
# [END automl_delete_dataset_beta]

samples/beta/delete_dataset_test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2020 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+
# http://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 datetime
16+
import os
17+
18+
from google.cloud import automl_v1beta1 as automl
19+
import pytest
20+
21+
import delete_dataset
22+
23+
PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
24+
BUCKET_ID = "{}-lcm".format(PROJECT_ID)
25+
26+
27+
@pytest.fixture(scope="function")
28+
def dataset_id():
29+
client = automl.AutoMlClient()
30+
project_location = client.location_path(PROJECT_ID, "us-central1")
31+
display_name = "test_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
32+
metadata = automl.types.TextExtractionDatasetMetadata()
33+
dataset = automl.types.Dataset(
34+
display_name=display_name, text_extraction_dataset_metadata=metadata
35+
)
36+
dataset = client.create_dataset(project_location, dataset)
37+
dataset_id = dataset.name.split("/")[-1]
38+
39+
yield dataset_id
40+
41+
42+
def test_delete_dataset(capsys, dataset_id):
43+
# delete dataset
44+
delete_dataset.delete_dataset(PROJECT_ID, dataset_id)
45+
out, _ = capsys.readouterr()
46+
assert "Dataset deleted." in out

samples/beta/import_dataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
1516
# [START automl_import_data_beta]
1617
from google.cloud import automl_v1beta1 as automl
1718

samples/beta/list_datasets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
1516
# [START automl_video_classification_list_datasets_beta]
1617
# [START automl_video_object_tracking_list_datasets_beta]
1718
from google.cloud import automl_v1beta1 as automl

0 commit comments

Comments
 (0)