Skip to content

Commit

Permalink
[healthcare] fix: fix broken tests for healthcare API (#3253)
Browse files Browse the repository at this point in the history
* [healthcare] fix: fix broken tests for healthcare API

fixes #3120

* use uuid for the resource names

* add retries around list_messages calls
  • Loading branch information
Takashi Matsuo authored Apr 3, 2020
1 parent ff791ec commit f8a1d3f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 35 deletions.
2 changes: 1 addition & 1 deletion healthcare/api-client/hl7v2/hl7v2_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def list_hl7v2_messages(
hl7v2_messages_parent, hl7v2_store_id)

hl7v2_messages = client.projects().locations().datasets().hl7V2Stores(
).messages().list(parent=hl7v2_message_path).execute().get('messages', [])
).messages().list(parent=hl7v2_message_path).execute().get('hl7V2Messages', [])

for hl7v2_message in hl7v2_messages:
print(hl7v2_message)
Expand Down
78 changes: 47 additions & 31 deletions healthcare/api-client/hl7v2/hl7v2_messages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

import os
import pytest
import re
import sys
import time
import uuid

from gcp_devrel.testing import eventually_consistent

# Add datasets for bootstrapping datasets for testing
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'datasets')) # noqa
Expand All @@ -28,8 +29,8 @@
project_id = os.environ['GOOGLE_CLOUD_PROJECT']
service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS']

dataset_id = 'test_dataset_{}'.format(int(time.time()))
hl7v2_store_id = 'test_hl7v2_store-{}'.format(int(time.time()))
dataset_id = 'test_dataset_{}'.format(uuid.uuid4())
hl7v2_store_id = 'test_hl7v2_store-{}'.format(uuid.uuid4())
hl7v2_message_file = 'resources/hl7-sample-ingest.json'
label_key = 'PROCESSED'
label_value = 'TRUE'
Expand Down Expand Up @@ -81,15 +82,20 @@ def test_CRUD_hl7v2_message(test_dataset, test_hl7v2_store, capsys):
hl7v2_store_id,
hl7v2_message_file)

hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

hl7v2_messages_list_to_str = str(hl7v2_messages_list).split('/', 9)[9]
hl7v2_message_id = re.sub('\']', '', hl7v2_messages_list_to_str)
hl7v2_message_id = ""
@eventually_consistent.call
def _():
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

assert len(hl7v2_messages_list) > 0
hl7v2_message_name = hl7v2_messages_list[0].get('name')
nonlocal hl7v2_message_id
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]

hl7v2_messages.get_hl7v2_message(
service_account_json,
Expand Down Expand Up @@ -124,15 +130,20 @@ def test_ingest_hl7v2_message(test_dataset, test_hl7v2_store, capsys):
hl7v2_store_id,
hl7v2_message_file)

hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

hl7v2_messages_list_to_str = str(hl7v2_messages_list).split('/', 9)[9]
hl7v2_message_id = re.sub('\']', '', hl7v2_messages_list_to_str)
hl7v2_message_id = ""
@eventually_consistent.call
def _():
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

assert len(hl7v2_messages_list) > 0
hl7v2_message_name = hl7v2_messages_list[0].get('name')
nonlocal hl7v2_message_id
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]

hl7v2_messages.get_hl7v2_message(
service_account_json,
Expand Down Expand Up @@ -167,15 +178,20 @@ def test_patch_hl7v2_message(test_dataset, test_hl7v2_store, capsys):
hl7v2_store_id,
hl7v2_message_file)

hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

hl7v2_messages_list_to_str = str(hl7v2_messages_list).split('/', 9)[9]
hl7v2_message_id = re.sub('\']', '', hl7v2_messages_list_to_str)
hl7v2_message_id = ""
@eventually_consistent.call
def _():
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
service_account_json,
project_id,
cloud_region,
dataset_id,
hl7v2_store_id)

assert len(hl7v2_messages_list) > 0
hl7v2_message_name = hl7v2_messages_list[0].get('name')
nonlocal hl7v2_message_id
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]

hl7v2_messages.patch_hl7v2_message(
service_account_json,
Expand Down
6 changes: 3 additions & 3 deletions healthcare/api-client/hl7v2/hl7v2_stores_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import pytest
import sys
import time
import uuid

# Add datasets for bootstrapping datasets for testing
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'datasets')) # noqa
Expand All @@ -26,8 +26,8 @@
project_id = os.environ['GOOGLE_CLOUD_PROJECT']
service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS']

dataset_id = 'test_dataset_{}'.format(int(time.time()))
hl7v2_store_id = 'test_hl7v2_store-{}'.format(int(time.time()))
dataset_id = 'test_dataset_{}'.format(uuid.uuid4())
hl7v2_store_id = 'test_hl7v2_store-{}'.format(uuid.uuid4())


@pytest.fixture(scope='module')
Expand Down
2 changes: 2 additions & 0 deletions healthcare/api-client/hl7v2/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pytest==5.3.2
gcp-devrel-py-tools==0.0.15
google-cloud-core

0 comments on commit f8a1d3f

Please sign in to comment.