-
Notifications
You must be signed in to change notification settings - Fork 6.5k
dialogflow: use unique names for all resources for tests to avoid col… #2696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c8394cf
dialogflow: use unique names for all resources for tests to avoid col…
nnegrey 2efa87d
lint: line length
nnegrey b864630
break up knowledge base tests and document tests from one file into i…
nnegrey 347bf69
Merge branch 'master' into dialogflow-unique-names
nnegrey 59f5bd9
lint
nnegrey c814542
Merge branch 'dialogflow-unique-names' of https://github.com/GoogleCl…
nnegrey d517a8e
Merge branch 'master' into dialogflow-unique-names
gguuss 26b469e
bump library version
nnegrey c0c1261
ping googleapis-common-protos to avoid release breakage
nnegrey f6987c3
Update requirements.txt
nnegrey 1fc96cd
Merge branch 'master' into dialogflow-unique-names
nnegrey 52d72d7
Merge branch 'master' into dialogflow-unique-names
nnegrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,57 @@ | ||
# Copyright 2020 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 | ||
# | ||
# http://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 __future__ import absolute_import | ||
|
||
import datetime | ||
import os | ||
|
||
import dialogflow_v2beta1 as dialogflow | ||
import pytest | ||
|
||
import document_management | ||
|
||
PROJECT_ID = os.getenv('GCLOUD_PROJECT') | ||
KNOWLEDGE_BASE_NAME = 'knowledge_' \ | ||
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S") | ||
DOCUMENT_DISPLAY_NAME = 'test_document_' \ | ||
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S") | ||
pytest.KNOWLEDGE_BASE_ID = None | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def setup_teardown(): | ||
# Create a knowledge base to use in document management | ||
client = dialogflow.KnowledgeBasesClient() | ||
project_path = client.project_path(PROJECT_ID) | ||
knowledge_base = dialogflow.types.KnowledgeBase( | ||
display_name=KNOWLEDGE_BASE_NAME) | ||
response = client.create_knowledge_base(project_path, knowledge_base) | ||
pytest.KNOWLEDGE_BASE_ID = response.name.split( | ||
'/knowledgeBases/')[1].split('\n')[0] | ||
|
||
yield | ||
|
||
# Delete the created knowledge base | ||
knowledge_base_path = client.knowledge_base_path( | ||
PROJECT_ID, pytest.KNOWLEDGE_BASE_ID) | ||
client.delete_knowledge_base(knowledge_base_path, force=True) | ||
|
||
|
||
def test_create_document(capsys): | ||
document_management.create_document( | ||
PROJECT_ID, pytest.KNOWLEDGE_BASE_ID, DOCUMENT_DISPLAY_NAME, | ||
'text/html', 'FAQ', 'https://cloud.google.com/storage/docs/faq') | ||
out, _ = capsys.readouterr() | ||
assert DOCUMENT_DISPLAY_NAME in out |
This file contains hidden or 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,49 @@ | ||
# Copyright 2020 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 | ||
# | ||
# http://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 __future__ import absolute_import | ||
|
||
import datetime | ||
import os | ||
import pytest | ||
|
||
import dialogflow_v2beta1 as dialogflow | ||
|
||
import knowledge_base_management | ||
|
||
PROJECT_ID = os.getenv('GCLOUD_PROJECT') | ||
KNOWLEDGE_BASE_NAME = 'knowledge_' \ | ||
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S") | ||
pytest.KNOWLEDGE_BASE_ID = None | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def teardown(): | ||
yield | ||
|
||
# Delete the created knowledge base | ||
client = dialogflow.KnowledgeBasesClient() | ||
assert pytest.KNOWLEDGE_BASE_ID is not None | ||
knowledge_base_path = client.knowledge_base_path( | ||
PROJECT_ID, pytest.KNOWLEDGE_BASE_ID) | ||
client.delete_knowledge_base(knowledge_base_path) | ||
|
||
|
||
def test_create_knowledge_base(capsys): | ||
knowledge_base_management.create_knowledge_base(PROJECT_ID, | ||
KNOWLEDGE_BASE_NAME) | ||
out, _ = capsys.readouterr() | ||
assert KNOWLEDGE_BASE_NAME in out | ||
|
||
pytest.KNOWLEDGE_BASE_ID = out.split('/knowledgeBases/')[1].split('\n')[0] |
This file contains hidden or 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,69 @@ | ||
# Copyright 2020 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 | ||
# | ||
# http://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 __future__ import absolute_import | ||
|
||
import datetime | ||
import os | ||
|
||
import dialogflow_v2beta1 as dialogflow | ||
import pytest | ||
|
||
import document_management | ||
|
||
PROJECT_ID = os.getenv('GCLOUD_PROJECT') | ||
KNOWLEDGE_BASE_NAME = 'knowledge_' \ | ||
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S") | ||
DOCUMENT_DISPLAY_NAME = 'test_document_' \ | ||
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S") | ||
pytest.KNOWLEDGE_BASE_ID = None | ||
pytest.DOCUMENT_ID = None | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def setup_teardown(): | ||
# Create a knowledge base to use in document management | ||
client = dialogflow.KnowledgeBasesClient() | ||
project_path = client.project_path(PROJECT_ID) | ||
knowledge_base = dialogflow.types.KnowledgeBase( | ||
display_name=KNOWLEDGE_BASE_NAME) | ||
response = client.create_knowledge_base(project_path, knowledge_base) | ||
pytest.KNOWLEDGE_BASE_ID = response.name.split( | ||
'/knowledgeBases/')[1].split('\n')[0] | ||
|
||
# Create a document to delete | ||
knowledge_base_path = client.knowledge_base_path( | ||
PROJECT_ID, pytest.KNOWLEDGE_BASE_ID) | ||
document = dialogflow.types.Document( | ||
display_name=DOCUMENT_DISPLAY_NAME, mime_type='text/html', | ||
content_uri='https://cloud.google.com/storage/docs/faq') | ||
document.knowledge_types.append( | ||
dialogflow.types.Document.KnowledgeType.Value('FAQ')) | ||
documents_client = dialogflow.DocumentsClient() | ||
response = documents_client.create_document(knowledge_base_path, document) | ||
document = response.result(timeout=90) | ||
pytest.DOCUMENT_ID = document.name.split('/documents/')[1].split('\n')[0] | ||
|
||
yield | ||
|
||
# Delete the created knowledge base | ||
client.delete_knowledge_base(knowledge_base_path, force=True) | ||
|
||
|
||
def test_delete_document(capsys): | ||
document_management.delete_document( | ||
PROJECT_ID, pytest.KNOWLEDGE_BASE_ID, pytest.DOCUMENT_ID) | ||
document_management.list_documents(PROJECT_ID, pytest.KNOWLEDGE_BASE_ID) | ||
out, _ = capsys.readouterr() | ||
assert DOCUMENT_DISPLAY_NAME not in out |
This file contains hidden or 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,48 @@ | ||
# Copyright 2020 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 | ||
# | ||
# http://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 __future__ import absolute_import | ||
|
||
import datetime | ||
import os | ||
|
||
import dialogflow_v2beta1 as dialogflow | ||
import pytest | ||
|
||
import knowledge_base_management | ||
|
||
PROJECT_ID = os.getenv('GCLOUD_PROJECT') | ||
KNOWLEDGE_BASE_NAME = 'knowledge_' \ | ||
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S") | ||
pytest.KNOWLEDGE_BASE_ID = None | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def setup(): | ||
# Create a knowledge base to delete | ||
client = dialogflow.KnowledgeBasesClient() | ||
project_path = client.project_path(PROJECT_ID) | ||
knowledge_base = dialogflow.types.KnowledgeBase( | ||
display_name=KNOWLEDGE_BASE_NAME) | ||
response = client.create_knowledge_base(project_path, knowledge_base) | ||
pytest.KNOWLEDGE_BASE_ID = response.name.split( | ||
'/knowledgeBases/')[1].split('\n')[0] | ||
|
||
|
||
def test_delete_knowledge_base(capsys): | ||
knowledge_base_management.delete_knowledge_base( | ||
PROJECT_ID, pytest.KNOWLEDGE_BASE_ID) | ||
knowledge_base_management.list_knowledge_bases(PROJECT_ID) | ||
out, _ = capsys.readouterr() | ||
assert KNOWLEDGE_BASE_NAME not in out |
This file contains hidden or 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
This file contains hidden or 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,33 @@ | ||
# Copyright 2020 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 | ||
# | ||
# http://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 __future__ import absolute_import | ||
|
||
import datetime | ||
import os | ||
|
||
import detect_intent_knowledge | ||
|
||
PROJECT_ID = os.getenv('GCLOUD_PROJECT') | ||
SESSION_ID = 'session_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S") | ||
KNOWLEDGE_BASE_ID = 'MjEwMjE4MDQ3MDQwMDc0NTQ3Mg' | ||
TEXTS = ['Where is my data stored?'] | ||
|
||
|
||
def test_detect_intent_knowledge(capsys): | ||
detect_intent_knowledge.detect_intent_knowledge( | ||
PROJECT_ID, SESSION_ID, 'en-us', KNOWLEDGE_BASE_ID, TEXTS) | ||
|
||
out, _ = capsys.readouterr() | ||
assert 'Knowledge results' in out |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gguuss, while I wait for the quota increase.
How do you feel about these types of tests?
I was gonna modify the rest and separate them into individual files in different PRs, but the current Knowledge and Document tests were checking that only 1 thing existing, so I at least had to update those for the 4 python versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine for checking that all the response parameters are there but adding more detailed checks, particularly in ML APIs, can make the checks more brittle. If these are mocks, then it diverges a bit from the spirit of doing integration testing to make sure we see whether our p;roducts are encountering outages or the client libraries are breaking.