Skip to content

Commit ec30b6a

Browse files
author
Takashi Matsuo
authored
[healthcare] fix: create/delete the Pub/Sub topic (GoogleCloudPlatform#3758)
fixes GoogleCloudPlatform#3756 fixes GoogleCloudPlatform#3757
1 parent b4a6570 commit ec30b6a

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

healthcare/api-client/dicom/dicom_stores_test.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
import os
1616
import sys
17-
import time
17+
import uuid
1818

19+
from google.cloud import pubsub_v1
1920
import pytest
2021

2122
# Add datasets for bootstrapping datasets for testing
@@ -28,9 +29,9 @@
2829
project_id = os.environ['GOOGLE_CLOUD_PROJECT']
2930
service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS']
3031

31-
dataset_id = 'test_dataset-{}'.format(int(time.time()))
32-
dicom_store_id = 'test_dicom_store_{}'.format(int(time.time()))
33-
pubsub_topic = 'test_pubsub_topic_{}'.format(int(time.time()))
32+
dataset_id = 'test_dataset-{}'.format(uuid.uuid4())
33+
dicom_store_id = 'test_dicom_store_{}'.format(uuid.uuid4())
34+
pubsub_topic = 'test_pubsub_topic_{}'.format(uuid.uuid4())
3435

3536
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
3637
bucket = os.environ['CLOUD_STORAGE_BUCKET']
@@ -57,6 +58,19 @@ def test_dataset():
5758
dataset_id)
5859

5960

61+
@pytest.fixture(scope='module')
62+
def test_pubsub_topic():
63+
# Create the Pub/Sub topic
64+
pubsub_client = pubsub_v1.PublisherClient()
65+
topic_path = pubsub_client.topic_path(project_id, pubsub_topic)
66+
pubsub_client.create_topic(topic_path)
67+
68+
yield pubsub_topic
69+
70+
# Delete the Pub/Sub topic
71+
pubsub_client.delete_topic(topic_path)
72+
73+
6074
def test_CRUD_dicom_store(test_dataset, capsys):
6175
dicom_stores.create_dicom_store(
6276
service_account_json,
@@ -94,7 +108,7 @@ def test_CRUD_dicom_store(test_dataset, capsys):
94108
assert 'Deleted DICOM store' in out
95109

96110

97-
def test_patch_dicom_store(test_dataset, capsys):
111+
def test_patch_dicom_store(test_dataset, test_pubsub_topic, capsys):
98112
dicom_stores.create_dicom_store(
99113
service_account_json,
100114
project_id,
@@ -108,7 +122,7 @@ def test_patch_dicom_store(test_dataset, capsys):
108122
cloud_region,
109123
dataset_id,
110124
dicom_store_id,
111-
pubsub_topic)
125+
test_pubsub_topic)
112126

113127
# Clean up
114128
dicom_stores.delete_dicom_store(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
google-api-python-client==1.8.2
22
google-auth-httplib2==0.0.3
33
google-auth==1.14.3
4-
google-cloud==0.34.0
4+
google-cloud-pubsub==1.4.3
55
requests==2.23.0

healthcare/api-client/v1/dicom/dicom_stores_test.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import uuid
1818

1919
import backoff
20+
from google.cloud import pubsub_v1
2021
from googleapiclient.errors import HttpError
2122
import pytest
2223

@@ -151,6 +152,19 @@ def clean_up():
151152
clean_up()
152153

153154

155+
@pytest.fixture(scope='module')
156+
def test_pubsub_topic():
157+
pubsub_client = pubsub_v1.PublisherClient()
158+
# Create the Pub/Sub topic
159+
topic_path = pubsub_client.topic_path(project_id, pubsub_topic)
160+
pubsub_client.create_topic(topic_path)
161+
162+
yield pubsub_topic
163+
164+
# Delete the Pub/Sub topic
165+
pubsub_client.delete_topic(topic_path)
166+
167+
154168
def test_CRUD_dicom_store(test_dataset, crud_dicom_store_id, capsys):
155169
dicom_stores.create_dicom_store(
156170
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):
175189
assert "Deleted DICOM store" in out
176190

177191

178-
def test_patch_dicom_store(test_dataset, test_dicom_store, capsys):
192+
def test_patch_dicom_store(
193+
test_dataset, test_dicom_store, test_pubsub_topic, capsys):
179194
dicom_stores.patch_dicom_store(
180-
project_id, cloud_region, dataset_id, dicom_store_id, pubsub_topic
195+
project_id, cloud_region, dataset_id, dicom_store_id, test_pubsub_topic
181196
)
182197

183198
out, _ = capsys.readouterr()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
google-api-python-client==1.8.2
22
google-auth-httplib2==0.0.3
33
google-auth==1.14.3
4-
google-cloud==0.34.0
4+
google-cloud-pubsub==1.4.3
55
requests==2.23.0

0 commit comments

Comments
 (0)