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.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))
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( 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
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( 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
def test_where_study(session: Session) -> None: direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE, objective=0) study = StudyModel(study_id=1, study_name="test-study", directions=[direction]) trial = TrialModel(trial_id=1, study_id=study.study_id, state=TrialState.COMPLETE) session.add(study) session.add(trial) session.add( TrialUserAttributeModel(trial_id=trial.trial_id, key="sample-key", value_json="1")) session.commit() user_attributes = TrialUserAttributeModel.where_study(study, session) assert 1 == len(user_attributes) assert "sample-key" == user_attributes[0].key assert "1" == user_attributes[0].value_json