Skip to content
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

[healthcare] fix: create/delete the Pub/Sub topic #3758

Merged
merged 2 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions healthcare/api-client/dicom/dicom_stores_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion healthcare/api-client/dicom/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
19 changes: 17 additions & 2 deletions healthcare/api-client/v1/dicom/dicom_stores_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import uuid

import backoff
from google.cloud import pubsub_v1
from googleapiclient.errors import HttpError
import pytest

Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion healthcare/api-client/v1/dicom/requirements.txt
Original file line number Diff line number Diff line change
@@ -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