Exemplo n.º 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))
Exemplo n.º 2
0
    def test_find_by_study_and_key(session):
        # type: (Session) -> None

        study = StudyModel(study_id=1, study_name='test-study')
        session.add(
            StudySystemAttributeModel(study_id=study.study_id, key='sample-key', value_json='1'))
        session.commit()

        attr = StudySystemAttributeModel.find_by_study_and_key(study, 'sample-key', session)
        assert attr is not None and '1' == attr.value_json

        assert StudySystemAttributeModel.find_by_study_and_key(study, 'not-found', session) is None
Exemplo n.º 3
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))
Exemplo n.º 4
0
    def test_find_by_study_and_key(session):
        # type: (Session) -> None

        study = StudyModel(study_id=1, study_name="test-study")
        session.add(
            StudySystemAttributeModel(study_id=study.study_id,
                                      key="sample-key",
                                      value_json="1"))
        session.commit()

        attr = StudySystemAttributeModel.find_by_study_and_key(
            study, "sample-key", session)
        assert attr is not None and "1" == attr.value_json

        assert StudySystemAttributeModel.find_by_study_and_key(
            study, "not-found", session) is None