Skip to content

Commit

Permalink
dialogflow: make flaky test more generic [(#2936)](GoogleCloudPlatfor…
Browse files Browse the repository at this point in the history
…m/python-docs-samples#2936)

* dialogflow: make flaky test more generic

* use uuid instead of datetime to avoid conflicts when parallel tests are run

Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
  • Loading branch information
nnegrey and busunkim96 committed Dec 9, 2020
1 parent 6dd655d commit 70e2f7e
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import context_management
import detect_intent_texts

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_session_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
CONTEXT_ID = 'test_context_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_session_{}'.format(uuid.uuid4())
CONTEXT_ID = 'test_context_{}'.format(uuid.uuid4())


def test_create_context(capsys):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@

from __future__ import absolute_import

import datetime
import os
import uuid

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")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
DOCUMENT_DISPLAY_NAME = 'test_document_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
DISPLAY_NAME = "entity_{}".format(uuid.uuid4()).replace('-', '')[:30]
ENTITY_VALUE_1 = "test_entity_value_1"
ENTITY_VALUE_2 = "test_entity_value_2"
SYNONYMS = ["fake_synonym_for_testing_1", "fake_synonym_for_testing_2"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_type_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_type_" + datetime.datetime.now().strftime(
"%Y%m%d%H%M%S"
)
DISPLAY_NAME = "entity_type_{}".format(uuid.uuid4()).replace('-', '')[:30]
pytest.ENTITY_TYPE_ID = None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
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")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@

from __future__ import absolute_import

import datetime
import os
import uuid

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")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
DOCUMENT_DISPLAY_NAME = 'test_document_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None
pytest.DOCUMENT_ID = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
DISPLAY_NAME = "entity_{}".format(uuid.uuid4()).replace('-', '')[:30]
ENTITY_VALUE_1 = "test_delete_entity_value"

pytest.ENTITY_TYPE_ID = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_type_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_type_" + datetime.datetime.now().strftime(
"%Y%m%d%H%M%S"
)
DISPLAY_NAME = "entity_type_{}".format(uuid.uuid4()).replace('-', '')[:30]
pytest.ENTITY_TYPE_ID = None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid

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")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_audio import detect_intent_audio

DIRNAME = os.path.realpath(os.path.dirname(__file__))
PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
AUDIOS = [
'{0}/resources/book_a_room.wav'.format(DIRNAME),
'{0}/resources/mountain_view.wav'.format(DIRNAME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import detect_intent_knowledge

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'session_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'session_{}'.format(uuid.uuid4())
KNOWLEDGE_BASE_ID = 'MjEwMjE4MDQ3MDQwMDc0NTQ3Mg'
TEXTS = ['Where is my data stored?']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_stream import detect_intent_stream

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
AUDIO_FILE_PATH = '{0}/resources/book_a_room.wav'.format(
os.path.realpath(os.path.dirname(__file__)),
)
Expand All @@ -29,5 +29,5 @@ def test_detect_intent_stream(capsys):
detect_intent_stream(PROJECT_ID, SESSION_ID, AUDIO_FILE_PATH, 'en-US')
out, _ = capsys.readouterr()

assert 'Intermediate transcript: "book"' in out
assert 'Fulfillment text: What time will the meeting start?' in out
assert 'Intermediate transcript:' in out
assert 'Fulfillment text:' in out
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_texts import detect_intent_texts

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
TEXTS = ["hello", "book a meeting room", "Mountain View",
"tomorrow", "10 AM", "2 hours", "10 people", "A", "yes"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_with_model_selection import \
detect_intent_with_model_selection

DIRNAME = os.path.realpath(os.path.dirname(__file__))
PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
AUDIOS = [
'{0}/resources/book_a_room.wav'.format(DIRNAME),
'{0}/resources/mountain_view.wav'.format(DIRNAME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_with_sentiment_analysis import \
detect_intent_with_sentiment_analysis

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
TEXTS = ["hello", "book a meeting room", "Mountain View",
"tomorrow", "10 AM", "2 hours", "10 people", "A", "yes"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_with_texttospeech_response import \
detect_intent_with_texttospeech_response

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
TEXTS = ["hello"]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid

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")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import intent_management

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
INTENT_DISPLAY_NAME = 'test_' \
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
INTENT_DISPLAY_NAME = 'test_{}'.format(uuid.uuid4())
MESSAGE_TEXTS = [
'fake_message_text_for_testing_1',
'fake_message_text_for_testing_2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
DISPLAY_NAME = "entity_{}".format(uuid.uuid4()).replace('-', '')[:30]
ENTITY_VALUE_1 = "test_list_entity_value"

pytest.ENTITY_TYPE_ID = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_type_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_type_" + datetime.datetime.now().strftime(
"%Y%m%d%H%M%S"
)
DISPLAY_NAME = "entity_type_{}".format(uuid.uuid4()).replace('-', '')[:30]


@pytest.fixture(scope="function", autouse=True)
Expand Down
Loading

0 comments on commit 70e2f7e

Please sign in to comment.