Exemple #1
0
    def test_cascade_delete_on_trial(session: Session) -> None:

        trial_id = 1
        direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE,
                                        objective=0)
        study = StudyModel(study_id=1,
                           study_name="test-study",
                           directions=[direction])
        trial = TrialModel(trial_id=trial_id,
                           study_id=study.study_id,
                           state=TrialState.COMPLETE)
        trial.system_attributes.append(
            TrialSystemAttributeModel(trial_id=trial_id,
                                      key="sample-key1",
                                      value_json="1"))
        trial.system_attributes.append(
            TrialSystemAttributeModel(trial_id=trial_id,
                                      key="sample-key2",
                                      value_json="2"))
        study.trials.append(trial)
        session.add(study)
        session.commit()

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

        session.delete(trial)
        session.commit()

        assert 0 == len(
            TrialSystemAttributeModel.where_trial_id(trial_id, session))
Exemple #2
0
    def test_all(session: 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(
            TrialSystemAttributeModel(trial_id=trial.trial_id, key="sample-key", value_json="1")
        )
        session.commit()

        system_attributes = TrialSystemAttributeModel.all(session)
        assert 1 == len(system_attributes)
        assert "sample-key" == system_attributes[0].key
        assert "1" == system_attributes[0].value_json
Exemple #3
0
    def test_find_by_trial_and_key(session: Session) -> None:

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

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

        attr = TrialSystemAttributeModel.find_by_trial_and_key(trial, "sample-key", session)
        assert attr is not None
        assert "1" == attr.value_json
        assert TrialSystemAttributeModel.find_by_trial_and_key(trial, "not-found", session) is None