def test_pre_requisites_appear_on_dashboard(self): """ When a course has a prerequisite, the dashboard should display the prerequisite. If we remove the prerequisite and access the dashboard again, the prerequisite should not appear. """ self.pre_requisite_course = CourseFactory.create( org='edx', number='999', display_name='Pre requisite Course') # lint-amnesty, pylint: disable=attribute-defined-outside-init self.course = CourseFactory.create( # lint-amnesty, pylint: disable=attribute-defined-outside-init org='edx', number='998', display_name='Test Course', pre_requisite_courses=[str(self.pre_requisite_course.id)]) self.course_enrollment = CourseEnrollmentFactory( course_id=self.course.id, user=self.user) # lint-amnesty, pylint: disable=attribute-defined-outside-init set_prerequisite_courses(self.course.id, [str(self.pre_requisite_course.id)]) response = self.client.get(reverse('dashboard')) self.assertContains(response, '<div class="prerequisites">') remove_prerequisite_course(self.course.id, get_course_milestones(self.course.id)[0]) response = self.client.get(reverse('dashboard')) self.assertNotContains(response, '<div class="prerequisites">')
def test_course_with_prereq(self): """ Simulate having a course which has closed enrollments that has a pre-req course """ pre_requisite_course = CourseFactory.create( org='edX', course='900', display_name='pre requisite course', emit_signals=True, ) pre_requisite_courses = [six.text_type(pre_requisite_course.id)] # for this failure to occur, the enrollment window needs to be in the past course = CourseFactory.create( org='edX', course='1000', display_name='course that has pre requisite', # closed enrollment enrollment_start=datetime.datetime(2013, 1, 1), enrollment_end=datetime.datetime(2014, 1, 1), start=datetime.datetime(2013, 1, 1), end=datetime.datetime(2030, 1, 1), pre_requisite_courses=pre_requisite_courses, emit_signals=True, ) set_prerequisite_courses(course.id, pre_requisite_courses) resp = self.client.get('/') # make sure both courses are visible in the catalog self.assertContains(resp, 'pre requisite course') self.assertContains(resp, 'course that has pre requisite')
def test_courseware_access(self, api_version): self.login() course_with_prereq = CourseFactory.create(start=self.LAST_WEEK, mobile_available=True) prerequisite_course = CourseFactory.create() set_prerequisite_courses(course_with_prereq.id, [str(prerequisite_course.id)]) # Create list of courses with various expected courseware_access responses and corresponding expected codes courses = [ course_with_prereq, CourseFactory.create(start=self.NEXT_WEEK, mobile_available=True), CourseFactory.create(visible_to_staff_only=True, mobile_available=True), CourseFactory.create(start=self.LAST_WEEK, mobile_available=True, visible_to_staff_only=False), ] expected_error_codes = [ MilestoneAccessError().error_code, # 'unfulfilled_milestones' StartDateError(self.NEXT_WEEK).error_code, # 'course_not_started' VisibilityError().error_code, # 'not_visible_to_user' None, ] # Enroll in all the courses for course in courses: self.enroll(course.id) # Verify courses have the correct response through error code. Last enrolled course is first course in response response = self.api_response(api_version=api_version) for course_index in range(len(courses)): result = response.data[course_index]['course']['courseware_access'] assert result['error_code'] == expected_error_codes[::(- 1)][course_index] if result['error_code'] is not None: assert not result['has_access']
def test_course_milestone_collected(self): student = UserFactory() course = CourseFactory.create(org='edx', number='998', display_name='Test Course') pre_requisite_course = CourseFactory.create( org='edx', number='999', display_name='Pre requisite Course') # set pre-requisite course set_prerequisite_courses(course.id, [str(pre_requisite_course.id)]) # get milestones collected by user before completing the pre-requisite course completed_milestones = milestones_achieved_by_user( student, str(pre_requisite_course.id)) assert len(completed_milestones) == 0 GeneratedCertificateFactory.create( user=student, course_id=pre_requisite_course.id, status=CertificateStatuses.generating, mode='verified') # get milestones collected by user after user has completed the pre-requisite course completed_milestones = milestones_achieved_by_user( student, str(pre_requisite_course.id)) assert len(completed_milestones) == 1 assert completed_milestones[0]['namespace'] == str( pre_requisite_course.id)
def test_courseware_page_unfulfilled_prereqs(self): """ Test courseware access when a course has pre-requisite course yet to be completed """ pre_requisite_course = CourseFactory.create( org='edX', course='900', run='test_run', ) pre_requisite_courses = [str(pre_requisite_course.id)] course = CourseFactory.create( org='edX', course='1000', run='test_run', pre_requisite_courses=pre_requisite_courses, ) set_prerequisite_courses(course.id, pre_requisite_courses) test_password = '******' user = UserFactory.create() user.set_password(test_password) user.save() self.login(user.email, test_password) CourseEnrollmentFactory(user=user, course_id=course.id) url = reverse('courseware', args=[str(course.id)]) response = self.client.get(url) self.assertRedirects(response, reverse('dashboard')) assert response.status_code == 302 fulfill_course_milestone(pre_requisite_course.id, user) response = self.client.get(url) assert response.status_code == 200
def test_access_on_course_with_pre_requisites(self): """ Test course access when a course has pre-requisite course yet to be completed """ user = UserFactory.create() pre_requisite_course = CourseFactory.create(org='test_org', number='788', run='test_run') pre_requisite_courses = [str(pre_requisite_course.id)] course = CourseFactory.create( org='test_org', number='786', run='test_run', pre_requisite_courses=pre_requisite_courses) set_prerequisite_courses(course.id, pre_requisite_courses) # user should not be able to load course even if enrolled CourseEnrollmentFactory(user=user, course_id=course.id) response = access._has_access_course(user, 'load', course) assert not response assert isinstance(response, access_response.MilestoneAccessError) # Staff can always access course staff = StaffFactory.create(course_key=course.id) assert access._has_access_course(staff, 'load', course) # User should be able access after completing required course fulfill_course_milestone(pre_requisite_course.id, user) assert access._has_access_course(user, 'load', course)
def test_course_listing_has_pre_requisite_courses(self): """ Creates four courses. Enroll test user in all courses Sets two of them as pre-requisites of another course. Checks course where pre-requisite course is set has appropriate info. """ course_location2 = self.store.make_course_key('Org1', 'Course2', 'Run2') self._create_course_with_access_groups(course_location2) pre_requisite_course_location = self.store.make_course_key('Org1', 'Course3', 'Run3') self._create_course_with_access_groups(pre_requisite_course_location) pre_requisite_course_location2 = self.store.make_course_key('Org1', 'Course4', 'Run4') self._create_course_with_access_groups(pre_requisite_course_location2) # create a course with pre_requisite_courses pre_requisite_courses = [ str(pre_requisite_course_location), str(pre_requisite_course_location2), ] course_location = self.store.make_course_key('Org1', 'Course1', 'Run1') self._create_course_with_access_groups(course_location, { 'pre_requisite_courses': pre_requisite_courses }) set_prerequisite_courses(course_location, pre_requisite_courses) # get dashboard course_enrollments = list(get_course_enrollments(self.student, None, [])) courses_having_prerequisites = frozenset( enrollment.course_id for enrollment in course_enrollments if enrollment.course_overview.pre_requisite_courses ) courses_requirements_not_met = get_pre_requisite_courses_not_completed( self.student, courses_having_prerequisites ) assert len(courses_requirements_not_met[course_location]['courses']) == len(pre_requisite_courses)
def test_about_page_unfulfilled_prereqs(self): pre_requisite_course = CourseFactory.create( org='edX', course='901', display_name='pre requisite course', ) pre_requisite_courses = [text_type(pre_requisite_course.id)] # for this failure to occur, the enrollment window needs to be in the past course = CourseFactory.create( org='edX', course='1000', # closed enrollment enrollment_start=datetime.datetime(2013, 1, 1), enrollment_end=datetime.datetime(2014, 1, 1), start=datetime.datetime(2013, 1, 1), end=datetime.datetime(2030, 1, 1), pre_requisite_courses=pre_requisite_courses, ) set_prerequisite_courses(course.id, pre_requisite_courses) self.setup_user() self.enroll(self.course, True) self.enroll(pre_requisite_course, True) url = reverse('about_course', args=[text_type(course.id)]) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) pre_requisite_courses = get_prerequisite_courses_display(course) pre_requisite_course_about_url = reverse( 'about_course', args=[text_type(pre_requisite_courses[0]['key'])]) self.assertIn( u"<span class=\"important-dates-item-text pre-requisite\"><a href=\"{}\">{}</a></span>" .format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']), resp.content.decode(resp.charset).strip('\n')) url = reverse('about_course', args=[six.text_type(pre_requisite_course.id)]) resp = self.client.get(url) self.assertEqual(resp.status_code, 200)
def test_about_page_unfulfilled_prereqs(self): pre_requisite_course = CourseFactory.create( org='edX', course='901', display_name='pre requisite course', ) pre_requisite_courses = [str(pre_requisite_course.id)] # for this failure to occur, the enrollment window needs to be in the past course = CourseFactory.create( org='edX', course='1000', # closed enrollment enrollment_start=datetime.datetime(2013, 1, 1), enrollment_end=datetime.datetime(2014, 1, 1), start=datetime.datetime(2013, 1, 1), end=datetime.datetime(2030, 1, 1), pre_requisite_courses=pre_requisite_courses, ) set_prerequisite_courses(course.id, pre_requisite_courses) self.setup_user() self.enroll(self.course, True) self.enroll(pre_requisite_course, True) url = reverse('about_course', args=[str(course.id)]) resp = self.client.get(url) assert resp.status_code == 200 pre_requisite_courses = get_prerequisite_courses_display(course) pre_requisite_course_about_url = reverse( 'about_course', args=[str(pre_requisite_courses[0]['key'])]) assert '<span class="important-dates-item-text pre-requisite"><a href="{}">{}</a></span>'.format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']) in resp.content.decode(resp.charset).strip('\n') # pylint: disable=line-too-long url = reverse('about_course', args=[str(pre_requisite_course.id)]) resp = self.client.get(url) assert resp.status_code == 200