Skip to content
Merged
Changes from all commits
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
81 changes: 80 additions & 1 deletion healthcare/api-client/fhir/fhir_stores_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import sys
import time

from google.cloud import storage

# Add datasets for bootstrapping datasets for testing
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'datasets')) # noqa
import datasets
Expand All @@ -30,7 +32,12 @@
dataset_id = 'test_dataset_{}'.format(int(time.time()))
fhir_store_id = 'test_fhir_store-{}'.format(int(time.time()))
pubsub_topic = 'test_pubsub_topic-{}'.format(int(time.time()))
resource_type = 'Patient'

gcs_uri = os.environ['CLOUD_STORAGE_BUCKET']
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
source_file_name = 'Patient.json'
resource_file = os.path.join(RESOURCES, source_file_name)
import_object = gcs_uri + '/' + source_file_name


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -126,3 +133,75 @@ def test_patch_fhir_store(test_dataset, capsys):
out, _ = capsys.readouterr()

assert 'Patched FHIR store' in out


def test_import_fhir_store_gcs(test_dataset, capsys):
fhir_stores.create_fhir_store(
service_account_json,
api_key,
project_id,
cloud_region,
dataset_id,
fhir_store_id)

storage_client = storage.Client()
bucket = storage_client.get_bucket(gcs_uri)
blob = bucket.blob(source_file_name)

blob.upload_from_filename(resource_file)

fhir_stores.import_fhir_store(
service_account_json,
api_key,
project_id,
cloud_region,
dataset_id,
fhir_store_id,
import_object)

# Clean up
blob.delete()

fhir_stores.delete_fhir_store(
service_account_json,
api_key,
project_id,
cloud_region,
dataset_id,
fhir_store_id)

out, _ = capsys.readouterr()

assert 'Imported FHIR resources' in out


def test_export_fhir_store_gcs(test_dataset, capsys):
fhir_stores.create_fhir_store(
service_account_json,
api_key,
project_id,
cloud_region,
dataset_id,
fhir_store_id)

fhir_stores.export_fhir_store_gcs(
service_account_json,
api_key,
project_id,
cloud_region,
dataset_id,
fhir_store_id,
gcs_uri)

# Clean up
fhir_stores.delete_fhir_store(
service_account_json,
api_key,
project_id,
cloud_region,
dataset_id,
fhir_store_id)

out, _ = capsys.readouterr()

assert 'Exported FHIR resources to bucket' in out