コード例 #1
0
    def test_cascade_delete_on_trial(session):
        # type: (Session) -> None

        trial_id = 1
        study = StudyModel(study_id=1,
                           study_name="test-study",
                           direction=StudyDirection.MINIMIZE)
        trial = TrialModel(trial_id=trial_id,
                           study_id=study.study_id,
                           state=TrialState.COMPLETE)
        trial.user_attributes.append(
            TrialUserAttributeModel(trial_id=trial_id,
                                    key="sample-key1",
                                    value_json="1"))
        trial.user_attributes.append(
            TrialUserAttributeModel(trial_id=trial_id,
                                    key="sample-key2",
                                    value_json="2"))
        study.trials.append(trial)
        session.add(study)
        session.commit()

        assert 2 == len(
            TrialUserAttributeModel.where_trial_id(trial_id, session))

        session.delete(trial)
        session.commit()

        assert 0 == len(
            TrialUserAttributeModel.where_trial_id(trial_id, session))
コード例 #2
0
    def test_all(session):
        # type: (Session) -> None

        study = StudyModel(study_id=1, study_name='test-study', direction=StudyDirection.MINIMIZE)
        trial = TrialModel(trial_id=1, study_id=study.study_id, state=TrialState.COMPLETE)

        session.add(
            TrialUserAttributeModel(trial_id=trial.trial_id, key='sample-key', value_json='1'))
        session.commit()

        user_attributes = TrialUserAttributeModel.all(session)
        assert 1 == len(user_attributes)
        assert 'sample-key' == user_attributes[0].key
        assert '1' == user_attributes[0].value_json
コード例 #3
0
    def test_find_by_trial_and_key(session):
        # type: (Session) -> None

        study = StudyModel(study_id=1, study_name='test-study')
        trial = TrialModel(study_id=study.study_id)

        session.add(
            TrialUserAttributeModel(trial_id=trial.trial_id, key='sample-key', value_json='1'))
        session.commit()

        attr = TrialUserAttributeModel.find_by_trial_and_key(trial, 'sample-key', session)
        assert attr is not None
        assert '1' == attr.value_json
        assert TrialUserAttributeModel.find_by_trial_and_key(trial, 'not-found', session) is None
コード例 #4
0
    def test_find_by_trial_and_key(session):
        # type: (Session) -> None

        study = StudyModel(study_id=1, study_name="test-study")
        trial = TrialModel(study_id=study.study_id)

        session.add(
            TrialUserAttributeModel(trial_id=trial.trial_id,
                                    key="sample-key",
                                    value_json="1"))
        session.commit()

        attr = TrialUserAttributeModel.find_by_trial_and_key(
            trial, "sample-key", session)
        assert attr is not None
        assert "1" == attr.value_json
        assert TrialUserAttributeModel.find_by_trial_and_key(
            trial, "not-found", session) is None
コード例 #5
0
    def test_where_trial(session):
        # type: (Session) -> None

        study = StudyModel(study_id=1,
                           study_name="test-study",
                           direction=StudyDirection.MINIMIZE)
        trial = TrialModel(trial_id=1,
                           study_id=study.study_id,
                           state=TrialState.COMPLETE)

        session.add(
            TrialUserAttributeModel(trial_id=trial.trial_id,
                                    key="sample-key",
                                    value_json="1"))
        session.commit()

        user_attributes = TrialUserAttributeModel.where_trial(trial, session)
        assert 1 == len(user_attributes)
        assert "sample-key" == user_attributes[0].key
        assert "1" == user_attributes[0].value_json