예제 #1
0
    def test_cascade_delete_on_study(session):
        # type: (Session) -> None

        study_id = 1
        study = StudyModel(study_id=study_id,
                           study_name="test-study",
                           direction=StudyDirection.MINIMIZE)
        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):
        # type: (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))