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 download_cohort_csv(): benchmark = get_benchmarker('cohort download_csv') benchmark('begin') params = request.get_json() cohort_id = int(get_param(params, 'cohortId')) cohort = CohortFilter.find_by_id( cohort_id, offset=0, limit=None, include_profiles=False, include_sids=True, include_students=False, ) if cohort and _can_current_user_view_cohort(cohort): fieldnames = get_param(params, 'csvColumnsSelected', []) sids = CohortFilter.get_sids(cohort['id']) return _response_with_csv_download(benchmark, cohort['domain'], fieldnames, sids) else: raise ResourceNotFoundError( f'No cohort found with identifier: {cohort_id}')