def test_course_grade_considers_subsection_grade_visibility( self, is_staff, expected_percent): """ Verify that the grade & is_passing info we send out is for visible grades only. Assumes that grading policy is the default one (search for DEFAULT_GRADING_POLICY). """ if is_staff: self.switch_to_staff() CourseEnrollment.enroll(self.user, self.course.id) tomorrow = now() + timedelta(days=1) with self.store.bulk_operations(self.course.id): never = self.add_subsection_with_problem(format='Homework', show_correctness='never') always = self.add_subsection_with_problem( format='Midterm Exam', show_correctness='always') past_due = self.add_subsection_with_problem( format='Final Exam', show_correctness='past_due', due=tomorrow) answer_problem(self.course, get_mock_request(self.user), never) answer_problem(self.course, get_mock_request(self.user), always) answer_problem(self.course, get_mock_request(self.user), past_due) # First, confirm the grade in the database - it should never change based on user state. # This is midterm and final and a single problem added together. assert CourseGradeFactory().read(self.user, self.course).percent == 0.72 response = self.client.get(self.url) assert response.status_code == 200 assert response.data['course_grade']['percent'] == expected_percent assert response.data['course_grade']['is_passing'] == (expected_percent >= 0.5)
def test_course_tabs_staff_only(self): """ Tests the static tabs that available only for instructor """ self.course.tabs.append(xmodule_tabs.CourseTab.load('static_tab', name='Static Tab Free', url_slug='extra_tab_1', course_staff_only=False)) self.course.tabs.append(xmodule_tabs.CourseTab.load('static_tab', name='Static Tab Instructors Only', url_slug='extra_tab_2', course_staff_only=True)) self.course.save() user = self.create_mock_user(is_authenticated=True, is_staff=False, is_enrolled=True) request = get_mock_request(user) course_tab_list = get_course_tab_list(request, self.course) name_list = [x.name for x in course_tab_list] self.assertIn('Static Tab Free', name_list) self.assertNotIn('Static Tab Instructors Only', name_list) # Login as member of staff self.client.logout() staff_user = StaffFactory(course_key=self.course.id) self.client.login(username=staff_user.username, password='******') request = get_mock_request(staff_user) course_tab_list_staff = get_course_tab_list(request, self.course) name_list_staff = [x.name for x in course_tab_list_staff] self.assertIn('Static Tab Free', name_list_staff) self.assertIn('Static Tab Instructors Only', name_list_staff)
def test_course_tabs_staff_only(self): """ Tests the static tabs that available only for instructor """ self.course.tabs.append(xmodule_tabs.CourseTab.load('static_tab', name='Static Tab Free', url_slug='extra_tab_1', course_staff_only=False)) self.course.tabs.append(xmodule_tabs.CourseTab.load('static_tab', name='Static Tab Instructors Only', url_slug='extra_tab_2', course_staff_only=True)) self.course.save() user = self.create_mock_user(is_authenticated=True, is_staff=False, is_enrolled=True) request = get_mock_request(user) course_tab_list = get_course_tab_list(request, self.course) name_list = [x.name for x in course_tab_list] self.assertIn('Static Tab Free', name_list) self.assertNotIn('Static Tab Instructors Only', name_list) # Login as member of staff self.client.logout() staff_user = StaffFactory(course_key=self.course.id) self.client.login(username=staff_user.username, password='******') request = get_mock_request(staff_user) course_tab_list_staff = get_course_tab_list(request, self.course) name_list_staff = [x.name for x in course_tab_list_staff] self.assertIn('Static Tab Free', name_list_staff) self.assertIn('Static Tab Instructors Only', name_list_staff)
def users_and_problem_setup(self): self.chapter = ItemFactory.create( parent=self.course, category="chapter", display_name="Test Chapter" ) self.sequence = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Test Sequential 1", graded=True, format="Homework" ) self.vertical = ItemFactory.create( parent=self.sequence, category='vertical', display_name='Test Vertical 1' ) problem_xml = MultipleChoiceResponseXMLFactory().build_xml( question_text='The correct answer is Choice 3', choices=[False, False, True, False], choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3'] ) self.problem = ItemFactory.create( parent=self.vertical, category="problem", display_name="Test Problem", data=problem_xml ) self.user2 = UserFactory.create(username='******', password='******') self.user3 = UserFactory.create(username='******', password='******') self.request = get_mock_request(self.user)
def setUp(self): super(TestVariedMetadata, self).setUp() self.course = CourseFactory.create() with self.store.bulk_operations(self.course.id): self.chapter = ItemFactory.create(parent=self.course, category="chapter", display_name="Test Chapter") self.sequence = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Test Sequential 1", graded=True) self.vertical = ItemFactory.create(parent=self.sequence, category='vertical', display_name='Test Vertical 1') self.problem_xml = u''' <problem url_name="capa-optionresponse"> <optionresponse> <optioninput options="('Correct', 'Incorrect')" correct="Correct"></optioninput> <optioninput options="('Correct', 'Incorrect')" correct="Correct"></optioninput> </optionresponse> </problem> ''' self.request = get_mock_request(UserFactory()) self.client.login(username=self.request.user.username, password="******") CourseEnrollment.enroll(self.request.user, self.course.id)
def setUp(self): super(TestSafeSessionMiddleware, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory.create() self.addCleanup(set_current_request, None) self.request = get_mock_request() self.client.response = HttpResponse() self.client.response.cookies = SimpleCookie()
def setUp(self): super(TestGatedContent, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.setup_gating_milestone(50, 100) self.non_staff_user = UserFactory() self.staff_user = UserFactory(is_staff=True, is_superuser=True) self.addCleanup(set_current_request, None) self.request = get_mock_request(self.non_staff_user)
def setUp(self): super(GradeTestBase, self).setUp() self.request = get_mock_request(UserFactory()) self.client.login(username=self.request.user.username, password="******") self.course_structure = get_course_blocks(self.request.user, self.course.location) self.subsection_grade_factory = SubsectionGradeFactory(self.request.user, self.course, self.course_structure) CourseEnrollment.enroll(self.request.user, self.course.id)
def setUpClass(cls): super(TestStudentModuleGrading, cls).setUpClass() cls.course = CourseFactory.create() cls.chapter = ItemFactory.create( parent=cls.course, category="chapter", display_name="Test Chapter" ) cls.sequence = ItemFactory.create( parent=cls.chapter, category='sequential', display_name="Test Sequential 1", graded=True ) cls.vertical = ItemFactory.create( parent=cls.sequence, category='vertical', display_name='Test Vertical 1' ) problem_xml = MultipleChoiceResponseXMLFactory().build_xml( question_text='The correct answer is Choice 3', choices=[False, False, True, False], choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3'] ) cls.problem = ItemFactory.create( parent=cls.vertical, category="problem", display_name="Test Problem", data=problem_xml ) cls.request = get_mock_request(UserFactory()) cls.user = cls.request.user cls.instructor = UserFactory(username='******', is_staff=True)
def setUpClass(cls): super(TestScoreForModule, cls).setUpClass() cls.course = CourseFactory.create() cls.a = ItemFactory.create(parent=cls.course, category="chapter", display_name="a") cls.b = ItemFactory.create(parent=cls.a, category="sequential", display_name="b") cls.c = ItemFactory.create(parent=cls.a, category="sequential", display_name="c") cls.d = ItemFactory.create(parent=cls.b, category="vertical", display_name="d") cls.e = ItemFactory.create(parent=cls.b, category="vertical", display_name="e") cls.f = ItemFactory.create(parent=cls.b, category="vertical", display_name="f") cls.g = ItemFactory.create(parent=cls.c, category="vertical", display_name="g") cls.h = ItemFactory.create(parent=cls.d, category="problem", display_name="h") cls.i = ItemFactory.create(parent=cls.d, category="problem", display_name="i") cls.j = ItemFactory.create(parent=cls.e, category="problem", display_name="j") cls.k = ItemFactory.create(parent=cls.e, category="html", display_name="k") cls.l = ItemFactory.create(parent=cls.e, category="problem", display_name="l") cls.m = ItemFactory.create(parent=cls.f, category="html", display_name="m") cls.n = ItemFactory.create(parent=cls.g, category="problem", display_name="n") cls.request = get_mock_request(UserFactory()) CourseEnrollment.enroll(cls.request.user, cls.course.id) answer_problem(cls.course, cls.request, cls.h, score=2, max_value=5) answer_problem(cls.course, cls.request, cls.i, score=3, max_value=5) answer_problem(cls.course, cls.request, cls.j, score=0, max_value=1) answer_problem(cls.course, cls.request, cls.l, score=1, max_value=3) answer_problem(cls.course, cls.request, cls.n, score=3, max_value=10) cls.course_grade = CourseGradeFactory(cls.request.user).create(cls.course)
def setUp(self): super(TestMultipleProblemTypesSubsectionScores, self).setUp() password = u'test' self.student = UserFactory.create(is_staff=False, username=u'test_student', password=password) self.client.login(username=self.student.username, password=password) self.request = get_mock_request(self.student) self.course_structure = get_course_blocks(self.student, self.course.location)
def setUp(self): super(TestVariedMetadata, self).setUp() self.course = CourseFactory.create() with self.store.bulk_operations(self.course.id): self.chapter = ItemFactory.create( parent=self.course, category="chapter", display_name="Test Chapter" ) self.sequence = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Test Sequential 1", graded=True ) self.vertical = ItemFactory.create( parent=self.sequence, category='vertical', display_name='Test Vertical 1' ) self.problem_xml = u''' <problem url_name="capa-optionresponse"> <optionresponse> <optioninput options="('Correct', 'Incorrect')" correct="Correct"></optioninput> <optioninput options="('Correct', 'Incorrect')" correct="Correct"></optioninput> </optionresponse> </problem> ''' self.addCleanup(set_current_request, None) self.request = get_mock_request(UserFactory()) self.client.login(username=self.request.user.username, password="******") CourseEnrollment.enroll(self.request.user, self.course.id)
def setUp(self): super().setUp() self.setup_gating_milestone(50, 100) self.non_staff_user = UserFactory() self.staff_user = UserFactory(is_staff=True, is_superuser=True) self.addCleanup(set_current_request, None) self.request = get_mock_request(self.non_staff_user)
def setUp(self): super(TestGatedContent, self).setUp() self.setup_gating_milestone(50, 100) self.non_staff_user = UserFactory() self.staff_user = UserFactory(is_staff=True, is_superuser=True) self.addCleanup(set_current_request, None) self.request = get_mock_request(self.non_staff_user)
def setUp(self): super(TestSafeSessionProcessResponse, self).setUp() self.user = UserFactory.create() self.request = get_mock_request() self.request.session = {} self.client.response = HttpResponse() self.client.response.cookies = SimpleCookie()
def test_invalid_course_key(self): self.setup_user() request = get_mock_request(self.user) with self.assertRaises(Http404): StaticCourseTabView().get(request, course_id='edX/toy', tab_slug='new_tab')
def setUpClass(cls): super(TestStudentModuleGrading, cls).setUpClass() cls.course = CourseFactory.create() cls.chapter = ItemFactory.create( parent=cls.course, category="chapter", display_name="Test Chapter" ) cls.sequence = ItemFactory.create( parent=cls.chapter, category='sequential', display_name="Test Sequential 1", graded=True ) cls.vertical = ItemFactory.create( parent=cls.sequence, category='vertical', display_name='Test Vertical 1' ) problem_xml = MultipleChoiceResponseXMLFactory().build_xml( question_text='The correct answer is Choice 3', choices=[False, False, True, False], choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3'] ) cls.problem = ItemFactory.create( parent=cls.vertical, category="problem", display_name="Test Problem", data=problem_xml ) cls.request = get_mock_request(UserFactory()) cls.user = cls.request.user cls.instructor = UserFactory(username='******', is_staff=True)
def test_get_course_tabs_list_entrance_exam_enabled(self): """ Unit Test: test_get_course_tabs_list_entrance_exam_enabled """ entrance_exam = ItemFactory.create( category="chapter", parent_location=self.course.location, data="Exam Data", display_name="Entrance Exam", is_entrance_exam=True) milestone = { 'name': 'Test Milestone', 'namespace': '{}.entrance_exams'.format(unicode(self.course.id)), 'description': 'Testing Courseware Tabs' } self.user.is_staff = False request = get_mock_request(self.user) self.course.entrance_exam_enabled = True self.course.entrance_exam_id = unicode(entrance_exam.location) milestone = add_milestone(milestone) add_course_milestone(unicode(self.course.id), self.relationship_types['REQUIRES'], milestone) add_course_content_milestone(unicode(self.course.id), unicode(entrance_exam.location), self.relationship_types['FULFILLS'], milestone) course_tab_list = get_course_tab_list(request, self.course) self.assertEqual(len(course_tab_list), 1) self.assertEqual(course_tab_list[0]['tab_id'], 'courseware') self.assertEqual(course_tab_list[0]['name'], 'Entrance Exam')
def setUp(self): super(TestMultipleProblemTypesSubsectionScores, self).setUp() password = u'test' self.student = UserFactory.create(is_staff=False, username=u'test_student', password=password) self.client.login(username=self.student.username, password=password) self.request = get_mock_request(self.student) self.course_structure = get_course_blocks(self.student, self.course.location)
def setUpClass(cls): super(TestScoreForModule, cls).setUpClass() cls.course = CourseFactory.create() with cls.store.bulk_operations(cls.course.id): cls.a = ItemFactory.create(parent=cls.course, category="chapter", display_name="a") cls.b = ItemFactory.create(parent=cls.a, category="sequential", display_name="b") cls.c = ItemFactory.create(parent=cls.a, category="sequential", display_name="c") cls.d = ItemFactory.create(parent=cls.b, category="vertical", display_name="d") cls.e = ItemFactory.create(parent=cls.b, category="vertical", display_name="e") cls.f = ItemFactory.create(parent=cls.b, category="vertical", display_name="f") cls.g = ItemFactory.create(parent=cls.c, category="vertical", display_name="g") cls.h = ItemFactory.create(parent=cls.d, category="problem", display_name="h") cls.i = ItemFactory.create(parent=cls.d, category="problem", display_name="i") cls.j = ItemFactory.create(parent=cls.e, category="problem", display_name="j") cls.k = ItemFactory.create(parent=cls.e, category="html", display_name="k") cls.l = ItemFactory.create(parent=cls.e, category="problem", display_name="l") cls.m = ItemFactory.create(parent=cls.f, category="html", display_name="m") cls.n = ItemFactory.create(parent=cls.g, category="problem", display_name="n") cls.request = get_mock_request(UserFactory()) CourseEnrollment.enroll(cls.request.user, cls.course.id) answer_problem(cls.course, cls.request, cls.h, score=2, max_value=5) answer_problem(cls.course, cls.request, cls.i, score=3, max_value=5) answer_problem(cls.course, cls.request, cls.j, score=0, max_value=1) answer_problem(cls.course, cls.request, cls.l, score=1, max_value=3) answer_problem(cls.course, cls.request, cls.n, score=3, max_value=10) cls.course_grade = CourseGradeFactory().create(cls.request.user, cls.course)
def test_initial_user_setting_tracking(self): request = get_mock_request() del request.user track_request_user_changes(request) request.user = UserFactory.create() assert "Setting for the first time" in request.debug_user_changes[0]
def setUp(self): super(TestSafeSessionMiddleware, self).setUp() self.user = UserFactory.create() self.addCleanup(set_current_request, None) self.request = get_mock_request() self.client.response = HttpResponse() self.client.response.cookies = SimpleCookie()
def test_initial_user_setting_logging(self, mock_log): request = get_mock_request() del request.user log_request_user_changes(request) request.user = UserFactory.create() assert mock_log.called assert "Setting for the first time" in mock_log.call_args[0][0]
def setUp(self): super(GradesAccessIntegrationTest, self).setUp() self.request = get_mock_request(UserFactory()) self.student = self.request.user self.client.login(username=self.student.username, password="******") CourseEnrollment.enroll(self.student, self.course.id) self.instructor = UserFactory.create(is_staff=True, username=u'test_instructor', password=u'test') self.refresh_course()
def setUp(self): super().setUp() password = '******' self.student = UserFactory.create(is_staff=False, username='******', password=password) self.client.login(username=self.student.username, password=password) self.addCleanup(set_current_request, None) self.request = get_mock_request(self.student) self.course_structure = get_course_blocks(self.student, self.course.location)
def test_invalid_course_key(self): self.setup_user() self.addCleanup(set_current_request, None) request = get_mock_request(self.user) with pytest.raises(Http404): StaticCourseTabView().get(request, course_id='edX/toy', tab_slug='new_tab')
def setUp(self): super(GradesEventIntegrationTest, self).setUp() self.request = get_mock_request(UserFactory()) self.student = self.request.user self.client.login(username=self.student.username, password="******") CourseEnrollment.enroll(self.student, self.course.id) self.instructor = UserFactory.create(is_staff=True, username=u'test_instructor', password=u'test') self.refresh_course()
def setUp(self): super(GradesAccessIntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.addCleanup(set_current_request, None) self.request = get_mock_request(UserFactory()) self.student = self.request.user self.client.login(username=self.student.username, password="******") CourseEnrollment.enroll(self.student, self.course.id) self.instructor = UserFactory.create(is_staff=True, username=u'test_instructor', password=u'test') self.refresh_course()
def setUp(self): super(TestCourseGradeLogging, self).setUp() self.course = CourseFactory.create() with self.store.bulk_operations(self.course.id): self.chapter = ItemFactory.create(parent=self.course, category="chapter", display_name="Test Chapter") self.sequence = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Test Sequential 1", graded=True) self.sequence_2 = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Test Sequential 2", graded=True) self.sequence_3 = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Test Sequential 3", graded=False) self.vertical = ItemFactory.create(parent=self.sequence, category='vertical', display_name='Test Vertical 1') self.vertical_2 = ItemFactory.create( parent=self.sequence_2, category='vertical', display_name='Test Vertical 2') self.vertical_3 = ItemFactory.create( parent=self.sequence_3, category='vertical', display_name='Test Vertical 3') problem_xml = MultipleChoiceResponseXMLFactory().build_xml( question_text='The correct answer is Choice 2', choices=[False, False, True, False], choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3']) self.problem = ItemFactory.create(parent=self.vertical, category="problem", display_name="test_problem_1", data=problem_xml) self.problem_2 = ItemFactory.create(parent=self.vertical_2, category="problem", display_name="test_problem_2", data=problem_xml) self.problem_3 = ItemFactory.create(parent=self.vertical_3, category="problem", display_name="test_problem_3", data=problem_xml) self.request = get_mock_request(UserFactory()) self.client.login(username=self.request.user.username, password="******") self.course_structure = get_course_blocks(self.request.user, self.course.location) self.subsection_grade_factory = SubsectionGradeFactory( self.request.user, self.course, self.course_structure) CourseEnrollment.enroll(self.request.user, self.course.id)
def setUp(self): super(GradeTestBase, self).setUp() self.addCleanup(set_current_request, None) self.request = get_mock_request(UserFactory()) self.client.login(username=self.request.user.username, password="******") self._set_grading_policy() self.course_structure = get_course_blocks(self.request.user, self.course.location) self.course_data = CourseData(self.request.user, structure=self.course_structure) self.subsection_grade_factory = SubsectionGradeFactory(self.request.user, self.course, self.course_structure) CourseEnrollment.enroll(self.request.user, self.course.id)
def setUp(self): self.reset_course() super(GradesEventIntegrationTest, self).setUp() self.addCleanup(set_current_request, None) self.request = get_mock_request(UserFactory()) self.student = self.request.user self.client.login(username=self.student.username, password="******") CourseEnrollment.enroll(self.student, self.course.id) self.instructor = UserFactory.create(is_staff=True) self.refresh_course()
def setUp(self): super(GradeTestBase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.addCleanup(set_current_request, None) self.request = get_mock_request(UserFactory()) self.client.login(username=self.request.user.username, password="******") self._set_grading_policy() self.course_structure = get_course_blocks(self.request.user, self.course.location) self.course_data = CourseData(self.request.user, structure=self.course_structure) self.subsection_grade_factory = SubsectionGradeFactory(self.request.user, self.course, self.course_structure) CourseEnrollment.enroll(self.request.user, self.course.id)
def setUp(self): """ Set up the course and user context """ super(CoursesRenderTest, self).setUp() store = modulestore() course_items = import_course_from_xml(store, self.user.id, TEST_DATA_DIR, ['toy']) course_key = course_items[0].id self.course = get_course_by_id(course_key) self.request = get_mock_request(UserFactory.create())
def setUp(self): """ Set up the course and user context """ super(CoursesRenderTest, self).setUp() store = modulestore() course_items = import_course_from_xml(store, self.user.id, TEST_DATA_DIR, ['toy']) course_key = course_items[0].id self.course = get_course_by_id(course_key) self.request = get_mock_request(UserFactory.create())
def test_user_change_with_no_ids(self): request = get_mock_request() del request.user track_request_user_changes(request) request.user = object() assert "Setting for the first time, but user has no id" in request.debug_user_changes[0] request.user = object() assert len(request.debug_user_changes) == 2 assert "Changing request user but user has no id." in request.debug_user_changes[1]
def setUp(self): super(TestMultipleProblemTypesSubsectionScores, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments password = u'test' self.student = UserFactory.create(is_staff=False, username=u'test_student', password=password) self.client.login(username=self.student.username, password=password) self.addCleanup(set_current_request, None) self.request = get_mock_request(self.student) self.course_structure = get_course_blocks(self.student, self.course.location)
def test_course_tabs_list_for_staff_members(self): """ Tests tab list is not limited if user is member of staff and has not passed entrance exam. """ # Login as member of staff self.client.logout() staff_user = StaffFactory(course_key=self.course.id) self.client.login(username=staff_user.username, password='******') request = get_mock_request(staff_user) course_tab_list = get_course_tab_list(request, self.course) self.assertEqual(len(course_tab_list), 5)
def test_course_tabs_list_for_staff_members(self): """ Tests tab list is not limited if user is member of staff and has not passed entrance exam. """ # Login as member of staff self.client.logout() staff_user = StaffFactory(course_key=self.course.id) self.client.login(username=staff_user.username, password='******') request = get_mock_request(staff_user) course_tab_list = get_course_tab_list(request, self.course) self.assertEqual(len(course_tab_list), 5)
def setUp(self): """ Set up the course and user context """ super(CoursesRenderTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments store = modulestore() course_items = import_course_from_xml(store, self.user.id, TEST_DATA_DIR, ['toy']) course_key = course_items[0].id self.course = get_course_by_id(course_key) self.addCleanup(set_current_request, None) self.request = get_mock_request(UserFactory.create())
def test_user_change_with_no_ids(self, mock_log): request = get_mock_request() del request.user log_request_user_changes(request) request.user = object() assert mock_log.called assert "Setting for the first time, but user has no id" in mock_log.call_args[0][0] request.user = object() assert mock_log.call_count == 2 assert "Changing request user but user has no id." in mock_log.call_args[0][0]
def setUp(self): """ Set up test course """ super(TestGetModuleScore, self).setUp() self.request = get_mock_request(UserFactory()) self.client.login(username=self.request.user.username, password="******") CourseEnrollment.enroll(self.request.user, self.course.id) self.course_structure = get_course_blocks(self.request.user, self.course.location) # warm up the score cache to allow accurate query counts, even if tests are run in random order get_module_score(self.request.user, self.course, self.seq1)
def test_get_static_tab_fragment(self): self.setup_user() course = get_course_by_id(self.course.id) request = get_mock_request(self.user) tab = xmodule_tabs.CourseTabList.get_tab_by_slug(course.tabs, 'new_tab') # Test render works okay tab_content = get_static_tab_fragment(request, course, tab).content self.assertIn(self.course.id.to_deprecated_string(), tab_content) self.assertIn('static_tab', tab_content) # Test when render raises an exception with patch('courseware.views.views.get_module') as mock_module_render: mock_module_render.return_value = MagicMock( render=Mock(side_effect=Exception('Render failed!')) ) static_tab_content = get_static_tab_fragment(request, course, tab).content self.assertIn("this module is temporarily unavailable", static_tab_content)
def test_pdf_textbook_tabs(self): """ Test that all textbooks tab links generating correctly. """ type_to_reverse_name = {'textbook': 'book', 'pdftextbook': 'pdf_book', 'htmltextbook': 'html_book'} request = get_mock_request(self.user) course_tab_list = get_course_tab_list(request, self.course) num_of_textbooks_found = 0 for tab in course_tab_list: # Verify links of all textbook type tabs. if tab.type == 'single_textbook': book_type, book_index = tab.tab_id.split("/", 1) expected_link = reverse( type_to_reverse_name[book_type], args=[self.course.id.to_deprecated_string(), book_index] ) tab_link = tab.link_func(self.course, reverse) self.assertEqual(tab_link, expected_link) num_of_textbooks_found += 1 self.assertEqual(num_of_textbooks_found, self.num_textbooks)
def test_get_course_tabs_list_skipped_entrance_exam(self): """ Tests tab list is not limited if user is allowed to skip entrance exam. """ #create a user student = UserFactory() # login as instructor hit skip entrance exam api in instructor app instructor = InstructorFactory(course_key=self.course.id) self.client.logout() self.client.login(username=instructor.username, password='******') url = reverse('mark_student_can_skip_entrance_exam', kwargs={'course_id': unicode(self.course.id)}) response = self.client.post(url, { 'unique_student_identifier': student.email, }) self.assertEqual(response.status_code, 200) # log in again as student self.client.logout() self.login(self.email, self.password) request = get_mock_request(self.user) course_tab_list = get_course_tab_list(request, self.course) self.assertEqual(len(course_tab_list), 5)
def test_get_course_tabs_list_entrance_exam_enabled(self): """ Unit Test: test_get_course_tabs_list_entrance_exam_enabled """ entrance_exam = ItemFactory.create( category="chapter", parent_location=self.course.location, data="Exam Data", display_name="Entrance Exam", is_entrance_exam=True ) milestone = { 'name': 'Test Milestone', 'namespace': '{}.entrance_exams'.format(unicode(self.course.id)), 'description': 'Testing Courseware Tabs' } self.user.is_staff = False request = get_mock_request(self.user) self.course.entrance_exam_enabled = True self.course.entrance_exam_id = unicode(entrance_exam.location) milestone = add_milestone(milestone) add_course_milestone( unicode(self.course.id), self.relationship_types['REQUIRES'], milestone ) add_course_content_milestone( unicode(self.course.id), unicode(entrance_exam.location), self.relationship_types['FULFILLS'], milestone ) course_tab_list = get_course_tab_list(request, self.course) self.assertEqual(len(course_tab_list), 1) self.assertEqual(course_tab_list[0]['tab_id'], 'courseware') self.assertEqual(course_tab_list[0]['name'], 'Entrance Exam')
def test_rescoring_events(self): self.submit_question_answer('p1', {'2_1': 'choice_choice_3'}) new_problem_xml = MultipleChoiceResponseXMLFactory().build_xml( question_text='The correct answer is Choice 3', choices=[False, False, False, True], choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3'] ) with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id): self.problem.data = new_problem_xml self.store.update_item(self.problem, self.instructor.id) self.store.publish(self.problem.location, self.instructor.id) with patch('lms.djangoapps.grades.events.tracker') as events_tracker: submit_rescore_problem_for_student( request=get_mock_request(self.instructor), usage_key=self.problem.location, student=self.student, only_if_higher=False ) course = self.store.get_course(self.course.id, depth=0) # make sure the tracker's context is updated with course info for args in events_tracker.get_tracker().context.call_args_list: self.assertEqual( args[0][1], {'course_id': unicode(self.course.id), 'org_id': unicode(self.course.org)} ) event_transaction_id = events_tracker.emit.mock_calls[0][1][1]['event_transaction_id'] events_tracker.emit.assert_has_calls( [ mock_call( events.GRADES_RESCORE_EVENT_TYPE, { 'course_id': unicode(self.course.id), 'user_id': unicode(self.student.id), 'problem_id': unicode(self.problem.location), 'new_weighted_earned': 2, 'new_weighted_possible': 2, 'only_if_higher': False, 'instructor_id': unicode(self.instructor.id), 'event_transaction_id': event_transaction_id, 'event_transaction_type': events.GRADES_RESCORE_EVENT_TYPE, }, ), mock_call( events.COURSE_GRADE_CALCULATED, { 'course_version': unicode(course.course_version), 'percent_grade': 0.02, 'grading_policy_hash': u'ChVp0lHGQGCevD0t4njna/C44zQ=', 'user_id': unicode(self.student.id), 'letter_grade': u'', 'event_transaction_id': event_transaction_id, 'event_transaction_type': events.GRADES_RESCORE_EVENT_TYPE, 'course_id': unicode(self.course.id), 'course_edited_timestamp': unicode(course.subtree_edited_on), }, ), ], any_order=True, )
def test_invalid_course_key(self): self.setup_user() request = get_mock_request(self.user) with self.assertRaises(Http404): StaticCourseTabView().get(request, course_id='edX/toy', tab_slug='new_tab')
def setUp(self): self.user = self.create_mock_user() self.request = get_mock_request(self.user)
def setUp(self): super(TestSafeSessionProcessRequest, self).setUp() self.user = UserFactory.create() self.request = get_mock_request()
def setUp(self): super(TestWeightedProblems, self).setUp() self.user = UserFactory() self.addCleanup(set_current_request, None) self.request = get_mock_request(self.user)
def test_rescoring_events(self, models_tracker, handlers_tracker, instructor_task_tracker): # submit answer self.submit_question_answer('p1', {'2_1': 'choice_choice_3'}) models_tracker.reset_mock() handlers_tracker.reset_mock() new_problem_xml = MultipleChoiceResponseXMLFactory().build_xml( question_text='The correct answer is Choice 3', choices=[False, False, False, True], choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3'] ) module_store = modulestore() with module_store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id): self.problem.data = new_problem_xml module_store.update_item(self.problem, self.instructor.id) module_store.publish(self.problem.location, self.instructor.id) submit_rescore_problem_for_student( request=get_mock_request(self.instructor), usage_key=self.problem.location, student=self.student, only_if_higher=False ) # check logging to make sure id's are tracked correctly across # events event_transaction_id = instructor_task_tracker.emit.mock_calls[0][1][1]['event_transaction_id'] self.assertEqual( instructor_task_tracker.get_tracker().context.call_args[0], ('edx.grades.problem.rescored', {'course_id': unicode(self.course.id), 'org_id': unicode(self.course.org)}) ) # make sure the id is propagated throughout the event flow for call in models_tracker.emit.mock_calls: self.assertEqual(event_transaction_id, call[1][1]['event_transaction_id']) self.assertEqual(unicode(RESCORE_TYPE), call[1][1]['event_transaction_type']) # make sure the models calls have re-added the course id to the context for args in models_tracker.get_tracker().context.call_args_list: self.assertEqual( args[0][1], {'course_id': unicode(self.course.id), 'org_id': unicode(self.course.org)} ) handlers_tracker.assert_not_called() instructor_task_tracker.emit.assert_called_with( unicode(RESCORE_TYPE), { 'course_id': unicode(self.course.id), 'user_id': unicode(self.student.id), 'problem_id': unicode(self.problem.location), 'new_weighted_earned': 2, 'new_weighted_possible': 2, 'only_if_higher': False, 'instructor_id': unicode(self.instructor.id), 'event_transaction_id': event_transaction_id, 'event_transaction_type': unicode(RESCORE_TYPE), } ) course = modulestore().get_course(self.course.id, depth=0) models_tracker.emit.assert_called_with( u'edx.grades.course.grade_calculated', { 'course_version': unicode(course.course_version), 'percent_grade': 0.02, 'grading_policy_hash': u'ChVp0lHGQGCevD0t4njna/C44zQ=', 'user_id': unicode(self.student.id), 'letter_grade': u'', 'event_transaction_id': event_transaction_id, 'event_transaction_type': unicode(RESCORE_TYPE), 'course_id': unicode(self.course.id), 'course_edited_timestamp': unicode(course.subtree_edited_on), } ) instructor_task_tracker.reset_mock() models_tracker.reset_mock() handlers_tracker.reset_mock()
def setUp(self): super(TestSafeSessionProcessRequest, self).setUp() self.user = UserFactory.create() self.addCleanup(set_current_request, None) self.request = get_mock_request()
def setUp(self): super(TestCourseGradeLogging, self).setUp() self.course = CourseFactory.create() self.chapter = ItemFactory.create( parent=self.course, category="chapter", display_name="Test Chapter" ) self.sequence = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Test Sequential 1", graded=True ) self.sequence_2 = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Test Sequential 2", graded=True ) self.sequence_3 = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Test Sequential 3", graded=False ) self.vertical = ItemFactory.create( parent=self.sequence, category='vertical', display_name='Test Vertical 1' ) self.vertical_2 = ItemFactory.create( parent=self.sequence_2, category='vertical', display_name='Test Vertical 2' ) self.vertical_3 = ItemFactory.create( parent=self.sequence_3, category='vertical', display_name='Test Vertical 3' ) problem_xml = MultipleChoiceResponseXMLFactory().build_xml( question_text='The correct answer is Choice 2', choices=[False, False, True, False], choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3'] ) self.problem = ItemFactory.create( parent=self.vertical, category="problem", display_name="test_problem_1", data=problem_xml ) self.problem_2 = ItemFactory.create( parent=self.vertical_2, category="problem", display_name="test_problem_2", data=problem_xml ) self.problem_3 = ItemFactory.create( parent=self.vertical_3, category="problem", display_name="test_problem_3", data=problem_xml ) self.request = get_mock_request(UserFactory()) self.client.login(username=self.request.user.username, password="******") self.course_structure = get_course_blocks(self.request.user, self.course.location) self.subsection_grade_factory = SubsectionGradeFactory(self.request.user, self.course, self.course_structure) CourseEnrollment.enroll(self.request.user, self.course.id)
def setUp(self): self.user = self.create_mock_user() self.addCleanup(set_current_request, None) self.request = get_mock_request(self.user)
def setUp(self): super(TestWeightedProblems, self).setUp() self.user = UserFactory() self.request = get_mock_request(self.user)
def setUp(self): """ Test case scaffolding """ super(EntranceExamTestCases, self).setUp() self.course = CourseFactory.create( metadata={ 'entrance_exam_enabled': True, } ) with self.store.bulk_operations(self.course.id): self.chapter = ItemFactory.create( parent=self.course, display_name='Overview' ) self.welcome = 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' ) problem_xml = MultipleChoiceResponseXMLFactory().build_xml( question_text='The correct answer is Choice 3', choices=[False, False, True, False], choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3'] ) self.problem_1 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 1", data=problem_xml ) self.problem_2 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 2" ) 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_mock_request(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 _pass_entrance_exam(self): """ Helper function to pass the entrance exam """ request = get_mock_request(self.user) answer_entrance_exam_problem(self.course, request, self.problem_1)