def test_get_merged_vcf__bad_project_id(mocker):
    """Test get merged file failure when non-uuid string is used as
    project id.
    """
    runner = CliRunner()

    mocked_login = mocker.patch.object(APIClient, "login", return_value=None)
    mocked_get_project = mocker.patch.object(
        APIClient,
        "get_project",
        return_value=Project(id=str(uuid4())),
    )

    res = runner.invoke(
        get_merged_vcf,
        [
            "1111111",
            "--email",
            "*****@*****.**",
            "--password",
            "123",
        ],
    )

    assert res.exit_code == 1
    mocked_login.assert_called_once()
    mocked_get_project.assert_not_called()
    assert "Project ID is not valid" in res.output
Exemple #2
0
def test_list_projects__with_unexpected_keys(mocker, credentials):
    """Test projects being outputed to the shell where webhook_url, roles and
    some randomly generated values are part of the response.
    """

    runner = CliRunner()
    mocked_get_projects = mocker.patch.object(
        APIClient,
        "list_projects",
        return_value=Projects(**MOCKED_PROJECTS_WITH_UNEXPECTED_KEYS),
    )
    mocked_get_pipeline_capabilities = mocker.patch.object(
        APIClient,
        "get_pipeline_capabilities",
        return_value=PipelineCapabilities(**MOCKED_PIPELINE_CAPABILITY),
    )
    res = runner.invoke(list_projects, credentials)
    assert res.exit_code == 0
    mocked_get_projects.assert_called_once()
    mocked_get_pipeline_capabilities.assert_called_once()

    project = Project(**MOCKED_PROJECTS_WITH_UNEXPECTED_KEYS["results"][0])
    pipeline = PipelineCapabilities(**MOCKED_PIPELINE_CAPABILITY)

    output_line = io.BytesIO()
    sys.stdout = output_line
    echo("\t".join([
        str(project.created),
        str(project.id),
        project.name.replace("\t", " "),
        pipeline.name,
    ]))
    assert output_line.getvalue() == res.output.encode()
Exemple #3
0
    def augment_projects_with_pipeline_capabilities(self, projects):
        """Fetch pipeline capabilities and append it to the project.

        Args:
            projects (list[Project]): list of projects

        Returns:
            list[Project]: same list of projects with pipeline capabilities
                uuid replaced with PipelineCapability
        """
        for project in projects:
            pipeline_capabilities = self.get_pipeline_capabilities(
                project.pipeline_capabilities)
            project_dict = dict(project)
            project_dict["pipeline_capabilities"] = pipeline_capabilities
            yield Project(**project_dict)
def test_get_merged_vcf__empty(mocker):
    """Test project doesn't have a merged VCF file."""
    project_id = str(uuid4())

    runner = CliRunner()

    mocked_login = mocker.patch.object(APIClient, "login", return_value=None)
    mocked_get_project = mocker.patch.object(
        APIClient,
        "get_project",
        return_value=Project(
            id=project_id,
            name="Project Cadmus",
            description="",
            created="2020-06-11T02:14:00.541889Z",
            organization=str(uuid4()),
            sample_count=3,
            pipeline_capabilites=str(uuid4()),
            files=[],
        ),
    )

    res = runner.invoke(
        get_merged_vcf,
        [
            project_id,
            "--email",
            "*****@*****.**",
            "--password",
            "123",
        ],
    )
    assert res.exit_code == 1
    mocked_login.assert_called_once()
    mocked_get_project.assert_called_once()
    assert (
        "No files to process for project {}".format(project_id) in res.output
    )
Exemple #5
0
def test_list_projects(mocker, credentials, recording, vcr):
    """Test projects being outputed to the shell."""
    runner = CliRunner()
    if not recording:
        # Mock list_projects only if using the cassettes, since we mock the
        # return value.
        list_projects_response = get_vcr_response("/api/v2/projects/", vcr)
        mocked_get_projects = mocker.patch.object(
            APIClient,
            "list_projects",
            return_value=Projects(**list_projects_response),
        )
        get_pipeline_capabilities_response = get_vcr_response(
            "/api/v2/pipeline-capabilities/", vcr, operator.contains)
        mocked_get_pipeline_capabilities = mocker.patch.object(
            APIClient,
            "get_pipeline_capabilities",
            return_value=PipelineCapabilities(
                **get_pipeline_capabilities_response),
        )
    res = runner.invoke(list_projects, credentials)
    assert res.exit_code == 0
    if not recording:
        mocked_get_projects.assert_called_once()
        projects = list_projects_response["results"]
        assert mocked_get_pipeline_capabilities.call_count == len(projects)
        output_line = io.BytesIO()
        sys.stdout = output_line
        for project in projects:
            project = Project(**project)
            echo("\t".join([
                str(project.created),
                str(project.id),
                project.name.replace("\t", " "),
                get_pipeline_capabilities_response["name"],
            ]))
        assert output_line.getvalue() == res.output.encode()
def test_get_merged_vcf__success__project_with_legacy_webhhok_url(mocker):
    """Test project download merged VCF success."""
    project_id = str(uuid4())
    file_id = str(uuid4())

    runner = CliRunner()

    mocked_login = mocker.patch.object(APIClient, "login", return_value=None)
    mocked_get_project = mocker.patch.object(
        APIClient,
        "get_project",
        return_value=Project(
            id=project_id,
            name="Project Cadmus",
            description="",
            created="2020-06-11T02:14:00.541889Z",
            organization=str(uuid4()),
            webhook_url="",
            sample_count=3,
            pipeline_capabilites=str(uuid4()),
            files=[
                {
                    "id": "755ec682-e4a5-414a-a5be-07e0af11cf75",
                    "s3_path": (
                        "app-data/output/apps/merge_vcfs/"
                        "{file_id}/{file_id}.vcf.bgz".format(file_id=file_id)
                    ),
                    "size": None,
                    "download_url": (
                        "https://bucket.s3.amazonaws.com/output/apps/"
                        "merge_vcfs/{file_id}/{file_id}.vcf.bgz".format(
                            file_id=file_id
                        )
                    ),
                    "file_type": "impute-vcf-merged",
                }
            ],
        ),
    )

    with runner.isolated_filesystem():
        mocked_download_file = mocker.patch(
            "gencove.command.projects.get_merged_vcf.main.download.utils."
            "download_file"
        )
        res = runner.invoke(
            get_merged_vcf,
            [
                project_id,
                "--email",
                "*****@*****.**",
                "--password",
                "123",
            ],
        )
    assert res.exit_code == 0
    mocked_login.assert_called_once()
    mocked_get_project.assert_called_once()
    mocked_download_file.assert_called_once_with(
        "{}.vcf.bgz".format(file_id),
        "https://bucket.s3.amazonaws.com/output/apps/"
        "merge_vcfs/{file_id}/{file_id}.vcf.bgz".format(file_id=file_id),
        no_progress=False,
    )