async def test_get_all_base_items_with_specified_type_and_state(
        async_test_client, clean_test_db_engine):
    with mock.patch(
            "hetdesrun.persistence.dbservice.revision.Session",
            sessionmaker(clean_test_db_engine),
    ):
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_1  # DRAFT
            ).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_2  # RELEASED
            ).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(**tr_dto_json_workflow_1  # DRAFT
                                              ).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(**tr_dto_json_workflow_2  # DRAFT
                                              ).to_transformation_revision())

        async with async_test_client as ac:
            response_released_component = await ac.get(
                "/api/base-items/?type=COMPONENT&state=RELEASED")
            response_draft_workflow = await ac.get(
                "/api/base-items/?type=WORKFLOW&state=DRAFT")

        assert response_released_component.status_code == 200
        assert len(response_released_component.json()) == 1
        assert response_released_component.json()[0] == tr_dto_json_component_2
        assert response_draft_workflow.status_code == 200
        assert len(response_draft_workflow.json()) == 2
        assert response_draft_workflow.json()[0] == tr_dto_json_workflow_1
        assert response_draft_workflow.json()[1] == tr_dto_json_workflow_2
示例#2
0
def test_transformation_dto_from_transformation_revision():
    transformation_revision = TransformationRevisionFrontendDto(
        **valid_transformation).to_transformation_revision()
    transformation_revision_dto = (
        TransformationRevisionFrontendDto.from_transformation_revision(
            transformation_revision))

    assert len(transformation_revision_dto.inputs) == len(
        valid_transformation["inputs"])
    assert len(transformation_revision_dto.outputs) == len(
        valid_transformation["outputs"])
async def test_deprecate_base_item_of_type_component(async_test_client,
                                                     clean_test_db_engine):
    with mock.patch(
            "hetdesrun.persistence.dbservice.revision.Session",
            sessionmaker(clean_test_db_engine),
    ):
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_2).to_transformation_revision())

        async with async_test_client as ac:
            response = await ac.put(
                "/api/base-items/" + str(tr_dto_json_component_2["id"]),
                json=tr_dto_json_component_2_deprecate,
            )

        assert response.status_code == 201
        assert response.json()["state"] == "DISABLED"
        assert response.json()["name"] != "new name"
        assert response.json()["category"] != "Test"
        assert len(response.json()["inputs"]) == 0

        tr_component_2 = read_single_transformation_revision(
            tr_dto_json_component_2["id"])

        assert tr_component_2.state.value == "DISABLED"
        assert tr_component_2.name != "new name"
        assert "disabled_timestamp" in tr_component_2.content
        assert "released_timestamp" in tr_component_2.content
示例#4
0
def test_transformation_dto_to_transformation_revision():
    transformation_revision = TransformationRevisionFrontendDto(
        **valid_transformation).to_transformation_revision()

    assert len(transformation_revision.io_interface.inputs) == len(
        valid_transformation["inputs"])
    assert len(transformation_revision.io_interface.outputs) == len(
        valid_transformation["outputs"])
示例#5
0
def test_transformation_validator_output_names_unique_identifies_double_name():
    transformation_with_double_output_name = deepcopy(valid_transformation)
    transformation_with_double_output_name["outputs"][1][
        "name"] = transformation_with_double_output_name["outputs"][0]["name"]

    with pytest.raises(ValueError) as exc:
        TransformationRevisionFrontendDto(
            **transformation_with_double_output_name)

    assert "duplicates" in str(exc.value)
async def test_get_all_base_items_with_specified_type(async_test_client,
                                                      clean_test_db_engine):
    with mock.patch(
            "hetdesrun.persistence.dbservice.revision.Session",
            sessionmaker(clean_test_db_engine),
    ):
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_1  # DRAFT
            ).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_2  # RELEASED
            ).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(**tr_dto_json_workflow_1  # DRAFT
                                              ).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(**tr_dto_json_workflow_2  # DRAFT
                                              ).to_transformation_revision())

        async with async_test_client as ac:
            response_component = await ac.get("/api/base-items/?type=COMPONENT"
                                              )
            response_workflow = await ac.get("/api/base-items/?type=WORKFLOW")
            response_foo = await ac.get("/api/base-items/?type=foo")

        assert response_component.status_code == 200
        assert len(response_component.json()) == 2
        assert response_component.json()[0] == tr_dto_json_component_1
        assert response_component.json()[1] == tr_dto_json_component_2
        assert response_workflow.status_code == 200
        assert len(response_workflow.json()) == 2
        assert response_workflow.json()[0] == tr_dto_json_workflow_1
        assert response_workflow.json()[1] == tr_dto_json_workflow_2
        assert response_foo.status_code == 422
        assert ("not a valid enumeration member"
                in response_foo.json()["detail"][0]["msg"])
async def test_get_all_base_items_with_valid_db_entries(
        async_test_client, clean_test_db_engine):
    with mock.patch(
            "hetdesrun.persistence.dbservice.revision.Session",
            sessionmaker(clean_test_db_engine),
    ):
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_1).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_workflow_1).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_workflow_2).to_transformation_revision())

        async with async_test_client as ac:
            response = await ac.get("/api/base-items/")

        assert response.status_code == 200
        assert response.json()[0] == tr_dto_json_component_1
        assert response.json()[1] == tr_dto_json_workflow_1
        assert response.json()[2] == tr_dto_json_workflow_2
async def test_get_transformation_revision_by_id_with_workflow(
        async_test_client, clean_test_db_engine):
    with mock.patch(
            "hetdesrun.persistence.dbservice.revision.Session",
            sessionmaker(clean_test_db_engine),
    ):
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_workflow_1).to_transformation_revision())

        async with async_test_client as ac:
            response = await ac.get("/api/base-items/" +
                                    str(get_uuid_from_seed("workflow 1")))
        assert response.status_code == 200
        assert response.json() == tr_dto_json_workflow_1
async def test_update_transformation_revision_from_released_component_dto(
        async_test_client, clean_test_db_engine):
    with mock.patch(
            "hetdesrun.persistence.dbservice.revision.Session",
            sessionmaker(clean_test_db_engine),
    ):
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_2).to_transformation_revision())

        async with async_test_client as ac:
            response = await ac.put(
                "/api/base-items/" + str(get_uuid_from_seed("component 2")),
                json=tr_dto_json_component_2_update,
            )

        assert response.status_code == 403
async def test_update_transformation_revision_with_component(
        async_test_client, clean_test_db_engine):
    with mock.patch(
            "hetdesrun.persistence.dbservice.revision.Session",
            sessionmaker(clean_test_db_engine),
    ):
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_1).to_transformation_revision())

        async with async_test_client as ac:
            response = await ac.put(
                "/api/base-items/" + str(get_uuid_from_seed("component 1")),
                json=tr_dto_json_component_1_update,
            )

        assert response.status_code == 201
        assert response.json()["name"] == "new name"
        assert response.json()["category"] == "Test"
        assert response.json()["inputs"][0]["id"] == str(
            get_uuid_from_seed("new input"))
async def test_get_all_base_items_with_specified_state(async_test_client,
                                                       clean_test_db_engine):
    with mock.patch(
            "hetdesrun.persistence.dbservice.revision.Session",
            sessionmaker(clean_test_db_engine),
    ):
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_1  # DRAFT
            ).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(
                **tr_dto_json_component_2  # RELEASED
            ).to_transformation_revision())
        store_single_transformation_revision(
            TransformationRevisionFrontendDto(**tr_dto_json_workflow_1  # DRAFT
                                              ).to_transformation_revision())
        tr_workflow_2 = TransformationRevisionFrontendDto(
            **tr_dto_json_workflow_2).to_transformation_revision()
        tr_workflow_2.deprecate()
        store_single_transformation_revision(tr_workflow_2)

        async with async_test_client as ac:
            response_draft = await ac.get("/api/base-items/?state=DRAFT")
            response_released = await ac.get("/api/base-items/?state=RELEASED")
            response_disabled = await ac.get("/api/base-items/?state=DISABLED")
            response_foo = await ac.get("/api/base-items/?state=foo")

        assert response_draft.status_code == 200
        assert len(response_draft.json()) == 2
        assert response_draft.json()[0] == tr_dto_json_component_1
        assert response_draft.json()[1] == tr_dto_json_workflow_1
        assert response_released.status_code == 200
        assert len(response_released.json()) == 1
        assert response_released.json()[0] == tr_dto_json_component_2
        assert response_disabled.status_code == 200
        assert len(response_disabled.json()) == 1
        assert response_disabled.json(
        )[0]["id"] == tr_dto_json_workflow_2["id"]
        assert response_disabled.json()[0]["state"] == "DISABLED"
        assert response_foo.status_code == 422
        assert ("not a valid enumeration member"
                in response_foo.json()["detail"][0]["msg"])
示例#12
0
def test_transformation_validators_accept_valid_workflow():
    TransformationRevisionFrontendDto(**valid_transformation)