def get_active_sis_enrollments_for_user(user_sis_id, roles=[]): canvas = Enrollments(per_page=100) params = {'state': [ENROLLMENT_ACTIVE]} if len(roles): params['type'] = roles enrollments = [] for enrollment in canvas.get_enrollments_for_regid(user_sis_id, params): try: valid_academic_section_sis_id(enrollment.sis_section_id) enrollments.append(enrollment) except CoursePolicyException: continue return enrollments
def test_enrollments_by_regid(self): canvas = Enrollments() enrollments = canvas.get_enrollments_for_regid( "9136CCB8F66711D5BE060004AC494FFE", include_courses=True) self.assertEquals(len(enrollments), 2, "Has 2 canvas enrollments") enrollment = enrollments[0] self.assertEquals(enrollment.course_url, "https://test.canvas.edu/courses/149650") self.assertEquals(enrollment.sis_course_id, "2013-spring-PHYS-121-A") self.assertEquals(enrollment.sws_course_id(), "2013,spring,PHYS,121/A") self.assertEquals(enrollment.sis_user_id, "9136CCB8F66711D5BE060004AC494FFE") self.assertEquals(enrollment.course_name, "MECHANICS") self.assertIsNotNone(enrollment.course) stu_enrollment = enrollments[1] self.assertEquals( stu_enrollment.grade_html_url, "https://test.instructure.com/courses/862539/grades/12345") self.assertEquals(stu_enrollment.current_score, 23.0, "Current score") self.assertEquals(stu_enrollment.login_id, "javerage", "Login ID") self.assertEquals( stu_enrollment.sis_user_id, "9136CCB8F66711D5BE060004AC494FFE", "SIS User ID") self.assertEquals(stu_enrollment.name, "JAMES AVERAGE STUDENT", "Name") self.assertEquals( enrollment.sortable_name, "STUDENT, JAMES AVERAGE", "Sortable Name") self.assertEquals( str(stu_enrollment.last_activity_at), "2012-08-18 23:08:51-06:00", "Last activity datetime") self.assertEquals( stu_enrollment.total_activity_time, 100, "Total activity time") self.assertEquals( stu_enrollment.status, CanvasEnrollment.STATUS_ACTIVE, "Status")