def test_create_and_delete_cohort(self): """Cohort_filter record to Flask-Login for recognized UID.""" owner = AuthorizedUser.find_by_uid(asc_advisor_uid).uid # Check validity of UID assert owner # Create cohort group_codes = ['MFB-DB', 'MFB-DL', 'MFB-MLB', 'MFB-OLB'] cohort = CohortFilter.create( uid=owner, name='Football, Defense', filter_criteria={ 'groupCodes': group_codes, }, ) cohort_id = cohort['id'] assert CohortFilter.find_by_id(cohort_id)['owner']['uid'] == owner assert cohort['totalStudentCount'] == len( CohortFilter.get_sids(cohort_id)) # Delete cohort and verify previous_owner_count = cohort_count(owner) CohortFilter.delete(cohort_id) std_commit(allow_test_environment=True) assert cohort_count(owner) == previous_owner_count - 1
def test_create_and_delete_cohort(self): """Cohort_filter record to Flask-Login for recognized UID.""" owner = AuthorizedUser.find_by_uid(asc_advisor_uid).uid shared_with = AuthorizedUser.find_by_uid(coe_advisor_uid).uid # Check validity of UIDs assert owner assert shared_with # Create and share cohort group_codes = ['MFB-DB', 'MFB-DL', 'MFB-MLB', 'MFB-OLB'] cohort = CohortFilter.create( uid=owner, name='Football, Defense', filter_criteria={ 'groupCodes': group_codes, }, ) cohort_id = cohort['id'] CohortFilter.share(cohort_id, shared_with) owners = CohortFilter.find_by_id(cohort_id)['owners'] assert len(owners) == 2 assert owner, shared_with in [user['uid'] for user in owners] assert cohort['totalStudentCount'] == len( CohortFilter.get_sids(cohort_id)) # Delete cohort and verify previous_owner_count = cohort_count(owner) previous_shared_count = cohort_count(shared_with) CohortFilter.delete(cohort_id) assert cohort_count(owner) == previous_owner_count - 1 assert cohort_count(shared_with) == previous_shared_count - 1
def delete(cls, curated_group_id): curated_group = cls.query.filter_by(id=curated_group_id).first() if curated_group: db.session.delete(curated_group) std_commit() # Delete all cohorts that reference the deleted group for cohort_filter_id in curated_group.get_referencing_cohort_ids(): CohortFilter.delete(cohort_filter_id) std_commit()
def delete_cohort(cohort_id): if cohort_id.isdigit(): cohort_id = int(cohort_id) if CohortFilter.is_cohort_owned_by(cohort_id, current_user.get_id()): CohortFilter.delete(cohort_id) return tolerant_jsonify( {'message': f'Cohort deleted (id={cohort_id})'}), 200 else: raise BadRequestError( f'User {current_user.get_uid()} does not own cohort with id={cohort_id}' ) else: raise ForbiddenRequestError( f'Programmatic deletion of canned cohorts is not allowed (id={cohort_id})' )
def delete_cohort(cohort_id): if cohort_id.isdigit(): cohort_id = int(cohort_id) uid = current_user.get_id() cohort = get_cohort_owned_by(cohort_id, uid) if cohort: CohortFilter.delete(cohort_id) return jsonify( {'message': 'Cohort deleted (id={})'.format(cohort_id)}), 200 else: raise BadRequestError( 'User {uid} does not own cohort_filter with id={id}'.format( uid=uid, id=cohort_id)) else: raise ForbiddenRequestError( 'Programmatic deletion of teams is not supported (id={})'.format( cohort_id))
def delete_cohort(cohort_id): if cohort_id.isdigit(): cohort_id = int(cohort_id) uid = current_user.get_id() cohort = next( (c for c in CohortFilter.all_owned_by(uid) if c.id == cohort_id), None) if cohort: CohortFilter.delete(cohort_id) return tolerant_jsonify( {'message': f'Cohort deleted (id={cohort_id})'}), 200 else: raise BadRequestError( f'User {uid} does not own cohort_filter with id={cohort_id}') else: raise ForbiddenRequestError( f'Programmatic deletion of canned cohorts is not allowed (id={cohort_id})' )
def test_create_and_delete_cohort(self): """Cohort_filter record to Flask-Login for recognized UID.""" owner = AuthorizedUser.find_by_uid(asc_advisor_uid).uid shared_with = AuthorizedUser.find_by_uid(coe_advisor_uid).uid # Check validity of UIDs assert owner assert shared_with # Create and share cohort group_codes = ['MFB-DB', 'MFB-DL', 'MFB-MLB', 'MFB-OLB'] cohort = CohortFilter.create(uid=owner, label='Football, Defense', group_codes=group_codes) cohort = CohortFilter.share(cohort.id, shared_with) assert len(cohort.owners) == 2 assert owner, shared_with in [user.uid for user in cohort.owners] # Delete cohort and verify previous_owner_count = cohort_count(owner) previous_shared_count = cohort_count(shared_with) CohortFilter.delete(cohort.id) assert cohort_count(owner) == previous_owner_count - 1 assert cohort_count(shared_with) == previous_shared_count - 1
def test_create_and_delete_cohort(self): """cohort_filter record to Flask-Login for recognized UID""" owner = AuthorizedUser.find_by_uid('2040') shared_with = AuthorizedUser.find_by_uid('1133399') # Check validity of UIDs assert owner assert shared_with # Create and share cohort cohort = CohortFilter.create(label='High-risk Badminton', team_codes=['MBK', 'WBK'], uid=owner.uid) cohort = CohortFilter.share(cohort['id'], shared_with.uid) assert len(cohort['owners']) == 2 assert owner, shared_with in cohort['owners'] # Delete cohort and verify previous_owner_count = cohort_count(owner) previous_shared_count = cohort_count(shared_with) CohortFilter.delete(cohort['id']) assert cohort_count(owner) == previous_owner_count - 1 assert cohort_count(shared_with) == previous_shared_count - 1