def test_create_unused_courses_report(self, mock_post): canvas = Reports() canvas.create_unused_courses_report('12345', term_id='2015-summer') mock_post.assert_called_with( '/api/v1/accounts/12345/reports/unused_courses_csv', {'parameters': { 'enrollment_term_id': '2015-summer' }})
def get_unused_course_report_data(term_sis_id): term = Terms().get_term_by_sis_id(term_sis_id) account_id = getattr(settings, 'RESTCLIENTS_CANVAS_ACCOUNT_ID', None) reports = Reports() unused_course_report = reports.create_unused_courses_report( account_id, term_id=term.term_id) report_data = reports.get_report_data(unused_course_report) reports.delete_report(unused_course_report) return report_data
def get_active_courses_for_term(term, account_id=None): if account_id is None: account_id = getattr(settings, 'RESTCLIENTS_CANVAS_ACCOUNT_ID', None) canvas_term = get_term_by_sis_id(term.canvas_sis_id()) reports = Reports() # Canvas report of "unused" courses for the term unused_course_report = reports.create_unused_courses_report( account_id, canvas_term.term_id) unused_courses = {} for row in reader(reports.get_report_data(unused_course_report)): try: sis_course_id = row[1] valid_academic_course_sis_id(sis_course_id) unused_courses[sis_course_id] = True except (IndexError, CoursePolicyException): pass # Canvas report of all courses for the term all_course_report = reports.create_course_provisioning_report( account_id, canvas_term.term_id) active_courses = [] for row in reader(reports.get_report_data(all_course_report)): try: sis_course_id = row[1] valid_academic_course_sis_id(sis_course_id) if sis_course_id not in unused_courses: active_courses.append(sis_course_id) except (IndexError, CoursePolicyException): pass reports.delete_report(unused_course_report) reports.delete_report(all_course_report) return active_courses