-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datacatalog): add sample to create an entry group (#9584)
* feat(datacatalog): add sample to create an entry group Closes #9583 * feat(datacatalog): add sample to create an entry group Fix pytest fixtures and synth.py.
- Loading branch information
1 parent
1ddb894
commit a5e5344
Showing
8 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
55 changes: 55 additions & 0 deletions
55
packages/google-cloud-datacatalog/samples/tests/conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import datetime | ||
import uuid | ||
|
||
import pytest | ||
|
||
import google.auth | ||
from google.cloud import datacatalog_v1beta1 | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def client(credentials): | ||
return datacatalog_v1beta1.DataCatalogClient(credentials=credentials) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def default_credentials(): | ||
return google.auth.default() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def credentials(default_credentials): | ||
return default_credentials[0] | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def project_id(default_credentials): | ||
return default_credentials[1] | ||
|
||
|
||
@pytest.fixture | ||
def random_entry_group_id(client, project_id): | ||
now = datetime.datetime.now() | ||
random_entry_group_id = "example_entry_group_{}_{}".format( | ||
now.strftime("%Y%m%d%H%M%S"), uuid.uuid4().hex[:8] | ||
) | ||
yield random_entry_group_id | ||
entry_group_name = datacatalog_v1beta1.DataCatalogClient.entry_group_path( | ||
project_id, "us-central1", random_entry_group_id | ||
) | ||
client.delete_entry_group(entry_group_name) |
29 changes: 29 additions & 0 deletions
29
packages/google-cloud-datacatalog/samples/tests/test_create_entry_group.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
from ..v1beta1 import create_entry_group | ||
|
||
|
||
def test_create_entry_group(capsys, client, project_id, random_entry_group_id): | ||
|
||
create_entry_group.create_entry_group(client, project_id, random_entry_group_id) | ||
out, err = capsys.readouterr() | ||
assert ( | ||
"Created entry group" | ||
" projects/{}/locations/{}/entryGroups/{}".format( | ||
project_id, "us-central1", random_entry_group_id | ||
) | ||
in out | ||
) |
Empty file.
54 changes: 54 additions & 0 deletions
54
packages/google-cloud-datacatalog/samples/v1beta1/create_entry_group.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
def create_entry_group(client, project_id, entry_group_id): | ||
|
||
# [START datacatalog_create_entry_group_tag] | ||
from google.cloud import datacatalog_v1beta1 | ||
|
||
# TODO(developer): Construct a Data Catalog client object. | ||
# client = datacatalog_v1beta1.DataCatalogClient() | ||
|
||
# TODO(developer): Set entry_group_id to the ID of the | ||
# entry group to create. | ||
# project_id = "your-project-id" | ||
|
||
# TODO(developer): Specify the geographic location where the | ||
# entry group should reside. | ||
# Currently, Data Catalog stores metadata in the us-central1 region. | ||
location_id = "us-central1" | ||
|
||
# TODO(developer): Set entry_group_id to the ID of the | ||
# entry group to create. | ||
# entry_group_id = "your_entry_group_id" | ||
|
||
# Construct a full location path to be the parent of the entry group. | ||
parent = datacatalog_v1beta1.DataCatalogClient.location_path( | ||
project_id, location_id | ||
) | ||
|
||
# Construct a full EntryGroup object to send to the API. | ||
entry_group = datacatalog_v1beta1.types.EntryGroup() | ||
entry_group.display_name = "My Entry Group" | ||
entry_group.description = "This Entry Group consists of ..." | ||
|
||
# Send the entry group to the API for creation. | ||
# Raises google.api_core.exceptions.AlreadyExists if the Entry Group | ||
# already exists within the project. | ||
entry_group = client.create_entry_group( | ||
parent, entry_group_id, entry_group | ||
) # Make an API request. | ||
print("Created entry group {}".format(entry_group.name)) | ||
# [END datacatalog_create_entry_group_tag] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters