Exemplo n.º 1
0
def test_chanjo_api_sample_existing(chanjo_config_dict, mocker, mock_process):
    """Test sample method"""

    # GIVEN a sample_id
    sample_id = "sample_id"

    # WHEN fetching an existing sample from the api, with a mocked stdout
    mocked_stdout = '[{"id": "%s"}]' % sample_id
    mocked_stderr = ""
    MockedProcess = mock_process(result_stderr=mocked_stderr,
                                 result_stdout=mocked_stdout)
    mocked_process = mocker.patch("cg.apps.coverage.api.Process")
    mocked_process.return_value = MockedProcess(
        binary=chanjo_config_dict["chanjo"]["binary_path"],
        config=chanjo_config_dict["chanjo"]["config_path"],
    )
    api = ChanjoAPI(chanjo_config_dict)
    sample = api.sample(sample_id=sample_id)

    # THEN sample should be a dictionary with key id = sample_id
    assert sample["id"] == sample_id
Exemplo n.º 2
0
def test_chanjo_api_sample_non_existing(chanjo_config_dict, mocker,
                                        mock_process):
    """Test sample method"""

    # GIVEN a sample_id
    sample_id = "sample_id"

    # WHEN fetching a non existing sample from the api, with a mocked stdout
    mocked_stdout = "[]"
    mocked_stderr = ""
    MockedProcess = mock_process(result_stderr=mocked_stderr,
                                 result_stdout=mocked_stdout)
    mocked_process = mocker.patch("cg.apps.coverage.api.Process")
    mocked_process.return_value = MockedProcess(
        binary=chanjo_config_dict["chanjo"]["binary_path"],
        config=chanjo_config_dict["chanjo"]["config_path"],
    )
    api = ChanjoAPI(chanjo_config_dict)
    sample = api.sample(sample_id=sample_id)

    # THEN None should have been returned
    assert sample is None