Ejemplo n.º 1
0
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
def test_get_set_fhir_store_iam_policy(test_dataset, capsys):
    fhir_stores.create_fhir_store(service_account_json, api_key, project_id,
                                  cloud_region, dataset_id, fhir_store_id)

    get_response = fhir_stores.get_fhir_store_iam_policy(
        service_account_json, api_key, project_id, cloud_region, dataset_id,
        fhir_store_id)

    set_response = fhir_stores.set_fhir_store_iam_policy(
        service_account_json, api_key, project_id, cloud_region, dataset_id,
        fhir_store_id,
        'serviceAccount:[email protected]',
        'roles/viewer')

    # 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 'etag' in get_response
    assert 'bindings' in set_response
    assert len(set_response['bindings']) == 1
    assert 'python-docs-samples-tests' in str(set_response['bindings'])
    assert 'roles/viewer' in str(set_response['bindings'])
Ejemplo n.º 3
0
def test_patch_fhir_store(test_dataset, capsys):
    fhir_stores.create_fhir_store(
        service_account_json,
        api_key,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)

    fhir_stores.patch_fhir_store(
        service_account_json,
        api_key,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        pubsub_topic)

    # 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 'Patched FHIR store' in out
def test_CRUD_fhir_store(test_dataset, capsys):
    fhir_stores.create_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)

    fhir_stores.get_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)

    fhir_stores.list_fhir_stores(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id)

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

    out, _ = capsys.readouterr()

    # Check that create/get/list/delete worked
    assert 'Created FHIR store' in out
    assert 'Name' in out
    assert 'fhirStores' in out
    assert 'Deleted FHIR store' in out
def test_import_fhir_store_gcs(test_dataset, capsys):
    fhir_stores.create_fhir_store(service_account_json, 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)

    time.sleep(10)  # Give new blob time to propagate
    fhir_stores.import_fhir_resources(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        import_object,
    )

    # Clean up
    blob.delete()

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

    out, _ = capsys.readouterr()

    assert "Imported FHIR resources" in out
def test_patch_fhir_store(test_dataset, capsys):
    fhir_stores.create_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)

    fhir_stores.patch_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)

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

    out, _ = capsys.readouterr()

    assert 'Patched FHIR store' in out
Ejemplo n.º 7
0
def test_get_set_fhir_store_iam_policy(test_dataset, capsys):
    fhir_stores.create_fhir_store(service_account_json, project_id,
                                  cloud_region, dataset_id, fhir_store_id)

    get_response = fhir_stores.get_fhir_store_iam_policy(
        service_account_json, project_id, cloud_region, dataset_id,
        fhir_store_id)

    set_response = fhir_stores.set_fhir_store_iam_policy(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        "serviceAccount:[email protected]",
        "roles/viewer",
    )

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

    out, _ = capsys.readouterr()

    assert "etag" in get_response
    assert "bindings" in set_response
    assert len(set_response["bindings"]) == 1
    assert "python-docs-samples-tests" in str(set_response["bindings"])
    assert "roles/viewer" in str(set_response["bindings"])
def test_export_fhir_store_gcs(test_dataset, capsys):
    fhir_stores.create_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)

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

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

    out, _ = capsys.readouterr()

    assert 'Exported FHIR resources to bucket' in out
Ejemplo n.º 9
0
def test_import_fhir_store_gcs(test_dataset, capsys):
    fhir_stores.create_fhir_store(service_account_json, 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)

    time.sleep(10)  # Give new blob time to propagate
    fhir_stores.import_fhir_resources(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        import_object,
    )

    # Clean up
    try:
        blob.delete()
    # If blob not found, then it's already been deleted, so no need to clean up.
    except exceptions.NotFound:
        pass

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

    out, _ = capsys.readouterr()

    assert "Imported FHIR resources" in out
Ejemplo n.º 10
0
def test_fhir_store():
    fhir_store = fhir_stores.create_fhir_store(service_account_json,
                                               project_id, cloud_region,
                                               dataset_id, fhir_store_id)

    yield fhir_store

    fhir_stores.delete_fhir_store(service_account_json, project_id,
                                  cloud_region, dataset_id, fhir_store_id)
Ejemplo n.º 11
0
def test_create_delete_fhir_store(test_dataset, capsys):
    fhir_stores.create_fhir_store(service_account_json, project_id,
                                  cloud_region, dataset_id, fhir_store_id)

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

    out, _ = capsys.readouterr()

    # Check that create/get/list/delete worked
    assert "Created FHIR store" in out
    assert "Deleted FHIR store" in out
Ejemplo n.º 12
0
 def clean_up():
     try:
         fhir_stores.delete_fhir_store(project_id, cloud_region, dataset_id,
                                       fhir_store_id)
     except HttpError as err:
         # The API returns 404 when the FHIR store doesn't exist.
         # The API returns 403 when the dataset doesn't exist, so
         # if we try to delete a FHIR store when the parent dataset
         # doesn't exist, the server will return a 403.
         if err.resp.status == 404 or err.resp.status == 403:
             print("Got exception {} while deleting FHIR store".format(
                 err.resp.status))
         else:
             raise
Ejemplo n.º 13
0
def test_crud_fhir_store(test_dataset, capsys):
    fhir_stores.create_fhir_store(project_id, cloud_region, dataset_id, fhir_store_id)

    fhir_stores.get_fhir_store(project_id, cloud_region, dataset_id, fhir_store_id)

    fhir_stores.list_fhir_stores(project_id, cloud_region, dataset_id)

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

    out, _ = capsys.readouterr()

    # Check that create/get/list/delete worked
    assert "Created FHIR store" in out
    assert "name" in out
    assert "fhirStores" in out
    assert "Deleted FHIR store" in out
def test_fhir_store():
    fhir_store = fhir_stores.create_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)

    yield fhir_store

    fhir_stores.delete_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)
Ejemplo n.º 15
0
def test_fhir_store():
    # We see HttpErrors with "dataset not initialized" message.
    # I think retry will mitigate the flake.
    @backoff.on_exception(backoff.expo, HTTPError, max_time=BACKOFF_MAX_TIME)
    def create_fhir_store():
        return fhir_stores.create_fhir_store(
            service_account_json, project_id, cloud_region, dataset_id, fhir_store_id
        )
    fhir_store = create_fhir_store()

    yield fhir_store

    # Clean up
    fhir_stores.delete_fhir_store(
        service_account_json, project_id, cloud_region, dataset_id, fhir_store_id
    )
Ejemplo n.º 16
0
def test_create_delete_fhir_store(test_dataset, capsys):
    # We see HttpErrors with "dataset not initialized" message.
    # I think retry will mitigate the flake.
    @backoff.on_exception(backoff.expo, HTTPError, max_time=BACKOFF_MAX_TIME)
    def create():
        fhir_stores.create_fhir_store(service_account_json, project_id,
                                      cloud_region, dataset_id, fhir_store_id)

    create()

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

    out, _ = capsys.readouterr()

    # Check that create/get/list/delete worked
    assert "Created FHIR store" in out
    assert "Deleted FHIR store" in out
Ejemplo n.º 17
0
def test_CRUD_fhir_store(test_dataset, capsys):
    fhir_stores.create_fhir_store(service_account_json, project_id,
                                  cloud_region, dataset_id, fhir_store_id)

    fhir_stores.get_fhir_store(service_account_json, project_id, cloud_region,
                               dataset_id, fhir_store_id)

    fhir_stores.list_fhir_stores(service_account_json, project_id,
                                 cloud_region, dataset_id)

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

    out, _ = capsys.readouterr()

    # Check that create/get/list/delete worked
    assert 'Created FHIR store' in out
    assert 'Name' in out
    assert 'fhirStores' in out
    assert 'Deleted FHIR store' in out
def test_get_set_fhir_store_iam_policy(test_dataset, capsys):
    fhir_stores.create_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)

    get_response = fhir_stores.get_fhir_store_iam_policy(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id)

    set_response = fhir_stores.set_fhir_store_iam_policy(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        'serviceAccount:[email protected]',
        'roles/viewer')

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

    out, _ = capsys.readouterr()

    assert 'etag' in get_response
    assert 'bindings' in set_response
    assert len(set_response['bindings']) == 1
    assert 'python-docs-samples-tests' in str(set_response['bindings'])
    assert 'roles/viewer' in str(set_response['bindings'])
Ejemplo n.º 19
0
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 _delete():
     fhir_stores.delete_fhir_store(project_id, location, dataset_id,
                                   fhir_store_id)
Ejemplo n.º 21
0
 def _delete():
     fhir_stores.delete_fhir_store(project_id, cloud_region, dataset_id,
                                   fhir_store_id)