def test_batch_student_count(self, client, fake_auth): """Get distinct number of SIDs in union of cohorts, curated groups, etc.""" user_id = AuthorizedUser.get_id_per_uid(coe_advisor_uid) cohort_ids = [] sids = set() for cohort in CohortFilter.get_cohorts_of_user_id(user_id): cohort_id = cohort['id'] cohort_ids.append(cohort_id) sids.update(set(CohortFilter.get_sids(cohort_id))) assert len(sids) > 1 curated_group = CuratedGroup.create( user_id, 'Like a lemon to a lime, a lime to a lemon') curated_group_ids = [curated_group.id] # We use SIDs from cohorts (above). Therefore, we expect no increase in 'batch_distinct_student_count'. for sid in sids: CuratedGroup.add_student(curated_group.id, sid) # A specific student (SID) that is in neither cohorts nor curated groups. some_other_sid = '5678901234' assert some_other_sid not in sids # Log in as authorized user fake_auth.login(coe_advisor_uid) count = _api_batch_distinct_student_count( client, cohort_ids=cohort_ids, curated_group_ids=curated_group_ids, sids=[some_other_sid], ) assert len(sids) + 1 == count
def test_batch_student_count_not_owner(self, client, fake_auth): """Deny user access to cohort owned by some other dept.""" user_id = AuthorizedUser.get_id_per_uid(coe_advisor_uid) cohorts = CohortFilter.get_cohorts_of_user_id(user_id) # Assert non-zero student count assert sum(list(map(lambda c: c['totalStudentCount'], cohorts))) # Log in as non-owner fake_auth.login(asc_advisor_uid) count = _api_batch_distinct_student_count(client, cohort_ids=[c['id'] for c in cohorts]) assert count == 0
def my_cohorts(): domain = get_param(request.args, 'domain', 'default') if is_unauthorized_domain(domain): raise ForbiddenRequestError( f'You are unauthorized to query the \'{domain}\' domain') cohorts = [] for cohort in CohortFilter.get_cohorts_of_user_id(current_user.get_id(), domain=domain): cohort['isOwnedByCurrentUser'] = True cohorts.append(cohort) return tolerant_jsonify(cohorts)
def my_cohorts(): cohorts = [] for cohort in CohortFilter.get_cohorts_of_user_id(current_user.get_id()): cohort['isOwnedByCurrentUser'] = True cohorts.append(cohort) return tolerant_jsonify(cohorts)