def test_resource_versions(test_dataset, test_fhir_store, test_patient,
                           capsys):
    # We have to update the resource so that different versions of it are
    # created, then we test to see if we can get/delete those versions.
    fhir_resources.update_resource(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        test_patient,
    )

    history = fhir_resources.list_resource_history(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        test_patient,
    )

    fhir_resources.get_resource_history(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        test_patient,
        history["entry"][-1]["resource"]["meta"]["versionId"],
    )

    fhir_resources.delete_resource_purge(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        test_patient,
    )

    out, _ = capsys.readouterr()

    print(out)

    # list_resource_history test
    assert "History for Patient resource" in out
    # get_resource_history test
    assert "Got history for Patient resource" in out
    # delete_resource_purge test
    assert "Deleted versions of Patient resource" in out
def test_CRUD_search_resource(test_dataset, test_fhir_store, capsys):
    response = fhir_resources.create_resource(service_account_json, base_url,
                                              project_id, cloud_region,
                                              dataset_id, fhir_store_id,
                                              resource_type)

    # Save the resource_id because you need to pass it into later tests
    resource_id = response.json()['id']

    fhir_resources.search_resources_get(service_account_json, base_url,
                                        project_id, cloud_region, dataset_id,
                                        fhir_store_id, resource_type)

    fhir_resources.get_resource(service_account_json, base_url, project_id,
                                cloud_region, dataset_id, fhir_store_id,
                                resource_type, resource_id)

    fhir_resources.update_resource(service_account_json, base_url, project_id,
                                   cloud_region, dataset_id, fhir_store_id,
                                   resource_type, resource_id)

    fhir_resources.conditional_update_resource(service_account_json, base_url,
                                               project_id, cloud_region,
                                               dataset_id, fhir_store_id,
                                               resource_type, resource_id)

    fhir_resources.patch_resource(service_account_json, base_url, project_id,
                                  cloud_region, dataset_id, fhir_store_id,
                                  resource_type, resource_id)

    fhir_resources.conditional_patch_resource(service_account_json, base_url,
                                              project_id, cloud_region,
                                              dataset_id, fhir_store_id,
                                              resource_type, resource_id)

    history = fhir_resources.list_resource_history(service_account_json,
                                                   base_url, project_id,
                                                   cloud_region, dataset_id,
                                                   fhir_store_id,
                                                   resource_type, resource_id)

    fhir_resources.get_resource_history(
        service_account_json, base_url, project_id, cloud_region, dataset_id,
        fhir_store_id, resource_type, resource_id,
        history['entry'][-1]['resource']['meta']['versionId'])

    fhir_resources.delete_resource_purge(service_account_json, base_url,
                                         project_id, cloud_region, dataset_id,
                                         fhir_store_id, resource_type,
                                         resource_id)

    fhir_resources.conditional_delete_resource(service_account_json, base_url,
                                               project_id, cloud_region,
                                               dataset_id, fhir_store_id,
                                               resource_type, resource_id)

    fhir_resources.delete_resource(service_account_json, base_url, project_id,
                                   cloud_region, dataset_id, fhir_store_id,
                                   resource_type, resource_id)

    out, _ = capsys.readouterr()

    # Check that create/search worked
    assert 'Created Resource' in out
    assert 'id' in out
    assert 'Conditionally updated' in out
    assert 'search' in out
    assert 'link' in out
    assert ' deleted' in out
    assert resource_id in out
    assert 'Deleted Resource' in out
def test_CRUD_search_resource(test_dataset, test_fhir_store, capsys):
    response = fhir_resources.create_resource(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type)

    # Save the resource_id because you need to pass it into later tests
    resource_id = response.json()['id']

    fhir_resources.search_resources_get(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type)

    fhir_resources.get_resource(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id)

    fhir_resources.update_resource(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id)

    fhir_resources.conditional_update_resource(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id)

    fhir_resources.patch_resource(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id)

    fhir_resources.conditional_patch_resource(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id)

    history = fhir_resources.list_resource_history(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id)

    fhir_resources.get_resource_history(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id,
        history['entry'][-1]['resource']['meta']['versionId'])

    fhir_resources.delete_resource_purge(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id)

    fhir_resources.conditional_delete_resource(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id)

    fhir_resources.delete_resource(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id,
        resource_type,
        resource_id)

    out, _ = capsys.readouterr()

    # Check that create/search worked
    assert 'Created Resource' in out
    assert 'id' in out
    assert 'Conditionally updated' in out
    assert 'search' in out
    assert 'link' in out
    assert ' deleted' in out
    assert resource_id in out
    assert 'Deleted Resource' in out