|
| 1 | +# Copyright 2024 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 | +import os |
| 15 | + |
| 16 | +import uuid |
| 17 | + |
| 18 | +from google.api_core.retry import Retry |
| 19 | + |
| 20 | +import pytest |
| 21 | + |
| 22 | +import create_entry_group |
| 23 | +import delete_entry_group |
| 24 | +import get_entry_group |
| 25 | +import list_entry_groups |
| 26 | +import update_entry_group |
| 27 | + |
| 28 | +PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") |
| 29 | +LOCATION = "us-central1" |
| 30 | +ENTRY_GROUP_ID = f"test-entry-group-{str(uuid.uuid4()).split('-')[0]}" |
| 31 | +EXPECTED_ENTRY_GROUP = ( |
| 32 | + f"projects/{PROJECT_ID}/locations/{LOCATION}/entryGroups/{ENTRY_GROUP_ID}" |
| 33 | +) |
| 34 | + |
| 35 | + |
| 36 | +@pytest.fixture(autouse=True, scope="session") |
| 37 | +def setup_and_teardown_entry_group() -> None: |
| 38 | + try: |
| 39 | + # Create Entry Group resource that will be used in tests for "get", "list" and "update" methods |
| 40 | + create_entry_group.create_entry_group(PROJECT_ID, LOCATION, ENTRY_GROUP_ID) |
| 41 | + yield |
| 42 | + finally: |
| 43 | + # Clean-up Entry Group resource created above |
| 44 | + delete_entry_group.delete_entry_group(PROJECT_ID, LOCATION, ENTRY_GROUP_ID) |
| 45 | + |
| 46 | + |
| 47 | +@Retry() |
| 48 | +def test_list_entry_groups() -> None: |
| 49 | + entry_groups = list_entry_groups.list_entry_groups(PROJECT_ID, LOCATION) |
| 50 | + assert EXPECTED_ENTRY_GROUP in [entry_group.name for entry_group in entry_groups] |
| 51 | + |
| 52 | + |
| 53 | +@Retry() |
| 54 | +def test_get_entry_group() -> None: |
| 55 | + entry_group = get_entry_group.get_entry_group(PROJECT_ID, LOCATION, ENTRY_GROUP_ID) |
| 56 | + assert EXPECTED_ENTRY_GROUP == entry_group.name |
| 57 | + |
| 58 | + |
| 59 | +@Retry() |
| 60 | +def test_update_entry_group() -> None: |
| 61 | + entry_group = update_entry_group.update_entry_group( |
| 62 | + PROJECT_ID, LOCATION, ENTRY_GROUP_ID |
| 63 | + ) |
| 64 | + assert EXPECTED_ENTRY_GROUP == entry_group.name |
| 65 | + |
| 66 | + |
| 67 | +@Retry() |
| 68 | +def test_create_entry_group() -> None: |
| 69 | + entry_group_id_to_create = f"test-entry-group-{str(uuid.uuid4()).split('-')[0]}" |
| 70 | + expected_entry_group_to_create = f"projects/{PROJECT_ID}/locations/{LOCATION}/entryGroups/{entry_group_id_to_create}" |
| 71 | + try: |
| 72 | + entry_group = create_entry_group.create_entry_group( |
| 73 | + PROJECT_ID, LOCATION, entry_group_id_to_create |
| 74 | + ) |
| 75 | + assert expected_entry_group_to_create == entry_group.name |
| 76 | + finally: |
| 77 | + # Clean-up created Entry Group |
| 78 | + delete_entry_group.delete_entry_group( |
| 79 | + PROJECT_ID, LOCATION, entry_group_id_to_create |
| 80 | + ) |
| 81 | + |
| 82 | + |
| 83 | +@Retry() |
| 84 | +def test_delete_entry_group() -> None: |
| 85 | + entry_group_id_to_delete = f"test-entry-group-{str(uuid.uuid4()).split('-')[0]}" |
| 86 | + # Create Entry Group to be deleted |
| 87 | + create_entry_group.create_entry_group( |
| 88 | + PROJECT_ID, LOCATION, entry_group_id_to_delete |
| 89 | + ) |
| 90 | + # No exception means successful call |
| 91 | + delete_entry_group.delete_entry_group( |
| 92 | + PROJECT_ID, LOCATION, entry_group_id_to_delete |
| 93 | + ) |
0 commit comments