|
| 1 | +# Copyright 2021, Google LLC |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | + |
| 14 | +import os |
| 15 | +import uuid |
| 16 | + |
| 17 | +from google.cloud.dialogflowcx_v3.services.agents.client import AgentsClient |
| 18 | +from google.cloud.dialogflowcx_v3.types.agent import Agent, DeleteAgentRequest |
| 19 | + |
| 20 | +import pytest |
| 21 | + |
| 22 | +from long_running_operation import export_long_running_agent |
| 23 | + |
| 24 | +PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") |
| 25 | +pytest.AGENT_ID = None |
| 26 | +pytest.PARENT = None |
| 27 | + |
| 28 | + |
| 29 | +def create_agent(project_id, display_name): |
| 30 | + parent = "projects/" + project_id + "/locations/global" |
| 31 | + |
| 32 | + agents_client = AgentsClient() |
| 33 | + |
| 34 | + agent = Agent( |
| 35 | + display_name=display_name, |
| 36 | + default_language_code="en", |
| 37 | + time_zone="America/Los_Angeles", |
| 38 | + ) |
| 39 | + |
| 40 | + response = agents_client.create_agent(request={"agent": agent, "parent": parent}) |
| 41 | + |
| 42 | + return response |
| 43 | + |
| 44 | + |
| 45 | +def delete_agent(name): |
| 46 | + agents_client = AgentsClient() |
| 47 | + agent = DeleteAgentRequest(name=name) |
| 48 | + agents_client.delete_agent(request=agent) |
| 49 | + |
| 50 | + |
| 51 | +@pytest.fixture(scope="function", autouse=True) |
| 52 | +def setup_teardown(): |
| 53 | + agentName = "temp_agent_" + str(uuid.uuid4()) |
| 54 | + pytest.PARENT = create_agent(PROJECT_ID, agentName).name |
| 55 | + pytest.AGENT_ID = pytest.PARENT.split("/")[5] |
| 56 | + print("Created Agent in setUp") |
| 57 | + |
| 58 | + yield |
| 59 | + |
| 60 | + delete_agent(pytest.PARENT) |
| 61 | + |
| 62 | + |
| 63 | +def test_export_agent(): |
| 64 | + actualResponse = export_long_running_agent(PROJECT_ID, pytest.AGENT_ID, "global") |
| 65 | + |
| 66 | + assert pytest.AGENT_ID in str(actualResponse) |
0 commit comments