|
| 1 | +# Copyright 2021 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 uuid |
| 17 | + |
| 18 | +from google.cloud.dialogflow_v2.services.agents.client import AgentsClient |
| 19 | +from google.cloud.dialogflow_v2.services.intents.client import IntentsClient |
| 20 | +from google.cloud.dialogflow_v2.types.intent import Intent |
| 21 | + |
| 22 | +import pytest |
| 23 | + |
| 24 | +from update_intent import update_intent |
| 25 | + |
| 26 | +PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") |
| 27 | +pytest.INTENT_ID = None |
| 28 | + |
| 29 | + |
| 30 | +def create_intent(project_id): |
| 31 | + intents_client = IntentsClient() |
| 32 | + |
| 33 | + parent = AgentsClient.agent_path(project_id) |
| 34 | + |
| 35 | + intent = Intent() |
| 36 | + |
| 37 | + intent.display_name = "fake_intent" |
| 38 | + |
| 39 | + intents = intents_client.create_intent(request={"parent": parent, "intent": intent}) |
| 40 | + |
| 41 | + return intents.name.split("/")[4] |
| 42 | + |
| 43 | + |
| 44 | +@pytest.fixture(scope="function", autouse=True) |
| 45 | +def setup_teardown(): |
| 46 | + pytest.INTENT_ID = create_intent(project_id=PROJECT_ID) |
| 47 | + print("Created Intent in setUp") |
| 48 | + |
| 49 | + |
| 50 | +def test_update_intent(): |
| 51 | + |
| 52 | + fake_intent = "fake_intent_{}".format(uuid.uuid4()) |
| 53 | + |
| 54 | + actualResponse = update_intent(PROJECT_ID, pytest.INTENT_ID, fake_intent) |
| 55 | + expectedResponse = fake_intent |
| 56 | + |
| 57 | + intents_client = IntentsClient() |
| 58 | + |
| 59 | + intents_client.delete_intent(name=actualResponse.name) |
| 60 | + |
| 61 | + assert actualResponse.display_name == expectedResponse |
0 commit comments