def test_cascade_delete_on_study(session: Session) -> None: study_id = 1 direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE, objective=0) study = StudyModel(study_id=study_id, study_name="test-study", directions=[direction]) 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))
def test_find_by_study_and_key(session: 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
def test_where_study_id(session: 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))