Example #1
0
def test_source_api_call(spark_session: SparkSession) -> None:
    test_path: Path = Path(__file__).parent.joinpath("./")
    test_name = "test_source_api_call"

    mock_server_url = "http://mock-server:1080"
    mock_client = MockServerFriendlyClient(mock_server_url)
    mock_client.clear(test_name)

    input_file = input_types.FileInput()
    request = input_types.ApiJsonResponse(
        response_data_folder="api_json_response")
    logger = get_logger(__name__)
    SparkPipelineFrameworkTestRunnerV2(
        spark_session=spark_session,
        test_path=test_path,
        test_name=test_name,
        test_validators=None,
        logger=logger,
        auto_find_helix_transformer=False,
        helix_transformers=[FeaturesComplexFeature],
        mock_client=mock_client,
        test_inputs=[input_file, request],
        temp_folder="output/temp",
    ).run_test2()

    with open(test_path.joinpath(
            "api_json_response/getProviderApptTypes.json")) as f:
        content = json.load(f)

    response: Response = requests.get(
        f"{mock_server_url}/{test_name}/getProviderApptTypes")
    assert response.json() == content
Example #2
0
def test_mock_fhir_graph_request(spark_session: SparkSession) -> None:
    """
    expect 2 $graph calls to be made to get Organization data
    """
    test_path: Path = Path(__file__).parent.joinpath("./")
    test_name = "test_mock_fhir_graph_request"

    mock_server_url = "http://mock-server:1080"
    mock_client = MockServerFriendlyClient(mock_server_url)
    mock_client.clear(f"/{test_name}/")

    fhir_calls = MockRequestResponseCalls(
        fhir_calls_folder=f"{test_path}/mock_request_responses/Organization",
        mock_url_prefix=f"{test_name}/4_0_0/Organization",
        url_suffix="$graph",
    )
    test_validators = MockCallValidator(related_inputs=fhir_calls)
    params = {
        "test_name":
        test_name,
        "mock_server_url":
        mock_server_url,
        "url_fhir_segments":
        "Organization/$graph",
        "files_path": [
            test_path.joinpath(
                "mock_request_responses/Organization/1023011178.json"),
            test_path.joinpath(
                "mock_request_responses/Organization/1841293990.json"),
        ],
    }

    logger = get_logger(__name__)
    SparkPipelineFrameworkTestRunnerV2(
        spark_session=spark_session,
        test_path=test_path,
        test_name=test_name,
        logger=logger,
        auto_find_helix_transformer=False,
        helix_transformers=[PipelineMockRequestResponsesV1],
        mock_client=mock_client,
        test_validators=[test_validators],
        test_inputs=[fhir_calls],
        temp_folder="temp",
        helix_pipeline_parameters=params,
    ).run_test2()
def test_practitioner_fail_on_fhir_validation(spark_session: SparkSession) -> None:
    test_path: Path = Path(__file__).parent.joinpath("./")

    # setup servers
    test_name = "practitioner_fail_on_fhir_validation"

    test_input = FileInput()
    test_fhir = FhirCalls()

    logger = get_logger(__name__)

    mock_server_url = "http://mock-server:1080"
    mock_client = MockServerFriendlyClient(mock_server_url)
    mock_client.clear(f"/{test_name}/")
    mock_client.expect_default()

    params = {
        "test_name": test_name,
        "mock_server_url": mock_server_url,
    }

    test_validator = FhirValidator(
        related_inputs=test_fhir,
        related_file_inputs=test_input,
        mock_server_url=mock_server_url,
        test_name=test_name,
        fhir_validation_url="http://fhir:3000/4_0_0",
    )

    with pytest.raises(AssertionError, match=r"Failed validation for resource*"):
        SparkPipelineFrameworkTestRunnerV2(
            spark_session=spark_session,
            test_path=test_path,
            test_name=test_name,
            test_validators=[test_validator],
            logger=logger,
            auto_find_helix_transformer=False,
            helix_transformers=[
                FeaturesDoctorFeaturePractitionerFailOnFhirValidationV1
            ],
            test_inputs=[test_input],
            temp_folder="output/temp",
            helix_pipeline_parameters=params,
        ).run_test2()
def test_doctor_feature_practitioner(spark_session: SparkSession) -> None:
    data_dir: Path = Path(__file__).parent.joinpath("./")
    test_name = "test_doctor_feature_practitioner"
    test_input = input_types.FileInput()
    test_fhir = input_types.FhirCalls()

    logger = get_logger(__name__)

    mock_server_url = "http://mock-server:1080"
    mock_client = MockServerFriendlyClient(mock_server_url)
    mock_client.clear(f"/{test_name}/")
    mock_client.expect_default()

    params = {
        "test_name": test_name,
        "mock_server_url": mock_server_url,
    }

    test_validator = FhirValidator(
        related_inputs=test_fhir,
        related_file_inputs=test_input,
        mock_server_url=mock_server_url,
        test_name=test_name,
        fhir_validation_url="http://fhir:3000/4_0_0",
    )

    SparkPipelineFrameworkTestRunnerV2(
        spark_session=spark_session,
        test_path=data_dir,
        test_name=test_name,
        test_validators=[
            test_validator,
            # OutputFileValidator(related_inputs=test_input, sort_output_by=["id"]),
        ],
        logger=logger,
        test_inputs=[test_input],
        temp_folder="output/temp",
        mock_client=mock_client,
        helix_pipeline_parameters=params,
    ).run_test2()
Example #5
0
def test_fhir_mock(spark_session: SparkSession) -> None:
    test_path: Path = Path(__file__).parent.joinpath("./")
    test_name = "test_fhir_mock"

    mock_server_url = "http://mock-server:1080"
    mock_client = MockServerFriendlyClient(mock_server_url)
    mock_client.clear(f"/{test_name}/")

    fhir_calls = FhirCalls()
    test_validators = MockCallValidator(related_inputs=fhir_calls)
    params = {
        "test_name":
        test_name,
        "mock_server_url":
        mock_server_url,
        "files_path": [
            test_path.joinpath(
                "fhir_calls/healthcare_service/1629334859-TT3-GPPC.json"),
            test_path.joinpath(
                "fhir_calls/healthcare_service/1790914448-TT4-GPPC.json"),
            test_path.joinpath(
                "fhir_calls/location/Medstar-Alias-TT3-GPPC.json"),
            test_path.joinpath(
                "fhir_calls/location/Medstar-Alias-TT4-GPPC.json"),
        ],
    }
    logger = get_logger(__name__)
    SparkPipelineFrameworkTestRunnerV2(
        spark_session=spark_session,
        test_path=test_path,
        test_name=test_name,
        test_validators=[test_validators],
        logger=logger,
        auto_find_helix_transformer=False,
        helix_transformers=[PipelineFhirCallsFhirMockV1],
        mock_client=mock_client,
        test_inputs=[fhir_calls],
        temp_folder="temp",
        helix_pipeline_parameters=params,
    ).run_test2()