示例#1
0
    def test_cascade_delete_on_study(session: Session) -> None:

        study_id = 1
        direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE,
                                        objective=0)
        study = StudyModel(study_id=study_id,
                           study_name="test-study",
                           directions=[direction])
        study.system_attributes.append(
            StudySystemAttributeModel(study_id=study_id,
                                      key="sample-key1",
                                      value_json="1"))
        study.system_attributes.append(
            StudySystemAttributeModel(study_id=study_id,
                                      key="sample-key2",
                                      value_json="2"))
        session.add(study)
        session.commit()

        assert 2 == len(
            StudySystemAttributeModel.where_study_id(study_id, session))

        session.delete(study)
        session.commit()

        assert 0 == len(
            StudySystemAttributeModel.where_study_id(study_id, session))
示例#2
0
    def test_where_study_id(session: Session) -> None:

        sample_study = StudyModel(study_id=1, study_name="test-study")
        empty_study = StudyModel(study_id=2, study_name="test-study")

        session.add(
            StudySystemAttributeModel(
                study_id=sample_study.study_id, key="sample-key", value_json="1"
            )
        )

        assert 1 == len(StudySystemAttributeModel.where_study_id(sample_study.study_id, session))
        assert 0 == len(StudySystemAttributeModel.where_study_id(empty_study.study_id, session))
        # Check the case of unknown study_id.
        assert 0 == len(StudySystemAttributeModel.where_study_id(-1, session))