def setUp(self): """ Test case scaffolding """ super(EntranceExamsTabsTestCase, self).setUp() self.course = CourseFactory.create() self.instructor_tab = ItemFactory.create( category="instructor", parent_location=self.course.location, data="Instructor Tab", display_name="Instructor", ) self.extra_tab_2 = ItemFactory.create( category="static_tab", parent_location=self.course.location, data="Extra Tab", display_name="Extra Tab 2", ) self.extra_tab_3 = ItemFactory.create( category="static_tab", parent_location=self.course.location, data="Extra Tab", display_name="Extra Tab 3", ) self.setup_user() self.enroll(self.course) self.user.is_staff = True self.relationship_types = milestones_helpers.get_milestone_relationship_types() milestones_helpers.seed_milestone_relationship_types()
def test_pre_requisite_course_update_and_fetch(self): seed_milestone_relationship_types() url = get_url(self.course.id) resp = self.client.get_json(url) course_detail_json = json.loads(resp.content) # assert pre_requisite_courses is initialized self.assertEqual([], course_detail_json['pre_requisite_courses']) # update pre requisite courses with a new course keys pre_requisite_course = CourseFactory.create(org='edX', course='900', run='test_run') pre_requisite_course2 = CourseFactory.create(org='edX', course='902', run='test_run') pre_requisite_course_keys = [unicode(pre_requisite_course.id), unicode(pre_requisite_course2.id)] course_detail_json['pre_requisite_courses'] = pre_requisite_course_keys self.client.ajax_post(url, course_detail_json) # fetch updated course to assert pre_requisite_courses has new values resp = self.client.get_json(url) course_detail_json = json.loads(resp.content) self.assertEqual(pre_requisite_course_keys, course_detail_json['pre_requisite_courses']) # remove pre requisite course course_detail_json['pre_requisite_courses'] = [] self.client.ajax_post(url, course_detail_json) resp = self.client.get_json(url) course_detail_json = json.loads(resp.content) self.assertEqual([], course_detail_json['pre_requisite_courses'])
def _add_entrance_exam(self): """ Sets up entrance exam """ seed_milestone_relationship_types() self.course.entrance_exam_enabled = True self.entrance_exam = ItemFactory.create( # pylint: disable=attribute-defined-outside-init parent=self.course, category="chapter", display_name="Entrance Exam Chapter", is_entrance_exam=True, in_entrance_exam=True ) self.problem_1 = ItemFactory.create( # pylint: disable=attribute-defined-outside-init parent=self.entrance_exam, category='problem', display_name="The Only Exam Problem", graded=True, in_entrance_exam=True ) add_entrance_exam_milestone(self.course, self.entrance_exam) self.course.entrance_exam_minimum_score_pct = 0.50 self.course.entrance_exam_id = unicode(self.entrance_exam.location) modulestore().update_item(self.course, self.user.id)
def setUp(self): super(ImportEntranceExamTestCase, self).setUp() self.url = reverse_course_url('import_handler', self.course.id) self.content_dir = path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.content_dir) # Create tar test file ----------------------------------------------- # OK course with entrance exam section: seed_milestone_relationship_types() entrance_exam_dir = tempfile.mkdtemp(dir=self.content_dir) # test course being deeper down than top of tar file embedded_exam_dir = os.path.join(entrance_exam_dir, "grandparent", "parent") os.makedirs(os.path.join(embedded_exam_dir, "course")) os.makedirs(os.path.join(embedded_exam_dir, "chapter")) with open(os.path.join(embedded_exam_dir, "course.xml"), "w+") as f: f.write('<course url_name="2013_Spring" org="EDx" course="0.00x"/>') with open(os.path.join(embedded_exam_dir, "course", "2013_Spring.xml"), "w+") as f: f.write( '<course ' 'entrance_exam_enabled="true" entrance_exam_id="xyz" entrance_exam_minimum_score_pct="0.7">' '<chapter url_name="2015_chapter_entrance_exam"/></course>' ) with open(os.path.join(embedded_exam_dir, "chapter", "2015_chapter_entrance_exam.xml"), "w+") as f: f.write('<chapter display_name="Entrance Exam" in_entrance_exam="true" is_entrance_exam="true"></chapter>') self.entrance_exam_tar = os.path.join(self.content_dir, "entrance_exam.tar.gz") with tarfile.open(self.entrance_exam_tar, "w:gz") as gtar: gtar.add(entrance_exam_dir)
def test_courseware_access(self): seed_milestone_relationship_types() 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, [unicode(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 = [ MilestoneError().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() for course_index in range(len(courses)): result = response.data[course_index]['course']['courseware_access'] self.assertEqual(result['error_code'], expected_error_codes[::-1][course_index]) if result['error_code'] is not None: self.assertFalse(result['has_access'])
def test_access_on_course_with_pre_requisites(self): """ Test course access when a course has pre-requisite course yet to be completed """ seed_milestone_relationship_types() user = UserFactory.create() pre_requisite_course = CourseFactory.create(org="test_org", number="788", run="test_run") pre_requisite_courses = [unicode(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_desc(user, "view_courseware_with_prerequisites", course) self.assertFalse(response) self.assertIsInstance(response, access_response.MilestoneError) # Staff can always access course staff = StaffFactory.create(course_key=course.id) self.assertTrue(access._has_access_course_desc(staff, "view_courseware_with_prerequisites", course)) # User should be able access after completing required course fulfill_course_milestone(pre_requisite_course.id, user) self.assertTrue(access._has_access_course_desc(user, "view_courseware_with_prerequisites", 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. """ seed_milestone_relationship_types() 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 = [ unicode(pre_requisite_course_location), unicode(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_enrollment_pairs = list(get_course_enrollment_pairs(self.student, None, [])) courses_having_prerequisites = frozenset(course.id for course, _enrollment in course_enrollment_pairs if course.pre_requisite_courses) courses_requirements_not_met = get_pre_requisite_courses_not_completed( self.student, courses_having_prerequisites ) self.assertEqual(len(courses_requirements_not_met[course_location]['courses']), len(pre_requisite_courses))
def test_courseware_page_unfulfilled_prereqs(self): """ Test courseware access when a course has pre-requisite course yet to be completed """ seed_milestone_relationship_types() pre_requisite_course = CourseFactory.create(org="edX", course="900", run="test_run") pre_requisite_courses = [unicode(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=[unicode(course.id)]) response = self.client.get(url) self.assertRedirects(response, reverse("dashboard")) self.assertEqual(response.status_code, 302) fulfill_course_milestone(pre_requisite_course.id, user) response = self.client.get(url) self.assertEqual(response.status_code, 200)
def setUp(self): """ Shared scaffolding for individual test runs """ super(EntranceExamHandlerTests, self).setUp() self.course_key = self.course.id self.usage_key = self.course.location self.course_url = '/course/{}'.format(unicode(self.course.id)) self.exam_url = '/course/{}/entrance_exam/'.format(unicode(self.course.id)) milestones_helpers.seed_milestone_relationship_types() self.milestone_relationship_types = milestones_helpers.get_milestone_relationship_types()
def test_invalid_pre_requisite_course(self): seed_milestone_relationship_types() url = get_url(self.course.id) resp = self.client.get_json(url) course_detail_json = json.loads(resp.content) # update pre requisite courses one valid and one invalid key pre_requisite_course = CourseFactory.create(org='edX', course='900', run='test_run') pre_requisite_course_keys = [unicode(pre_requisite_course.id), 'invalid_key'] course_detail_json['pre_requisite_courses'] = pre_requisite_course_keys response = self.client.ajax_post(url, course_detail_json) self.assertEqual(400, response.status_code)
def test_pre_requisite_course(self): seed_milestone_relationship_types() pre_requisite_course = CourseFactory.create(org='edX', course='900', display_name='pre requisite course') course = CourseFactory.create(pre_requisite_courses=[unicode(pre_requisite_course.id)]) self.setup_user() url = reverse('about_course', args=[unicode(course.id)]) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) self.assertIn("<span class=\"important-dates-item-text pre-requisite\">{} {}</span>" .format(pre_requisite_course.display_org_with_default, pre_requisite_course.display_number_with_default), resp.content.strip('\n'))
def test_pre_requisite_course(self): seed_milestone_relationship_types() pre_requisite_course = CourseFactory.create(org='edX', course='900', display_name='pre requisite course') course = CourseFactory.create(pre_requisite_courses=[unicode(pre_requisite_course.id)]) self.setup_user() url = reverse('about_course', args=[unicode(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=[unicode(pre_requisite_courses[0]['key'])]) self.assertIn("<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.strip('\n'))
def test_entrance_exam_store_default_min_score(self): """ test that creating an entrance exam should store the default value, if key missing in json request or entrance_exam_minimum_score_pct is an empty string """ seed_milestone_relationship_types() settings_details_url = get_url(self.course.id) test_data_1 = { 'entrance_exam_enabled': 'true', 'syllabus': 'none', 'short_description': 'empty', 'overview': '', 'effort': '', 'intro_video': '' } response = self.client.post( settings_details_url, data=json.dumps(test_data_1), content_type='application/json', HTTP_ACCEPT='application/json' ) self.assertEquals(response.status_code, 200) course = modulestore().get_course(self.course.id) self.assertTrue(course.entrance_exam_enabled) # entrance_exam_minimum_score_pct is not present in the request so default value should be saved. self.assertEquals(course.entrance_exam_minimum_score_pct, .5) #add entrance_exam_minimum_score_pct with empty value in json request. test_data_2 = { 'entrance_exam_enabled': 'true', 'entrance_exam_minimum_score_pct': '', 'syllabus': 'none', 'short_description': 'empty', 'overview': '', 'effort': '', 'intro_video': '' } response = self.client.post( settings_details_url, data=json.dumps(test_data_2), content_type='application/json', HTTP_ACCEPT='application/json' ) self.assertEquals(response.status_code, 200) course = modulestore().get_course(self.course.id) self.assertTrue(course.entrance_exam_enabled) self.assertEquals(course.entrance_exam_minimum_score_pct, .5)
def test_entrance_exam_created_updated_and_deleted_successfully(self): seed_milestone_relationship_types() settings_details_url = get_url(self.course.id) data = { 'entrance_exam_enabled': 'true', 'entrance_exam_minimum_score_pct': '60', 'syllabus': 'none', 'short_description': 'empty', 'overview': '', 'effort': '', 'intro_video': '' } response = self.client.post(settings_details_url, data=json.dumps(data), content_type='application/json', HTTP_ACCEPT='application/json') self.assertEquals(response.status_code, 200) course = modulestore().get_course(self.course.id) self.assertTrue(course.entrance_exam_enabled) self.assertEquals(course.entrance_exam_minimum_score_pct, .60) # Update the entrance exam data['entrance_exam_enabled'] = "true" data['entrance_exam_minimum_score_pct'] = "80" response = self.client.post( settings_details_url, data=json.dumps(data), content_type='application/json', HTTP_ACCEPT='application/json' ) self.assertEquals(response.status_code, 200) course = modulestore().get_course(self.course.id) self.assertTrue(course.entrance_exam_enabled) self.assertEquals(course.entrance_exam_minimum_score_pct, .80) # Delete the entrance exam data['entrance_exam_enabled'] = "false" response = self.client.post( settings_details_url, data=json.dumps(data), content_type='application/json', HTTP_ACCEPT='application/json' ) course = modulestore().get_course(self.course.id) self.assertEquals(response.status_code, 200) self.assertFalse(course.entrance_exam_enabled) self.assertEquals(course.entrance_exam_minimum_score_pct, None)
def test_course_milestone_collected(self): seed_milestone_relationship_types() 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, [unicode(pre_requisite_course.id)]) # get milestones collected by user before completing the pre-requisite course completed_milestones = milestones_achieved_by_user(student, unicode(pre_requisite_course.id)) self.assertEqual(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, unicode(pre_requisite_course.id)) self.assertEqual(len(completed_milestones), 1) self.assertEqual(completed_milestones[0]['namespace'], unicode(pre_requisite_course.id))
def test_about_page_unfulfilled_prereqs(self): seed_milestone_relationship_types() pre_requisite_course = CourseFactory.create( org='edX', course='900', display_name='pre requisite course', ) pre_requisite_courses = [unicode(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=[unicode(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=[unicode(pre_requisite_courses[0]['key'])]) self.assertIn("<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.strip('\n')) url = reverse('about_course', args=[unicode(pre_requisite_course.id)]) resp = self.client.get(url) self.assertEqual(resp.status_code, 200)
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. """ seed_milestone_relationship_types() 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 = [ unicode(pre_requisite_course_location), unicode(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_enrollment_pairs = list( get_course_enrollment_pairs(self.student, None, [])) courses_having_prerequisites = frozenset( course.id for course, _enrollment in course_enrollment_pairs if course.pre_requisite_courses) courses_requirements_not_met = get_pre_requisite_courses_not_completed( self.student, courses_having_prerequisites) self.assertEqual( len(courses_requirements_not_met[course_location]['courses']), len(pre_requisite_courses))
def setUp(self): super(ImportEntranceExamTestCase, self).setUp() self.url = reverse_course_url('import_handler', self.course.id) self.content_dir = path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.content_dir) # Create tar test file ----------------------------------------------- # OK course with entrance exam section: seed_milestone_relationship_types() entrance_exam_dir = tempfile.mkdtemp(dir=self.content_dir) # test course being deeper down than top of tar file embedded_exam_dir = os.path.join(entrance_exam_dir, "grandparent", "parent") os.makedirs(os.path.join(embedded_exam_dir, "course")) os.makedirs(os.path.join(embedded_exam_dir, "chapter")) with open(os.path.join(embedded_exam_dir, "course.xml"), "w+") as f: f.write( '<course url_name="2013_Spring" org="EDx" course="0.00x"/>') with open(os.path.join(embedded_exam_dir, "course", "2013_Spring.xml"), "w+") as f: f.write( '<course ' 'entrance_exam_enabled="true" entrance_exam_id="xyz" entrance_exam_minimum_score_pct="0.7">' '<chapter url_name="2015_chapter_entrance_exam"/></course>') with open( os.path.join(embedded_exam_dir, "chapter", "2015_chapter_entrance_exam.xml"), "w+") as f: f.write( '<chapter display_name="Entrance Exam" in_entrance_exam="true" is_entrance_exam="true"></chapter>' ) self.entrance_exam_tar = os.path.join(self.content_dir, "entrance_exam.tar.gz") with tarfile.open(self.entrance_exam_tar, "w:gz") as gtar: gtar.add(entrance_exam_dir)
def test_access_on_course_with_pre_requisites(self): """ Test course access when a course has pre-requisite course yet to be completed """ seed_milestone_relationship_types() user = UserFactory.create() pre_requisite_course = CourseFactory.create(org='test_org', number='788', run='test_run') pre_requisite_courses = [unicode(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_desc( user, 'view_courseware_with_prerequisites', course) self.assertFalse(response) self.assertIsInstance(response, access_response.MilestoneError) # Staff can always access course staff = StaffFactory.create(course_key=course.id) self.assertTrue( access._has_access_course_desc( staff, 'view_courseware_with_prerequisites', course)) # User should be able access after completing required course fulfill_course_milestone(pre_requisite_course.id, user) self.assertTrue( access._has_access_course_desc( user, 'view_courseware_with_prerequisites', course))
def setUp(self): seed_milestone_relationship_types()
def _add_prerequisite_course(self): """ Helper method to set up the prerequisite course """ seed_milestone_relationship_types() self.prereq_course = CourseFactory.create() # pylint: disable=attribute-defined-outside-init add_prerequisite_course(self.course.id, self.prereq_course.id)
def setUp(self): """ Test case scaffolding """ super(EntranceExamTestCases, self).setUp() self.course = CourseFactory.create(metadata={"entrance_exam_enabled": True}) self.chapter = ItemFactory.create(parent=self.course, display_name="Overview") ItemFactory.create(parent=self.chapter, display_name="Welcome") ItemFactory.create(parent=self.course, category="chapter", display_name="Week 1") self.chapter_subsection = ItemFactory.create( parent=self.chapter, category="sequential", display_name="Lesson 1" ) chapter_vertical = ItemFactory.create( parent=self.chapter_subsection, category="vertical", display_name="Lesson 1 Vertical - Unit 1" ) ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 1") ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 2") ItemFactory.create(category="instructor", parent=self.course, data="Instructor Tab", display_name="Instructor") self.entrance_exam = ItemFactory.create( parent=self.course, category="chapter", display_name="Entrance Exam Section - Chapter 1", is_entrance_exam=True, in_entrance_exam=True, ) self.exam_1 = ItemFactory.create( parent=self.entrance_exam, category="sequential", display_name="Exam Sequential - Subsection 1", graded=True, in_entrance_exam=True, ) subsection = ItemFactory.create(parent=self.exam_1, category="vertical", display_name="Exam Vertical - Unit 1") self.problem_1 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 1" ) self.problem_2 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 2" ) seed_milestone_relationship_types() add_entrance_exam_milestone(self.course, self.entrance_exam) self.course.entrance_exam_enabled = True self.course.entrance_exam_minimum_score_pct = 0.50 self.course.entrance_exam_id = unicode(self.entrance_exam.scope_ids.usage_id) self.anonymous_user = AnonymousUserFactory() self.request = get_request_for_user(UserFactory()) modulestore().update_item(self.course, self.request.user.id) # pylint: disable=no-member self.client.login(username=self.request.user.username, password="******") CourseEnrollment.enroll(self.request.user, self.course.id) self.expected_locked_toc = [ { "active": True, "sections": [ { "url_name": u"Exam_Sequential_-_Subsection_1", "display_name": u"Exam Sequential - Subsection 1", "graded": True, "format": "", "due": None, "active": True, } ], "url_name": u"Entrance_Exam_Section_-_Chapter_1", "display_name": u"Entrance Exam Section - Chapter 1", } ] self.expected_unlocked_toc = [ { "active": False, "sections": [ { "url_name": u"Welcome", "display_name": u"Welcome", "graded": False, "format": "", "due": None, "active": False, }, { "url_name": u"Lesson_1", "display_name": u"Lesson 1", "graded": False, "format": "", "due": None, "active": False, }, ], "url_name": u"Overview", "display_name": u"Overview", }, {"active": False, "sections": [], "url_name": u"Week_1", "display_name": u"Week 1"}, {"active": False, "sections": [], "url_name": u"Instructor", "display_name": u"Instructor"}, { "active": True, "sections": [ { "url_name": u"Exam_Sequential_-_Subsection_1", "display_name": u"Exam Sequential - Subsection 1", "graded": True, "format": "", "due": None, "active": True, } ], "url_name": u"Entrance_Exam_Section_-_Chapter_1", "display_name": u"Entrance Exam Section - Chapter 1", }, ]
def setUp(self): """ Test case scaffolding """ super(EntranceExamTestCases, self).setUp() self.course = CourseFactory.create( metadata={ 'entrance_exam_enabled': True, } ) self.chapter = ItemFactory.create( parent=self.course, display_name='Overview' ) ItemFactory.create( parent=self.chapter, display_name='Welcome' ) ItemFactory.create( parent=self.course, category='chapter', display_name="Week 1" ) self.chapter_subsection = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Lesson 1" ) chapter_vertical = ItemFactory.create( parent=self.chapter_subsection, category='vertical', display_name='Lesson 1 Vertical - Unit 1' ) ItemFactory.create( parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 1" ) ItemFactory.create( parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 2" ) ItemFactory.create( category="instructor", parent=self.course, data="Instructor Tab", display_name="Instructor" ) self.entrance_exam = ItemFactory.create( parent=self.course, category="chapter", display_name="Entrance Exam Section - Chapter 1", is_entrance_exam=True, in_entrance_exam=True ) self.exam_1 = ItemFactory.create( parent=self.entrance_exam, category='sequential', display_name="Exam Sequential - Subsection 1", graded=True, in_entrance_exam=True ) subsection = ItemFactory.create( parent=self.exam_1, category='vertical', display_name='Exam Vertical - Unit 1' ) self.problem_1 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 1" ) self.problem_2 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 2" ) self.problem_3 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 3" ) if settings.FEATURES.get('ENTRANCE_EXAMS', False): namespace_choices = milestones_helpers.get_namespace_choices() milestone_namespace = milestones_helpers.generate_milestone_namespace( namespace_choices.get('ENTRANCE_EXAM'), self.course.id ) self.milestone = { 'name': 'Test Milestone', 'namespace': milestone_namespace, 'description': 'Testing Courseware Entrance Exam Chapter', } milestones_helpers.seed_milestone_relationship_types() self.milestone_relationship_types = milestones_helpers.get_milestone_relationship_types() self.milestone = milestones_helpers.add_milestone(self.milestone) milestones_helpers.add_course_milestone( unicode(self.course.id), self.milestone_relationship_types['REQUIRES'], self.milestone ) milestones_helpers.add_course_content_milestone( unicode(self.course.id), unicode(self.entrance_exam.location), self.milestone_relationship_types['FULFILLS'], self.milestone ) user = UserFactory() self.request = RequestFactory() self.request.user = user self.request.COOKIES = {} self.request.META = {} self.request.is_secure = lambda: True self.request.get_host = lambda: "edx.org" self.request.method = 'GET' self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents( self.course.id, user, self.entrance_exam ) self.course.entrance_exam_enabled = True self.course.entrance_exam_minimum_score_pct = 0.50 self.course.entrance_exam_id = unicode(self.entrance_exam.scope_ids.usage_id) modulestore().update_item(self.course, user.id) # pylint: disable=no-member self.client.login(username=self.request.user.username, password="******") CourseEnrollment.enroll(self.request.user, self.course.id) self.expected_locked_toc = ( [ { 'active': True, 'sections': [ { 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True } ], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1' } ] ) self.expected_unlocked_toc = ( [ { 'active': False, 'sections': [ { 'url_name': u'Welcome', 'display_name': u'Welcome', 'graded': False, 'format': '', 'due': None, 'active': False }, { 'url_name': u'Lesson_1', 'display_name': u'Lesson 1', 'graded': False, 'format': '', 'due': None, 'active': False } ], 'url_name': u'Overview', 'display_name': u'Overview' }, { 'active': False, 'sections': [], 'url_name': u'Week_1', 'display_name': u'Week 1' }, { 'active': False, 'sections': [], 'url_name': u'Instructor', 'display_name': u'Instructor' }, { 'active': True, 'sections': [ { 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True } ], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1' } ] )
def setUp(self): """ Test case scaffolding """ super(EntranceExamTestCases, self).setUp() self.course = CourseFactory.create( metadata={ 'entrance_exam_enabled': True, } ) self.chapter = ItemFactory.create( parent=self.course, display_name='Overview' ) ItemFactory.create( parent=self.chapter, display_name='Welcome' ) ItemFactory.create( parent=self.course, category='chapter', display_name="Week 1" ) self.chapter_subsection = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Lesson 1" ) chapter_vertical = ItemFactory.create( parent=self.chapter_subsection, category='vertical', display_name='Lesson 1 Vertical - Unit 1' ) ItemFactory.create( parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 1" ) ItemFactory.create( parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 2" ) ItemFactory.create( category="instructor", parent=self.course, data="Instructor Tab", display_name="Instructor" ) self.entrance_exam = ItemFactory.create( parent=self.course, category="chapter", display_name="Entrance Exam Section - Chapter 1", is_entrance_exam=True, in_entrance_exam=True ) self.exam_1 = ItemFactory.create( parent=self.entrance_exam, category='sequential', display_name="Exam Sequential - Subsection 1", graded=True, in_entrance_exam=True ) subsection = ItemFactory.create( parent=self.exam_1, category='vertical', display_name='Exam Vertical - Unit 1' ) self.problem_1 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 1" ) self.problem_2 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 2" ) seed_milestone_relationship_types() add_entrance_exam_milestone(self.course, self.entrance_exam) self.course.entrance_exam_enabled = True self.course.entrance_exam_minimum_score_pct = 0.50 self.course.entrance_exam_id = unicode(self.entrance_exam.scope_ids.usage_id) self.anonymous_user = AnonymousUserFactory() self.request = get_request_for_user(UserFactory()) modulestore().update_item(self.course, self.request.user.id) # pylint: disable=no-member self.client.login(username=self.request.user.username, password="******") CourseEnrollment.enroll(self.request.user, self.course.id) self.expected_locked_toc = ( [ { 'active': True, 'sections': [ { 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True } ], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1', 'display_id': u'entrance-exam-section-chapter-1', } ] ) self.expected_unlocked_toc = ( [ { 'active': False, 'sections': [ { 'url_name': u'Welcome', 'display_name': u'Welcome', 'graded': False, 'format': '', 'due': None, 'active': False }, { 'url_name': u'Lesson_1', 'display_name': u'Lesson 1', 'graded': False, 'format': '', 'due': None, 'active': False } ], 'url_name': u'Overview', 'display_name': u'Overview', 'display_id': u'overview' }, { 'active': False, 'sections': [], 'url_name': u'Week_1', 'display_name': u'Week 1', 'display_id': u'week-1' }, { 'active': False, 'sections': [], 'url_name': u'Instructor', 'display_name': u'Instructor', 'display_id': u'instructor' }, { 'active': True, 'sections': [ { 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True } ], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1', 'display_id': u'entrance-exam-section-chapter-1' } ] )
def test_pre_requisite_course_list_present(self): seed_milestone_relationship_types() settings_details_url = get_url(self.course.id) response = self.client.get_html(settings_details_url) self.assertContains(response, "Prerequisite Course")
def setUp(self): """ Test case scaffolding """ super(EntranceExamTestCases, self).setUp() self.course = CourseFactory.create(metadata={ 'entrance_exam_enabled': True, }) self.chapter = ItemFactory.create(parent=self.course, display_name='Overview') ItemFactory.create(parent=self.chapter, display_name='Welcome') ItemFactory.create(parent=self.course, category='chapter', display_name="Week 1") self.chapter_subsection = ItemFactory.create(parent=self.chapter, category='sequential', display_name="Lesson 1") chapter_vertical = ItemFactory.create( parent=self.chapter_subsection, category='vertical', display_name='Lesson 1 Vertical - Unit 1') ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 1") ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 2") ItemFactory.create(category="instructor", parent=self.course, data="Instructor Tab", display_name="Instructor") self.entrance_exam = ItemFactory.create( parent=self.course, category="chapter", display_name="Entrance Exam Section - Chapter 1", is_entrance_exam=True, in_entrance_exam=True) self.exam_1 = ItemFactory.create( parent=self.entrance_exam, category='sequential', display_name="Exam Sequential - Subsection 1", graded=True, in_entrance_exam=True) subsection = ItemFactory.create(parent=self.exam_1, category='vertical', display_name='Exam Vertical - Unit 1') self.problem_1 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 1") self.problem_2 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 2") seed_milestone_relationship_types() add_entrance_exam_milestone(self.course, self.entrance_exam) self.course.entrance_exam_enabled = True self.course.entrance_exam_minimum_score_pct = 0.50 self.course.entrance_exam_id = unicode( self.entrance_exam.scope_ids.usage_id) self.anonymous_user = AnonymousUserFactory() self.request = get_request_for_user(UserFactory()) modulestore().update_item(self.course, self.request.user.id) # pylint: disable=no-member self.client.login(username=self.request.user.username, password="******") CourseEnrollment.enroll(self.request.user, self.course.id) self.expected_locked_toc = ([{ 'active': True, 'sections': [{ 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True }], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1', 'display_id': u'entrance-exam-section-chapter-1', }]) self.expected_unlocked_toc = ([{ 'active': False, 'sections': [{ 'url_name': u'Welcome', 'display_name': u'Welcome', 'graded': False, 'format': '', 'due': None, 'active': False }, { 'url_name': u'Lesson_1', 'display_name': u'Lesson 1', 'graded': False, 'format': '', 'due': None, 'active': False }], 'url_name': u'Overview', 'display_name': u'Overview', 'display_id': u'overview' }, { 'active': False, 'sections': [], 'url_name': u'Week_1', 'display_name': u'Week 1', 'display_id': u'week-1' }, { 'active': False, 'sections': [], 'url_name': u'Instructor', 'display_name': u'Instructor', 'display_id': u'instructor' }, { 'active': True, 'sections': [{ 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True }], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1', 'display_id': u'entrance-exam-section-chapter-1' }])
def setUp(self): super(PreRequisiteCourseCatalog, self).setUp() seed_milestone_relationship_types()
def setUp(self): """ Test case scaffolding """ super(EntranceExamTestCases, self).setUp() self.course = CourseFactory.create(metadata={ 'entrance_exam_enabled': True, }) self.chapter = ItemFactory.create(parent=self.course, display_name='Overview') ItemFactory.create(parent=self.chapter, display_name='Welcome') ItemFactory.create(parent=self.course, category='chapter', display_name="Week 1") self.chapter_subsection = ItemFactory.create(parent=self.chapter, category='sequential', display_name="Lesson 1") chapter_vertical = ItemFactory.create( parent=self.chapter_subsection, category='vertical', display_name='Lesson 1 Vertical - Unit 1') ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 1") ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 2") ItemFactory.create(category="instructor", parent=self.course, data="Instructor Tab", display_name="Instructor") self.entrance_exam = ItemFactory.create( parent=self.course, category="chapter", display_name="Entrance Exam Section - Chapter 1", is_entrance_exam=True, in_entrance_exam=True) self.exam_1 = ItemFactory.create( parent=self.entrance_exam, category='sequential', display_name="Exam Sequential - Subsection 1", graded=True, in_entrance_exam=True) subsection = ItemFactory.create(parent=self.exam_1, category='vertical', display_name='Exam Vertical - Unit 1') self.problem_1 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 1") self.problem_2 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 2") self.problem_3 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 3") if settings.FEATURES.get('ENTRANCE_EXAMS', False): namespace_choices = milestones_helpers.get_namespace_choices() milestone_namespace = milestones_helpers.generate_milestone_namespace( namespace_choices.get('ENTRANCE_EXAM'), self.course.id) self.milestone = { 'name': 'Test Milestone', 'namespace': milestone_namespace, 'description': 'Testing Courseware Entrance Exam Chapter', } milestones_helpers.seed_milestone_relationship_types() self.milestone_relationship_types = milestones_helpers.get_milestone_relationship_types( ) self.milestone = milestones_helpers.add_milestone(self.milestone) milestones_helpers.add_course_milestone( unicode(self.course.id), self.milestone_relationship_types['REQUIRES'], self.milestone) milestones_helpers.add_course_content_milestone( unicode(self.course.id), unicode(self.entrance_exam.location), self.milestone_relationship_types['FULFILLS'], self.milestone) user = UserFactory() self.request = RequestFactory() self.request.user = user self.request.COOKIES = {} self.request.META = {} self.request.is_secure = lambda: True self.request.get_host = lambda: "edx.org" self.request.method = 'GET' self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents( self.course.id, user, self.entrance_exam) self.course.entrance_exam_enabled = True self.course.entrance_exam_minimum_score_pct = 0.50 self.course.entrance_exam_id = unicode( self.entrance_exam.scope_ids.usage_id) modulestore().update_item(self.course, user.id) # pylint: disable=no-member self.client.login(username=self.request.user.username, password="******") CourseEnrollment.enroll(self.request.user, self.course.id) self.expected_locked_toc = ([{ 'active': True, 'sections': [{ 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True }], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1' }]) self.expected_unlocked_toc = ([{ 'active': False, 'sections': [{ 'url_name': u'Welcome', 'display_name': u'Welcome', 'graded': False, 'format': '', 'due': None, 'active': False }, { 'url_name': u'Lesson_1', 'display_name': u'Lesson 1', 'graded': False, 'format': '', 'due': None, 'active': False }], 'url_name': u'Overview', 'display_name': u'Overview' }, { 'active': False, 'sections': [], 'url_name': u'Week_1', 'display_name': u'Week 1' }, { 'active': False, 'sections': [], 'url_name': u'Instructor', 'display_name': u'Instructor' }, { 'active': True, 'sections': [{ 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True }], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1' }])