Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit a1c2854

Browse files
nnegreybusunkim96
authored andcommitted
Add Set Endpoint Samples [(#2497)](GoogleCloudPlatform/python-docs-samples#2497)
* Add Set Endpoint Samples * Add additional test result option * Sample Request update * Add filter_
1 parent 0460120 commit a1c2854

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

samples/beta/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-automl==0.7.0

samples/beta/set_endpoint.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2019 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 set_endpoint(project_id):
17+
"""Change your endpoint"""
18+
# [START automl_set_endpoint]
19+
from google.cloud import automl_v1beta1 as automl
20+
21+
# You must first create a dataset, using the `eu` endpoint, before you can
22+
# call other operations such as: list, get, import, delete, etc.
23+
client_options = {'api_endpoint': 'eu-automl.googleapis.com:443'}
24+
25+
# Instantiates a client
26+
client = automl.AutoMlClient(client_options=client_options)
27+
28+
# A resource that represents Google Cloud Platform location.
29+
# project_id = 'YOUR_PROJECT_ID'
30+
project_location = client.location_path(project_id, 'eu')
31+
# [END automl_set_endpoint]
32+
33+
# List all the datasets available
34+
# Note: Create a dataset in `eu`, before calling `list_datasets`.
35+
response = client.list_datasets(
36+
project_location, filter_='')
37+
38+
for dataset in response:
39+
print(dataset)

samples/beta/set_endpoint_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2019 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 os
16+
import set_endpoint
17+
18+
PROJECT_ID = os.environ['GCLOUD_PROJECT']
19+
20+
21+
def test_set_endpoint(capsys):
22+
set_endpoint.set_endpoint(PROJECT_ID)
23+
24+
out, _ = capsys.readouterr()
25+
# Look for the display name
26+
assert 'do_not_delete_me' in out

0 commit comments

Comments
 (0)