Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e7ebcdc

Browse filesBrowse files
nnegreyDoug Mahugh
authored andcommitted
dialogflow: split up entity and entity type tests (GoogleCloudPlatform#2735)
* dialogflow: split up entity and entity type tests * delete old file * run black on new files
1 parent a2e4e81 commit e7ebcdc
Copy full SHA for e7ebcdc

File tree

Expand file treeCollapse file tree

7 files changed

+369
-92
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+369
-92
lines changed
+70Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2020 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+
from __future__ import absolute_import
16+
17+
import datetime
18+
import os
19+
import pytest
20+
21+
import dialogflow_v2 as dialogflow
22+
23+
import entity_management
24+
25+
PROJECT_ID = os.getenv("GCLOUD_PROJECT")
26+
DISPLAY_NAME = "entity_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
27+
ENTITY_VALUE_1 = "test_entity_value_1"
28+
ENTITY_VALUE_2 = "test_entity_value_2"
29+
SYNONYMS = ["fake_synonym_for_testing_1", "fake_synonym_for_testing_2"]
30+
31+
pytest.ENTITY_TYPE_ID = None
32+
33+
34+
@pytest.fixture(scope="function", autouse=True)
35+
def setup_teardown():
36+
# Create an entity type to use with create entity
37+
entity_types_client = dialogflow.EntityTypesClient()
38+
parent = entity_types_client.project_agent_path(PROJECT_ID)
39+
entity_type = dialogflow.types.EntityType(
40+
display_name=DISPLAY_NAME,
41+
kind=dialogflow.enums.EntityType.Kind.KIND_MAP,
42+
)
43+
44+
response = entity_types_client.create_entity_type(parent, entity_type)
45+
pytest.ENTITY_TYPE_ID = response.name.split("agent/entityTypes/")[1]
46+
47+
yield
48+
# Delete the created entity type and its entities
49+
assert pytest.ENTITY_TYPE_ID is not None
50+
entity_type_path = entity_types_client.entity_type_path(
51+
PROJECT_ID, pytest.ENTITY_TYPE_ID
52+
)
53+
entity_types_client.delete_entity_type(entity_type_path)
54+
55+
56+
def test_create_entity(capsys):
57+
entity_management.create_entity(
58+
PROJECT_ID, pytest.ENTITY_TYPE_ID, ENTITY_VALUE_1, []
59+
)
60+
entity_management.create_entity(
61+
PROJECT_ID, pytest.ENTITY_TYPE_ID, ENTITY_VALUE_2, SYNONYMS
62+
)
63+
64+
entity_management.list_entities(PROJECT_ID, pytest.ENTITY_TYPE_ID)
65+
66+
out, _ = capsys.readouterr()
67+
assert ENTITY_VALUE_1 in out
68+
assert ENTITY_VALUE_2 in out
69+
for synonym in SYNONYMS:
70+
assert synonym in out
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2020 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+
from __future__ import absolute_import
16+
17+
import datetime
18+
import os
19+
import pytest
20+
21+
import dialogflow_v2 as dialogflow
22+
23+
import entity_type_management
24+
25+
PROJECT_ID = os.getenv("GCLOUD_PROJECT")
26+
DISPLAY_NAME = "entity_type_" + datetime.datetime.now().strftime(
27+
"%Y%m%d%H%M%S"
28+
)
29+
pytest.ENTITY_TYPE_ID = None
30+
31+
32+
@pytest.fixture(scope="function", autouse=True)
33+
def teardown():
34+
yield
35+
36+
# Delete the created entity type
37+
entity_types_client = dialogflow.EntityTypesClient()
38+
assert pytest.ENTITY_TYPE_ID is not None
39+
entity_type_path = entity_types_client.entity_type_path(
40+
PROJECT_ID, pytest.ENTITY_TYPE_ID
41+
)
42+
entity_types_client.delete_entity_type(entity_type_path)
43+
44+
45+
def test_create_entity_type(capsys):
46+
entity_type_management.create_entity_type(
47+
PROJECT_ID, DISPLAY_NAME, "KIND_MAP"
48+
)
49+
out, _ = capsys.readouterr()
50+
51+
assert 'display_name: "{}"'.format(DISPLAY_NAME) in out
52+
53+
# Save the entity id so that it can be deleted
54+
pytest.ENTITY_TYPE_ID = out.split("agent/entityTypes/")[1].split('"\n')[0]
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2020 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+
from __future__ import absolute_import
16+
17+
import datetime
18+
import os
19+
import pytest
20+
21+
import dialogflow_v2 as dialogflow
22+
23+
import entity_management
24+
25+
PROJECT_ID = os.getenv("GCLOUD_PROJECT")
26+
DISPLAY_NAME = "entity_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
27+
ENTITY_VALUE_1 = "test_delete_entity_value"
28+
29+
pytest.ENTITY_TYPE_ID = None
30+
31+
32+
@pytest.fixture(scope="function", autouse=True)
33+
def setup_teardown():
34+
# Create an entity type
35+
entity_types_client = dialogflow.EntityTypesClient()
36+
parent = entity_types_client.project_agent_path(PROJECT_ID)
37+
entity_type = dialogflow.types.EntityType(
38+
display_name=DISPLAY_NAME,
39+
kind=dialogflow.enums.EntityType.Kind.KIND_MAP,
40+
)
41+
42+
response = entity_types_client.create_entity_type(parent, entity_type)
43+
pytest.ENTITY_TYPE_ID = response.name.split("agent/entityTypes/")[1]
44+
45+
# Create an entity inside the entity type
46+
entity_type_path = entity_types_client.entity_type_path(
47+
PROJECT_ID, pytest.ENTITY_TYPE_ID
48+
)
49+
entity = dialogflow.types.EntityType.Entity(
50+
value=ENTITY_VALUE_1, synonyms=[ENTITY_VALUE_1]
51+
)
52+
response = entity_types_client.batch_create_entities(
53+
entity_type_path, [entity]
54+
)
55+
response.result()
56+
57+
yield
58+
59+
# Delete the created entity type and its entities
60+
entity_types_client.delete_entity_type(entity_type_path)
61+
62+
63+
def test_delete_entity(capsys):
64+
entity_management.delete_entity(
65+
PROJECT_ID, pytest.ENTITY_TYPE_ID, ENTITY_VALUE_1
66+
)
67+
68+
entity_management.list_entities(PROJECT_ID, pytest.ENTITY_TYPE_ID)
69+
70+
out, _ = capsys.readouterr()
71+
assert ENTITY_VALUE_1 not in out
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2020 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+
from __future__ import absolute_import
16+
17+
import datetime
18+
import os
19+
import pytest
20+
21+
import dialogflow_v2 as dialogflow
22+
23+
import entity_type_management
24+
25+
PROJECT_ID = os.getenv("GCLOUD_PROJECT")
26+
DISPLAY_NAME = "entity_type_" + datetime.datetime.now().strftime(
27+
"%Y%m%d%H%M%S"
28+
)
29+
pytest.ENTITY_TYPE_ID = None
30+
31+
32+
@pytest.fixture(scope="function", autouse=True)
33+
def setup():
34+
# Create an entity type for deletion
35+
entity_types_client = dialogflow.EntityTypesClient()
36+
parent = entity_types_client.project_agent_path(PROJECT_ID)
37+
entity_type = dialogflow.types.EntityType(
38+
display_name=DISPLAY_NAME,
39+
kind=dialogflow.enums.EntityType.Kind.KIND_MAP,
40+
)
41+
42+
response = entity_types_client.create_entity_type(parent, entity_type)
43+
pytest.ENTITY_TYPE_ID = response.name.split("agent/entityTypes/")[1]
44+
45+
46+
def test_delete_entity_type(capsys):
47+
entity_type_management.delete_entity_type(
48+
PROJECT_ID, pytest.ENTITY_TYPE_ID
49+
)
50+
51+
entity_type_management.list_entity_types(PROJECT_ID)
52+
out, _ = capsys.readouterr()
53+
assert DISPLAY_NAME not in out

‎dialogflow/cloud-client/entity_management_test.py

Copy file name to clipboardExpand all lines: dialogflow/cloud-client/entity_management_test.py
-92Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.