Exemplo n.º 1
0
def test_project_retrieve(capsys, requests_mock):
    p_obj = factories.ProjectFactory()
    args = {
        "sodar_url": SODAR_SERVER_URL,
        "sodar_api_token": SODAR_API_TOKEN,
        "project_uuid": p_obj.sodar_uuid,
    }
    tpl = "%(sodar_url)sproject/api/retrieve/%(project_uuid)s"
    requests_mock.register_uri(
        "GET",
        tpl % args,
        headers={"Authorization": "Token %s" % args["sodar_api_token"]},
        json=cattr.unstructure(p_obj),
    )

    main([
        "--sodar-server-url",
        SODAR_SERVER_URL,
        "--sodar-api-token",
        SODAR_API_TOKEN,
        "project",
        "retrieve",
        p_obj.sodar_uuid,
    ])
    captured = capsys.readouterr()

    assert json.dumps(cattr.unstructure(p_obj)) + "\n" == captured.out
Exemplo n.º 2
0
def test_samplesheet_import(capsys, requests_mock):
    p_base = Path(__file__).parent / "data" / "isatab"
    i_obj = factories.InvestigationFactory()
    args = {
        "sodar_url": SODAR_SERVER_URL,
        "sodar_api_token": SODAR_API_TOKEN,
        "project_uuid": i_obj.project,
    }
    tpl = "%(sodar_url)ssamplesheets/api/import/%(project_uuid)s"
    requests_mock.register_uri(
        "POST",
        tpl % args,
        headers={"Authorization": "Token %s" % args["sodar_api_token"]},
        json=cattr.unstructure(i_obj),
    )

    main([
        "--sodar-server-url",
        SODAR_SERVER_URL,
        "--sodar-api-token",
        SODAR_API_TOKEN,
        "samplesheet",
        "import",
        i_obj.project,
        str(p_base / "i_Investigation.txt"),
        str(p_base / "s_test.txt"),
        str(p_base / "a_test_exome_sequencing_nucleotide_sequencing.txt"),
    ])
    captured = capsys.readouterr()

    assert json.dumps(cattr.unstructure(i_obj)) + "\n" == captured.out
Exemplo n.º 3
0
def test_project_create(capsys, requests_mock):
    p_obj = factories.ProjectFactory()
    args = {"sodar_url": SODAR_SERVER_URL, "sodar_api_token": SODAR_API_TOKEN}
    args["project"] = p_obj
    tpl = "%(sodar_url)sproject/api/create"
    requests_mock.register_uri(
        "POST",
        tpl % args,
        headers={"Authorization": "Token %s" % args["sodar_api_token"]},
        json=cattr.unstructure(p_obj),
    )

    main([
        "--sodar-server-url",
        SODAR_SERVER_URL,
        "--sodar-api-token",
        SODAR_API_TOKEN,
        "project",
        "create",
        "--parent-uuid",
        "YYY",
        "--title",
        "The title",
        "--owner-uuid",
        "OOO",
    ])
    captured = capsys.readouterr()

    assert cattr.unstructure(p_obj) == json.loads(captured.out)
Exemplo n.º 4
0
def test_call_landingzone_retrieve(capsys, requests_mock):
    lz_obj = factories.LandingZoneFactory()
    args = {
        "sodar_url": SODAR_SERVER_URL,
        "sodar_api_token": SODAR_API_TOKEN,
        "landingzone_uuid": lz_obj.sodar_uuid,
    }
    tpl = "%(sodar_url)slandingzones/api/retrieve/%(landingzone_uuid)s"
    requests_mock.register_uri(
        "GET",
        tpl % args,
        headers={"Authorization": "Token %s" % args["sodar_api_token"]},
        json=cattr.unstructure(lz_obj),
    )

    main([
        "--sodar-server-url",
        SODAR_SERVER_URL,
        "--sodar-api-token",
        SODAR_API_TOKEN,
        "landingzone",
        "retrieve",
        lz_obj.sodar_uuid,
    ])
    captured = capsys.readouterr()

    assert json.dumps(cattr.unstructure(lz_obj)) + "\n" == captured.out
Exemplo n.º 5
0
def test_samplesheet_export(capsys, requests_mock, tmpdir):
    p_base = Path(__file__).parent / "data" / "isatab"
    result = {
        "investigation": {
            "path": "i_Investigation.txt",
            "tsv": (p_base / "i_Investigation.txt").open("rt").read(),
        },
        "studies": {
            "s_test.txt": {
                "tsv": (p_base / "s_test.txt").open("rt").read()
            }
        },
        "assays": {
            "a_test_exome_sequencing_nucleotide_sequencing.txt": {
                "tsv":
                (p_base / "a_test_exome_sequencing_nucleotide_sequencing.txt"
                 ).open("rt").read()
            }
        },
    }

    i_obj = factories.InvestigationFactory()
    args = {
        "sodar_url": SODAR_SERVER_URL,
        "sodar_api_token": SODAR_API_TOKEN,
        "project_uuid": i_obj.project,
    }
    tpl = "%(sodar_url)ssamplesheets/api/export/json/%(project_uuid)s"
    requests_mock.register_uri(
        "GET",
        tpl % args,
        headers={"Authorization": "Token %s" % args["sodar_api_token"]},
        json=result,
    )

    main([
        "--sodar-server-url",
        SODAR_SERVER_URL,
        "--sodar-api-token",
        SODAR_API_TOKEN,
        "samplesheet",
        "export",
        "--print-output",
        "--write-output",
        str(tmpdir),
        i_obj.project,
    ])
    captured = capsys.readouterr()

    assert json.dumps(result) + "\n" == captured.out
    assert list(sorted(x.basename for x in tmpdir.listdir())) == [
        "a_test_exome_sequencing_nucleotide_sequencing.txt",
        "i_Investigation.txt",
        "s_test.txt",
    ]
Exemplo n.º 6
0
def test_call_landingzone_submit_validate(capsys, requests_mock):
    lz_obj = factories.LandingZoneFactory()
    # Move landing zone
    m_args = {
        "sodar_url": SODAR_SERVER_URL,
        "sodar_api_token": SODAR_API_TOKEN,
        "landingzone_uuid": lz_obj.sodar_uuid,
    }
    m_tpl = "%(sodar_url)slandingzones/api/submit/validate/%(landingzone_uuid)s"
    m_result = factories.LandingZoneFactory(
        sodar_uuid=m_args["landingzone_uuid"])
    requests_mock.register_uri(
        "POST",
        m_tpl % m_args,
        headers={"Authorization": "Token %s" % m_args["sodar_api_token"]},
        json=cattr.unstructure(m_result),
    )
    # Retrieve landing zone.
    r_args = m_args.copy()
    r_tpl = "%(sodar_url)slandingzones/api/retrieve/%(landingzone_uuid)s"
    r_result = m_result
    requests_mock.register_uri(
        "GET",
        r_tpl % r_args,
        headers={"Authorization": "Token %s" % r_args["sodar_api_token"]},
        json=cattr.unstructure(r_result),
    )

    main([
        "--sodar-server-url",
        SODAR_SERVER_URL,
        "--sodar-api-token",
        SODAR_API_TOKEN,
        "landingzone",
        "validate",
        lz_obj.sodar_uuid,
    ])
    captured = capsys.readouterr()

    assert json.dumps(cattr.unstructure(r_result)) + "\n" == captured.out
Exemplo n.º 7
0
def test_project_list(capsys, requests_mock):
    args = {"sodar_url": SODAR_SERVER_URL, "sodar_api_token": SODAR_API_TOKEN}
    tpl = "%(sodar_url)sproject/api/list"
    p_obj = factories.ProjectFactory()
    requests_mock.register_uri(
        "GET",
        tpl % args,
        headers={"Authorization": "Token %s" % args["sodar_api_token"]},
        json=cattr.unstructure([p_obj]),
    )

    main([
        "--sodar-server-url",
        SODAR_SERVER_URL,
        "--sodar-api-token",
        SODAR_API_TOKEN,
        "project",
        "list",
    ])
    captured = capsys.readouterr()

    assert json.dumps(cattr.unstructure([p_obj])) + "\n" == captured.out
Exemplo n.º 8
0
def test_call_landingzone_create(capsys, requests_mock):
    # Query project information.
    project = factories.ProjectFactory()
    i_args = {
        "sodar_url": SODAR_SERVER_URL,
        "sodar_api_token": SODAR_API_TOKEN,
        "project_uuid": project.sodar_uuid,
    }
    i_tpl = "%(sodar_url)ssamplesheets/api/investigation/retrieve/%(project_uuid)s"
    investigation = factories.InvestigationFactory()
    requests_mock.register_uri(
        "GET",
        i_tpl % i_args,
        headers={"Authorization": "Token %s" % i_args["sodar_api_token"]},
        json=cattr.unstructure(investigation),
    )
    # Creation of landing zone.
    l_tpl = "%(sodar_url)slandingzones/api/create/%(project_uuid)s"
    lz_obj = factories.LandingZoneFactory(project=i_args["project_uuid"])
    requests_mock.register_uri(
        "POST",
        l_tpl % i_args,
        headers={"Authorization": "Token %s" % i_args["sodar_api_token"]},
        json=cattr.unstructure(lz_obj),
    )

    main([
        "--sodar-server-url",
        SODAR_SERVER_URL,
        "--sodar-api-token",
        SODAR_API_TOKEN,
        "landingzone",
        "create",
        project.sodar_uuid,
    ])
    captured = capsys.readouterr()

    assert json.dumps(cattr.unstructure(lz_obj)) + "\n" == captured.out
Exemplo n.º 9
0
def test_no_args():
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        main([])
    assert pytest_wrapped_e.type == SystemExit
    assert pytest_wrapped_e.value.code == 1