def test_sis_term_id_for_name(self): """Handles well-formed term names.""" assert berkeley.sis_term_id_for_name('Spring 2015') == '2152' assert berkeley.sis_term_id_for_name('Summer 2016') == '2165' assert berkeley.sis_term_id_for_name('Fall 2017') == '2178' assert berkeley.sis_term_id_for_name('Fall 1997') == '1978' assert berkeley.sis_term_id_for_name('Winter 1976') == '1760'
def test_term_id_lists(self, app): all_term_ids = set( berkeley.reverse_term_ids(include_future_terms=True, include_legacy_terms=True)) canvas_integrated_term_ids = set(berkeley.reverse_term_ids()) future_term_ids = set(berkeley.future_term_ids()) legacy_term_ids = set(berkeley.legacy_term_ids()) assert canvas_integrated_term_ids < all_term_ids assert berkeley.sis_term_id_for_name( app.config['EARLIEST_LEGACY_TERM']) in all_term_ids assert berkeley.sis_term_id_for_name( app.config['EARLIEST_TERM']) in all_term_ids assert berkeley.sis_term_id_for_name( app.config['CURRENT_TERM']) in all_term_ids assert berkeley.sis_term_id_for_name( app.config['FUTURE_TERM']) in all_term_ids assert berkeley.current_term_id() in canvas_integrated_term_ids assert berkeley.earliest_term_id() in canvas_integrated_term_ids assert future_term_ids.isdisjoint(canvas_integrated_term_ids) assert future_term_ids < all_term_ids assert berkeley.future_term_id() in future_term_ids assert legacy_term_ids.isdisjoint(canvas_integrated_term_ids) assert legacy_term_ids < all_term_ids assert berkeley.earliest_legacy_term_id() in berkeley.legacy_term_ids()
def get_canvas_site_maps(): canvas_site_map = {} advisee_site_map = {} canvas_sites = queries.get_advisee_enrolled_canvas_sites() for canvas_course_term, canvas_sites_grp in groupby(canvas_sites, operator.itemgetter('canvas_course_term')): sis_term_id = berkeley.sis_term_id_for_name(canvas_course_term) canvas_site_map[sis_term_id] = {} for row in canvas_sites_grp: canvas_site_id = row['canvas_course_id'] sis_sections = row.get('sis_section_ids', []) if sis_sections: # The SIS-derived feeds tend to deliver section IDs as integers rather than strings. sis_sections = [int(s) for s in sis_sections.split(',')] canvas_site_map[sis_term_id][canvas_site_id] = { 'canvasCourseId': row['canvas_course_id'], 'courseName': row.get('canvas_course_name'), 'courseCode': row.get('canvas_course_code'), 'courseTerm': canvas_course_term, 'enrollments': [], 'adviseeEnrollments': [], 'sis_sections': sis_sections, } if not advisee_site_map.get(sis_term_id): advisee_site_map[sis_term_id] = {} sids = row.get('advisee_sids', []) if sids: sids = sids.split(',') for sid in sids: if not advisee_site_map[sis_term_id].get(sid): advisee_site_map[sis_term_id][sid] = [] advisee_site_map[sis_term_id][sid].append({ 'canvas_course_id': canvas_site_id, }) return canvas_site_map, advisee_site_map
def merge_memberships_into_site_map(site_map): # Collect the bCourses enrollments of interest. canvas_enrollments = queries.get_all_enrollments_in_advisee_canvas_sites() for key, group in groupby(canvas_enrollments, key=operator.itemgetter('canvas_course_id')): canvas_site_id = key enrollments = list(group) sis_term_id = berkeley.sis_term_id_for_name(enrollments[0].get('canvas_course_term')) site = site_map.get(sis_term_id, {}).get(canvas_site_id) if site: site['enrollments'] = enrollments else: app.logger.warn(f'Did not find canvas_course_id {canvas_site_id} in site map for term {sis_term_id}') return site_map
def app_config(): current_term_name = app.config['CURRENT_TERM'] current_term_id = sis_term_id_for_name(current_term_name) return tolerant_jsonify({ 'currentEnrollmentTerm': current_term_name, 'currentEnrollmentTermId': int(current_term_id), 'ebEnvironment': app.config['EB_ENVIRONMENT'] if 'EB_ENVIRONMENT' in app.config else None, 'nessieEnv': app.config['NESSIE_ENV'], })
def test_missing_term_name(self): """Returns None for missing term names.""" assert berkeley.sis_term_id_for_name(None) is None
def test_unparseable_term_name(self): """Returns None for unparseable term names.""" assert berkeley.sis_term_id_for_name('Autumn 2061') is None assert berkeley.sis_term_id_for_name('Default Term') is None