diff --git a/healthcare/api-client/dicom/dicom_stores_test.py b/healthcare/api-client/dicom/dicom_stores_test.py index c9b4465f7608..df3688fd0c7b 100644 --- a/healthcare/api-client/dicom/dicom_stores_test.py +++ b/healthcare/api-client/dicom/dicom_stores_test.py @@ -14,8 +14,9 @@ import os import sys -import time +import uuid +from google.cloud import pubsub_v1 import pytest # Add datasets for bootstrapping datasets for testing @@ -28,9 +29,9 @@ project_id = os.environ['GOOGLE_CLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] -dataset_id = 'test_dataset-{}'.format(int(time.time())) -dicom_store_id = 'test_dicom_store_{}'.format(int(time.time())) -pubsub_topic = 'test_pubsub_topic_{}'.format(int(time.time())) +dataset_id = 'test_dataset-{}'.format(uuid.uuid4()) +dicom_store_id = 'test_dicom_store_{}'.format(uuid.uuid4()) +pubsub_topic = 'test_pubsub_topic_{}'.format(uuid.uuid4()) RESOURCES = os.path.join(os.path.dirname(__file__), 'resources') bucket = os.environ['CLOUD_STORAGE_BUCKET'] @@ -57,6 +58,19 @@ def test_dataset(): dataset_id) +@pytest.fixture(scope='module') +def test_pubsub_topic(): + # Create the Pub/Sub topic + pubsub_client = pubsub_v1.PublisherClient() + topic_path = pubsub_client.topic_path(project_id, pubsub_topic) + pubsub_client.create_topic(topic_path) + + yield pubsub_topic + + # Delete the Pub/Sub topic + pubsub_client.delete_topic(topic_path) + + def test_CRUD_dicom_store(test_dataset, capsys): dicom_stores.create_dicom_store( service_account_json, @@ -94,7 +108,7 @@ def test_CRUD_dicom_store(test_dataset, capsys): assert 'Deleted DICOM store' in out -def test_patch_dicom_store(test_dataset, capsys): +def test_patch_dicom_store(test_dataset, test_pubsub_topic, capsys): dicom_stores.create_dicom_store( service_account_json, project_id, @@ -108,7 +122,7 @@ def test_patch_dicom_store(test_dataset, capsys): cloud_region, dataset_id, dicom_store_id, - pubsub_topic) + test_pubsub_topic) # Clean up dicom_stores.delete_dicom_store( diff --git a/healthcare/api-client/dicom/requirements.txt b/healthcare/api-client/dicom/requirements.txt index 959f5ef412d6..2e225a3b186f 100644 --- a/healthcare/api-client/dicom/requirements.txt +++ b/healthcare/api-client/dicom/requirements.txt @@ -1,5 +1,5 @@ google-api-python-client==1.8.2 google-auth-httplib2==0.0.3 google-auth==1.14.3 -google-cloud==0.34.0 +google-cloud-pubsub==1.4.3 requests==2.23.0 diff --git a/healthcare/api-client/v1/dicom/dicom_stores_test.py b/healthcare/api-client/v1/dicom/dicom_stores_test.py index dc45da9fb79b..332f6f17048d 100644 --- a/healthcare/api-client/v1/dicom/dicom_stores_test.py +++ b/healthcare/api-client/v1/dicom/dicom_stores_test.py @@ -17,6 +17,7 @@ import uuid import backoff +from google.cloud import pubsub_v1 from googleapiclient.errors import HttpError import pytest @@ -151,6 +152,19 @@ def clean_up(): clean_up() +@pytest.fixture(scope='module') +def test_pubsub_topic(): + pubsub_client = pubsub_v1.PublisherClient() + # Create the Pub/Sub topic + topic_path = pubsub_client.topic_path(project_id, pubsub_topic) + pubsub_client.create_topic(topic_path) + + yield pubsub_topic + + # Delete the Pub/Sub topic + pubsub_client.delete_topic(topic_path) + + def test_CRUD_dicom_store(test_dataset, crud_dicom_store_id, capsys): dicom_stores.create_dicom_store( project_id, cloud_region, dataset_id, crud_dicom_store_id @@ -175,9 +189,10 @@ def test_CRUD_dicom_store(test_dataset, crud_dicom_store_id, capsys): assert "Deleted DICOM store" in out -def test_patch_dicom_store(test_dataset, test_dicom_store, capsys): +def test_patch_dicom_store( + test_dataset, test_dicom_store, test_pubsub_topic, capsys): dicom_stores.patch_dicom_store( - project_id, cloud_region, dataset_id, dicom_store_id, pubsub_topic + project_id, cloud_region, dataset_id, dicom_store_id, test_pubsub_topic ) out, _ = capsys.readouterr() diff --git a/healthcare/api-client/v1/dicom/requirements.txt b/healthcare/api-client/v1/dicom/requirements.txt index 959f5ef412d6..2e225a3b186f 100644 --- a/healthcare/api-client/v1/dicom/requirements.txt +++ b/healthcare/api-client/v1/dicom/requirements.txt @@ -1,5 +1,5 @@ google-api-python-client==1.8.2 google-auth-httplib2==0.0.3 google-auth==1.14.3 -google-cloud==0.34.0 +google-cloud-pubsub==1.4.3 requests==2.23.0