def test_get_decisions(self): client = AdSel() decisions = client.get_decisions() self.assertEqual(len(decisions), 9) dec = decisions[3] self.assertEqual(dec.decision_name, "Pending Decision") self.assertEqual(dec.decision_id, 4)
def reset_collection(assignment_import, collection_type): if collection_type == COHORT_COLLECTION_TYPE: assignment = CohortAssignment() assignment.override_previous = True assignment.override_protected = True assignment.cohort_number = assignment_import.cohort elif collection_type == MAJOR_COLLECTION_TYPE: assignment = MajorAssignment() assignment.major_code = assignment_import.major assignment.assignment_type = "file" assignment.comments = assignment_import.comment assignment.user = assignment_import.created_by assignment.campus = assignment_import.campus assignment.quarter = assignment_import.quarter applicants_to_assign = [] for imp_assignment in assignment_import.get_assignments(): app = imp_assignment.get_application() applicants_to_assign.append(app) assignment.quarter = assignment_import.quarter assignment.applicants = applicants_to_assign client = AdSel() if collection_type == COHORT_COLLECTION_TYPE: return client.assign_cohorts_bulk(assignment) elif collection_type == MAJOR_COLLECTION_TYPE: return client.assign_majors(assignment)
def get_applications_by_type_id_qtr(type, id, quarter): apps = [] if type == COHORT_COLLECTION_TYPE: apps = get_applications_by_cohort_qtr(id, quarter) if type == MAJOR_COLLECTION_TYPE: apps = get_applications_by_major_qtr(id, quarter) if type == PURPLEGOLD_COLLECTION_TYPE: client = AdSel() apps = client.get_all_applications_by_qtr(quarter) return apps
def get_applications_by_major_qtr(major_id, quarter): try: client = AdSel() applications = client.get_all_applications_by_qtr(quarter) matching_apps = [] for application in applications: if application.major_program_code == major_id: matching_apps.append(application) except DataFailureException: return None return matching_apps
def get_applications_by_cohort_qtr(cohort_id, quarter): matching_apps = [] try: client = AdSel() applications = client.get_all_applications_by_qtr(quarter) for application in applications: if application.assigned_cohort == int(cohort_id): matching_apps.append(application) except DataFailureException: pass return matching_apps
def _get_cohort_by_id(cohort_id, quarter): client = AdSel() cohorts = client.get_cohorts_by_qtr(quarter) for cohort in cohorts: if cohort.cohort_number == cohort_id: return { "collection_id": cohort_id, "residency": cohort.cohort_residency, "admit_decision": cohort.admit_decision, "protected_group": cohort.protected_group, "description": cohort.cohort_description, "applications_assigned": cohort.assigned_count }
def reset_purplegold(import_args, apps): assignment = PurpleGoldAssignment() assignment.assignment_type = "file" assignment.quarter = import_args['quarter'] assignment.campus = import_args['campus'] assignment.user = import_args['created_by'] assignment.comments = import_args['comment'] applicants_to_assign = [] for app in apps: applicants_to_assign.append( PurpleGoldApplication(adsel_id=app.adsel_id, award_amount=0)) assignment.applicants = applicants_to_assign client = AdSel() return client.assign_purple_gold(assignment)
def _get_major_by_id(major_id, quarter): client = AdSel() try: major = client.get_major_details_by_qtr_major(quarter, major_id) return { "collection_id": major.major_abbr, "applications_assigned": major.assigned_count, "program_code": major.program_code, "major_pathway": major.major_pathway, "display_name": major.display_name, "college": major.college, "division": major.division, "dtx": major.dtx, "assigned_resident": major.assigned_resident, "assigned_nonresident": major.assigned_nonresident, "assigned_international": major.assigned_international } except DataFailureException: return None
def create_from_syskey_list(assignment_import, syskeys): applications = [] adsel = AdSel() try: applications = \ adsel.get_applications_by_qtr_syskey_list( assignment_import.quarter, syskeys ) except DataFailureException as ex: pass found_syskeys = dict.fromkeys(syskeys, False) for app in applications: found_syskeys[app.system_key] = True SyskeyAssignment.create_from_adsel_appliction( app, assignment_import) missing_syskeys = [ key for key, value in found_syskeys.items() if not value ] for key in missing_syskeys: SyskeyAssignment.create_missing(key, assignment_import)
def submit_collection(assignment_import): (assignment_import, assignment) = _get_collection(assignment_import) client = AdSel() client.get_quarters() if isinstance(assignment_import, SyskeyImport): if assignment_import.cohort: if assignment_import.upload_filename is not None: return client.assign_cohorts_bulk(assignment) else: return client.assign_cohorts_manual(assignment) elif assignment_import.major and len(assignment_import.major) > 0: return client.assign_majors(assignment) else: return client.assign_purple_gold(assignment)
def get_activity_log(**kwargs): activities = AdSel().get_filtered_activities(**kwargs) activity_json = [] for activity in activities: try: date = pytz.utc.localize(activity.assignment_date) except ValueError: date = activity.assignment_date act = { 'activity_date': date, 'comment': activity.comment, 'assigned_msg': activity.total_assigned, 'submitted_msg': activity.total_submitted, 'user': activity.user, 'cohort': activity.cohort_number, 'major': activity.major_abbr, 'collection_type': 'Cohort' if activity.major_abbr is None else 'Major' } activity_json.append(act) return activity_json
def get_collection_list_by_type(collection_type, quarter_id): if collection_type == MAJOR_COLLECTION_TYPE: client = AdSel() majors = client.get_majors_by_qtr(quarter_id) response = [] for major in majors: response.append({ 'value': major.program_code, 'abbr': major.major_abbr, 'text': major.display_name, 'division': major.division, 'college': major.college, 'dtx': major.dtx, 'assigned_count': major.assigned_count }) return response elif collection_type == COHORT_COLLECTION_TYPE: client = AdSel() cohorts = client.get_cohorts_by_qtr(quarter_id) response = [] for cohort in cohorts: response.append({ 'value': cohort.cohort_number, 'text': cohort.cohort_description, 'description': cohort.cohort_description, 'residency': cohort.cohort_residency, 'protected': cohort.protected_group, 'admit_decision': cohort.admit_decision, 'assigned_count': cohort.assigned_count }) sorted_response = sorted(response, key=lambda k: k['value']) return sorted_response else: raise InvalidCollectionException(collection_type)
def get_application_by_qtr_syskey(qtr_id, syskey): return AdSel().get_applications_by_qtr_syskey(qtr_id, syskey)
def get_current_quarters(): client = AdSel() quarters = client.get_quarters() return quarters
def test_get_major_details(self): client = AdSel() major_details = client.get_major_details_by_qtr_major(0, "0_BIOL_1") self.assertEqual(major_details.assigned_nonresident, 6) self.assertEqual(major_details.assigned_international, 0) self.assertEqual(major_details.assigned_resident, 12412)
class AdselTest(TestCase): adsel = AdSel() def test_request_headers(self): self.assertEqual(self.adsel._headers(), {'Accept': 'application/json'}) def test_error(self): with self.assertRaises(DataFailureException): self.adsel._get_resource("/foobar/") def test_get_majors(self): majors = self.adsel.get_majors_by_qtr(0) self.assertEqual(len(majors), 4) self.assertEqual(majors[1].major_abbr, "CHEM") majors_unpaginated = self.adsel.get_majors_by_qtr(1) self.assertEqual(len(majors_unpaginated), 2) @mock.patch('uw_adsel.AdSel.get_now', side_effect=mocked_get_now) def test_get_quarters(self, mock_obj): quarters = self.adsel.get_quarters() self.assertEqual(len(quarters), 2) self.assertEqual(quarters[0].begin, datetime(2019, 11, 5, 0, 0, 0)) self.assertFalse(quarters[1].is_current) self.assertTrue(quarters[0].is_current) def test_get_cohorts(self): cohorts = self.adsel.get_cohorts_by_qtr(0) self.assertEqual(len(cohorts), 2) self.assertEqual(cohorts[1].cohort_description, "This is another cohort") cohorts_unpaginated = self.adsel.get_cohorts_by_qtr(1) self.assertEqual(len(cohorts_unpaginated), 2) @mock.patch('uw_adsel.AdSel.get_now', side_effect=mocked_get_now) def test_get_now(self, mock_obj): self.assertEqual(self.adsel.get_now(), datetime(2019, 11, 12, 0, 10, 21)) def test_get_activities(self): activities = self.adsel.get_activities() self.assertEqual(len(activities), 4) self.assertEqual(activities[0].user, "javerage") self.assertEqual(activities[0].decision_import_id, 784) self.assertEqual(activities[0].assignment_category, "Cohort") def test_get_filtered_activities(self): # netid filter activities = self.adsel.get_filtered_activities(netid="javerage") self.assertEqual(len(activities), 2) # No results activities = self.adsel.get_filtered_activities(netid="foo") self.assertEqual(len(activities), 0) # dual filter activities = self.adsel.get_filtered_activities(netid="javerage", system_key=12345) self.assertEqual(len(activities), 4) def test_get_application(self): applications = self.adsel.get_applications_by_qtr_syskey(0, 123) self.assertEqual(len(applications), 4) self.assertEqual(applications[0].adsel_id, 1) def test_get_applications_by_syskey_list(self): # No Match applications = self.adsel.get_applications_by_qtr_syskey_list(0, [123]) self.assertEqual(len(applications), 0) # Partial Match applications = self.adsel.get_applications_by_qtr_syskey_list( 0, [123, 76711, 656340]) self.assertEqual(len(applications), 2) # Full Match applications = self.adsel.get_applications_by_qtr_syskey_list( 0, [456340, 97508, 156340, 76711]) self.assertEqual(len(applications), 6) def test_post(self): a1 = Application() a1.adsel_id = 123 a1.system_key = 41 a1.application_number = 1 a2 = Application() a2.adsel_id = 734 a2.system_key = 34 a2.application_number = 5 cohort_assign = CohortAssignment() cohort_assign.applicants = [a1, a2] cohort_assign.assignment_type = "upload" cohort_assign.cohort_number = 1 cohort_assign.override_protected = True cohort_assign.override_previous = False cohort_assign.quarter = 0 cohort_assign.campus = 1 cohort_assign.comments = "My comment" cohort_assign.user = "******" cohort_json = cohort_assign.json_data() self.assertEqual(cohort_json['overridePreviousCohort'], False) self.assertEqual(cohort_json['overridePreviousProtectedCohort'], True) try: submission = self.adsel.assign_cohorts_bulk(cohort_assign) except Exception: self.fail('assign_cohorts raised an exception') major_assign = MajorAssignment() major_assign.applicants = [a1, a2] major_assign.assignment_type = "upload" major_assign.major_code = "CSE" major_assign.quarter = 0 major_assign.campus = 1 major_assign.comments = "My comment" major_assign.user = "******" major_json = major_assign.json_data() self.assertEqual(len(major_json['applicants']), 2) self.assertEqual(major_json['applicants'][0]['admissionSelectionId'], 123) try: submission = self.adsel.assign_majors(major_assign) except Exception: self.fail('assign_majors raised an exception') def test_get_all_app(self): apps = self.adsel.get_all_applications_by_qtr(0) self.assertEqual(len(apps), 4) def test_purple_gold_assignment(self): a1 = PurpleGoldApplication() a1.adsel_id = 123 a1.system_key = 41 a1.application_number = 1 a1.award_amount = 1000 a2 = PurpleGoldApplication() a2.adsel_id = 734 a2.system_key = 34 a2.application_number = 5 a2.award_amount = 2000 purple_gold_assign = PurpleGoldAssignment() purple_gold_assign.applicants = [a1, a2] purple_gold_assign.assignment_type = "upload" purple_gold_assign.quarter = 0 purple_gold_assign.campus = 1 purple_gold_assign.comments = "My comment" purple_gold_assign.user = "******" json_data = purple_gold_assign.json_data() self.assertEqual(json_data['applicants'][0]['awardAmount'], 1000) try: submission = self.adsel.assign_purple_gold(purple_gold_assign) except Exception: self.fail('assign_purple_gold raised an exception') def test_get_major_details(self): client = AdSel() major_details = client.get_major_details_by_qtr_major(0, "0_BIOL_1") self.assertEqual(major_details.assigned_nonresident, 6) self.assertEqual(major_details.assigned_international, 0) self.assertEqual(major_details.assigned_resident, 12412) def test_get_decisions(self): client = AdSel() decisions = client.get_decisions() self.assertEqual(len(decisions), 9) dec = decisions[3] self.assertEqual(dec.decision_name, "Pending Decision") self.assertEqual(dec.decision_id, 4) def test_decision_assignment(self): a1 = DepartmentalDecisionApplication() a1.adsel_id = 123 a1.system_key = 41 a1.application_number = 1 a1.decision_id = 1 a2 = DepartmentalDecisionApplication() a2.adsel_id = 734 a2.system_key = 34 a2.application_number = 5 a2.decision_id = 2 dd_assign = DecisionAssignment() dd_assign.applicants = [a1, a2] dd_assign.assignment_type = "upload" dd_assign.quarter = 0 dd_assign.campus = 1 dd_assign.comments = "My comment" dd_assign.user = "******" json_data = dd_assign.json_data() self.assertEqual(json_data['applicants'][0]['departmentalDecisionId'], 1) self.assertEqual(json_data['assignmentDetail']['assignmentCategory'], "DepartmentalDecision") try: submission = self.adsel.assign_decisions(dd_assign) except Exception: self.fail('assign_decisions raised an exception')