def setUp(self): super(CourseOverviewAccessTestCase, self).setUp() today = datetime.datetime.now(pytz.UTC) last_week = today - datetime.timedelta(days=7) next_week = today + datetime.timedelta(days=7) self.course_default = CourseFactory.create() self.course_started = CourseFactory.create(start=last_week) self.course_not_started = CourseFactory.create(start=next_week, days_early_for_beta=10) self.course_staff_only = CourseFactory.create(visible_to_staff_only=True) self.course_mobile_available = CourseFactory.create(mobile_available=True) self.course_with_pre_requisite = CourseFactory.create( pre_requisite_courses=[str(self.course_started.id)] ) self.course_with_pre_requisites = CourseFactory.create( pre_requisite_courses=[str(self.course_started.id), str(self.course_not_started.id)] ) self.user_normal = UserFactory.create() self.user_beta_tester = BetaTesterFactory.create(course_key=self.course_not_started.id) self.user_completed_pre_requisite = UserFactory.create() fulfill_course_milestone(self.user_completed_pre_requisite, self.course_started.id) self.user_staff = UserFactory.create(is_staff=True) self.user_anonymous = AnonymousUserFactory.create()
def test_rebind_noauth_module_to_user_anonymous(self): """ Tests that get_user_module_for_noauth succeeds when rebind_noauth_module_to_user is run from a module bound to AnonymousUser """ module = self.get_module_for_user(self.anon_user) user2 = UserFactory() user2.id = 2 module.system.rebind_noauth_module_to_user(module, user2) self.assertTrue(module) self.assertEqual(module.system.anonymous_student_id, anonymous_id_for_user(user2, self.course.id)) self.assertEqual(module.scope_ids.user_id, user2.id) self.assertEqual(module.descriptor.scope_ids.user_id, user2.id)
def test_rebind_noauth_module_to_user_not_anonymous(self): """ Tests that an exception is thrown when rebind_noauth_module_to_user is run from a module bound to a real user """ module = self.get_module_for_user(self.user) user2 = UserFactory() user2.id = 2 with self.assertRaisesRegexp( render.LmsModuleRenderError, "rebind_noauth_module_to_user can only be called from a module bound to an anonymous user" ): self.assertTrue(module.system.rebind_noauth_module_to_user(module, user2))
def test__has_access_course_desc_can_enroll(self): yesterday = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1) tomorrow = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1) # Non-staff can enroll if authenticated and specifically allowed for that course # even outside the open enrollment period user = UserFactory.create() course = Mock( enrollment_start=tomorrow, enrollment_end=tomorrow, id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), enrollment_domain="", ) CourseEnrollmentAllowedFactory(email=user.email, course_id=course.id) self.assertTrue(access._has_access_course_desc(user, "enroll", course)) # Staff can always enroll even outside the open enrollment period user = StaffFactory.create(course_key=course.id) self.assertTrue(access._has_access_course_desc(user, "enroll", course)) # Non-staff cannot enroll if it is between the start and end dates and invitation only # and not specifically allowed course = Mock( enrollment_start=yesterday, enrollment_end=tomorrow, id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), enrollment_domain="", invitation_only=True, ) user = UserFactory.create() self.assertFalse(access._has_access_course_desc(user, "enroll", course)) # Non-staff can enroll if it is between the start and end dates and not invitation only course = Mock( enrollment_start=yesterday, enrollment_end=tomorrow, id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), enrollment_domain="", invitation_only=False, ) self.assertTrue(access._has_access_course_desc(user, "enroll", course)) # Non-staff cannot enroll outside the open enrollment period if not specifically allowed course = Mock( enrollment_start=tomorrow, enrollment_end=tomorrow, id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), enrollment_domain="", invitation_only=False, ) self.assertFalse(access._has_access_course_desc(user, "enroll", course))
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 = [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(user, 'load', course) self.assertFalse(response) self.assertIsInstance(response, access_response.MilestoneAccessError) # Staff can always access course staff = StaffFactory.create(course_key=course.id) self.assertTrue(access._has_access_course(staff, 'load', course)) # User should be able access after completing required course fulfill_course_milestone(pre_requisite_course.id, user) self.assertTrue(access._has_access_course(user, 'load', course))
def test__catalog_visibility(self): """ Tests the catalog visibility tri-states """ user = UserFactory.create() course_id = SlashSeparatedCourseKey("edX", "test", "2012_Fall") staff = StaffFactory.create(course_key=course_id) course = Mock(id=course_id, catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT) self.assertTrue(access._has_access_course_desc(user, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(user, "see_about_page", course)) self.assertTrue(access._has_access_course_desc(staff, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(staff, "see_about_page", course)) # Now set visibility to just about page course = Mock( id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), catalog_visibility=CATALOG_VISIBILITY_ABOUT ) self.assertFalse(access._has_access_course_desc(user, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(user, "see_about_page", course)) self.assertTrue(access._has_access_course_desc(staff, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(staff, "see_about_page", course)) # Now set visibility to none, which means neither in catalog nor about pages course = Mock( id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), catalog_visibility=CATALOG_VISIBILITY_NONE ) self.assertFalse(access._has_access_course_desc(user, "see_in_catalog", course)) self.assertFalse(access._has_access_course_desc(user, "see_about_page", course)) self.assertTrue(access._has_access_course_desc(staff, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(staff, "see_about_page", course))
def test_see_exists(self, ispublic): """ Test if user can see course """ user = UserFactory.create(is_staff=False) course = Mock(ispublic=ispublic) self.assertEquals(bool(access._has_access_course_desc(user, "see_exists", course)), ispublic)
def setUp(self): self.user = UserFactory.create() self.request = RequestFactory().get('/') self.request.user = self.user self.request.session = {} self.course = CourseFactory.create() problem_xml = OptionResponseXMLFactory().build_xml( question_text='The correct answer is Correct', num_inputs=2, weight=2, options=['Correct', 'Incorrect'], correct_option='Correct' ) self.descriptor = ItemFactory.create( category='problem', data=problem_xml, display_name='Option Response Problem' ) self.location = self.descriptor.location self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents( self.course.id, self.user, self.descriptor )
def setUp(self): super(MobileAPITestCase, self).setUp() self.course = CourseFactory.create(mobile_available=True, static_asset_path="needed_for_split") self.user = UserFactory.create() self.password = '******' self.username = self.user.username IgnoreMobileAvailableFlagConfig(enabled=False).save()
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_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 test_spoc_gradebook_mongo_calls(self): """ Test that the MongoDB cache is used in API to return grades """ # prepare course structure course = ItemFactory.create(parent_location=self.course.location, category="course", display_name="Test course") students = [] for i in xrange(20): username = "******" % i student = UserFactory.create(username=username) CourseEnrollmentFactory.create(user=student, course_id=self.course.id) students.append(student) chapter = ItemFactory.create( parent=course, category="chapter", display_name="Chapter", publish_item=True, start=datetime.datetime(2015, 3, 1, tzinfo=UTC), ) sequential = ItemFactory.create( parent=chapter, category="sequential", display_name="Lesson", publish_item=True, start=datetime.datetime(2015, 3, 1, tzinfo=UTC), metadata={"graded": True, "format": "Homework"}, ) vertical = ItemFactory.create( parent=sequential, category="vertical", display_name="Subsection", publish_item=True, start=datetime.datetime(2015, 4, 1, tzinfo=UTC), ) for i in xrange(10): problem = ItemFactory.create( category="problem", parent=vertical, display_name="A Problem Block %d" % i, weight=1, publish_item=False, metadata={"rerandomize": "always"}, ) for j in students: grade = i % 2 StudentModuleFactory.create( grade=grade, max_grade=1, student=j, course_id=self.course.id, module_state_key=problem.location ) # check MongoDB calls count url = reverse("spoc_gradebook", kwargs={"course_id": self.course.id}) with check_mongo_calls(8): response = self.client.get(url) self.assertEqual(response.status_code, 200)
def test_spoc_gradebook_pages(self): for i in xrange(2): username = "******" % i student = UserFactory.create(username=username) CourseEnrollmentFactory.create(user=student, course_id=self.course.id) url = reverse("spoc_gradebook", kwargs={"course_id": self.course.id}) response = self.client.get(url) self.assertEqual(response.status_code, 200) # Max number of student per page is one. Patched setting MAX_STUDENTS_PER_PAGE_GRADE_BOOK = 1 self.assertEqual(len(response.mako_context["students"]), 1) # pylint: disable=no-member
def test_overview_anon(self): # anonymous disallowed url = reverse('user-detail', kwargs={'username': self.user.username}) response = self.client.get(url) self.assertEqual(response.status_code, 401) # can't get info on someone else other = UserFactory.create() self.client.login(username=self.username, password=self.password) response = self.client.get(reverse('user-detail', kwargs={'username': other.username})) self.assertEqual(response.status_code, 403)
def user_create_and_signin(self, user_number): """ Create a user and sign them in """ self.users[user_number] = UserFactory.create( username=self.USERS[user_number]['USERNAME'], email=self.USERS[user_number]['EMAIL'], password=self.USERS[user_number]['PASSWORD'] ) self.client.login(username=self.USERS[user_number]['USERNAME'], password=self.USERS[user_number]['PASSWORD'])
def setUp(self): super(TestVideoOutline, self).setUp() self.user = UserFactory.create() self.course = CourseFactory.create(mobile_available=True) self.section = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name=u"test factory section omega \u03a9" ) self.sub_section = ItemFactory.create( parent_location=self.section.location, category="sequential", display_name=u"test subsection omega \u03a9" ) self.unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={"graded": True, "format": "Homework"}, display_name=u"test unit omega \u03a9", ) self.other_unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={"graded": True, "format": "Homework"}, display_name=u"test unit omega 2 \u03a9", ) self.nameless_unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={"graded": True, "format": "Homework"}, display_name=None, ) self.edx_video_id = "testing-123" self.video_url = "http://val.edx.org/val/video.mp4" self.html5_video_url = "http://video.edx.org/html5/video.mp4" api.create_profile({"profile_name": "youtube", "extension": "mp4", "width": 1280, "height": 720}) api.create_profile({"profile_name": "mobile_low", "extension": "mp4", "width": 640, "height": 480}) # create the video in VAL api.create_video( { "edx_video_id": self.edx_video_id, "client_video_id": u"test video omega \u03a9", "duration": 12, "courses": [unicode(self.course.id)], "encoded_videos": [ {"profile": "youtube", "url": "xyz123", "file_size": 0, "bitrate": 1500}, {"profile": "mobile_low", "url": self.video_url, "file_size": 12345, "bitrate": 250}, ], } ) self.client.login(username=self.user.username, password="******")
def test_other_user(self): # login and enroll as the test user self.login_and_enroll() self.logout() # login and enroll as another user other = UserFactory.create() self.client.login(username=other.username, password='******') self.enroll() self.logout() # now login and call the API as the test user self.login() self.api_response(expected_response_code=404, username=other.username)
def setUp(self): self.user = UserFactory.create() self.request = RequestFactory().get('/') self.request.user = self.user self.request.session = {} self.course = CourseFactory.create() self.problem_xml = OptionResponseXMLFactory().build_xml( question_text='The correct answer is Correct', num_inputs=2, weight=2, options=['Correct', 'Incorrect'], correct_option='Correct' )
def test_instructor_tab(self): """ Verify that the instructor tab appears for staff only. """ def has_instructor_tab(user, course): """Returns true if the "Instructor" tab is shown.""" request = RequestFactory().request() request.user = user tabs = get_course_tab_list(request, course) return len([tab for tab in tabs if tab.name == 'Instructor']) == 1 self.assertTrue(has_instructor_tab(self.instructor, self.course)) student = UserFactory.create() self.assertFalse(has_instructor_tab(student, self.course))
def test_certificate_generation_api_without_global_staff(self): """ Test certificates generation api endpoint returns permission denied if user who made the request is not member of global staff. """ user = UserFactory.create() self.client.login(username=user.username, password="******") url = reverse("start_certificate_generation", kwargs={"course_id": unicode(self.course.id)}) response = self.client.post(url) self.assertEqual(response.status_code, 403) self.client.login(username=self.instructor.username, password="******") response = self.client.post(url) self.assertEqual(response.status_code, 403)
def setUp(self): # Create one user and save it to the database self.user = UserFactory.build(username="******", email="*****@*****.**") self.user.set_password("test_password") self.user.save() # Create a registration for the user RegistrationFactory(user=self.user) # Create a profile for the user UserProfileFactory(user=self.user) # Create the test client self.client = Client() # Store the login url self.url = reverse("login")
def setUp(self): self.user = UserFactory.create() self.request = RequestFactory().get("/") self.request.user = self.user self.request.session = {} self.course = CourseFactory.create() self.content_string = "<p>This is the content<p>" self.rewrite_link = '<a href="/static/foo/content">Test rewrite</a>' self.rewrite_bad_link = '<img src="/static//file.jpg" />' self.course_link = '<a href="/course/bar/content">Test course rewrite</a>' self.descriptor = ItemFactory.create( category="html", data=self.content_string + self.rewrite_link + self.rewrite_bad_link + self.course_link ) self.location = self.descriptor.location self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents( self.course.id, self.user, self.descriptor )
def test_instructor_tab(self): """ Verify that the instructor tab appears for staff only. """ def has_instructor_tab(user, course): """Returns true if the "Instructor" tab is shown.""" request = RequestFactory().request() request.user = user tabs = get_course_tab_list(request, course) return len([tab for tab in tabs if tab.name == 'Instructor']) == 1 self.assertTrue(has_instructor_tab(self.instructor, self.course)) staff = StaffFactory(course_key=self.course.id) self.assertTrue(has_instructor_tab(staff, self.course)) student = UserFactory.create() self.assertFalse(has_instructor_tab(student, self.course))
def test_total_credit_cart_sales_amount(self): """ Test to check the total amount for all the credit card purchases. """ student = UserFactory.create() self.client.login(username=student.username, password="******") student_cart = Order.get_cart_for_user(student) item = self.add_course_to_user_cart(student_cart, self.course.id) resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': item.id, 'qty': 4}) self.assertEqual(resp.status_code, 200) student_cart.purchase() self.client.login(username=self.instructor.username, password="******") CourseFinanceAdminRole(self.course.id).add_users(self.instructor) single_purchase_total = PaidCourseRegistration.get_total_amount_of_purchased_item(self.course.id) bulk_purchase_total = CourseRegCodeItem.get_total_amount_of_purchased_item(self.course.id) total_amount = single_purchase_total + bulk_purchase_total response = self.client.get(self.url) self.assertIn('{currency}{amount}'.format(currency='$', amount=total_amount), response.content)
def setUp(self): self.location = Location('i4x', 'edX', 'toy', 'chapter', 'Overview') self.course_id = 'edX/toy/2012_Fall' self.toy_course = modulestore().get_course(self.course_id) self.mock_user = UserFactory() self.mock_user.id = 1 self.request_factory = RequestFactory() # Construct a mock module for the modulestore to return self.mock_module = MagicMock() self.mock_module.id = 1 self.dispatch = 'score_update' # Construct a 'standard' xqueue_callback url self.callback_url = reverse('xqueue_callback', kwargs=dict(course_id=self.course_id, userid=str(self.mock_user.id), mod_id=self.mock_module.id, dispatch=self.dispatch))
def test_entrance_exam_gating(self): """ Unit Test: test_entrance_exam_gating """ # This user helps to cover a discovered bug in the milestone fulfillment logic chaos_user = UserFactory() locked_toc = self._return_table_of_contents() for toc_section in self.expected_locked_toc: self.assertIn(toc_section, locked_toc) # Set up the chaos user answer_entrance_exam_problem(self.course, self.request, self.problem_1, chaos_user) answer_entrance_exam_problem(self.course, self.request, self.problem_1) answer_entrance_exam_problem(self.course, self.request, self.problem_2) unlocked_toc = self._return_table_of_contents() for toc_section in self.expected_unlocked_toc: self.assertIn(toc_section, unlocked_toc)
def setUp(self): super(TestInlineAnalytics, self).setUp() self.user = UserFactory.create() self.request = RequestFactory().get('/') self.request.user = self.user self.request.session = {} self.course = CourseFactory.create( org='A', number='B', display_name='C', ) self.staff = StaffFactory(course_key=self.course.id) self.instructor = InstructorFactory(course_key=self.course.id) self.problem_xml = OptionResponseXMLFactory().build_xml( question_text='The correct answer is Correct', num_inputs=2, weight=2, options=['Correct', 'Incorrect'], correct_option='Correct', ) self.descriptor = ItemFactory.create( category='problem', data=self.problem_xml, display_name='Option Response Problem', rerandomize='never', ) self.location = self.descriptor.location self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents( self.course.id, self.user, self.descriptor, ) self.field_data_cache_staff = FieldDataCache.cache_for_descriptor_descendents( self.course.id, self.staff, self.descriptor, ) self.field_data_cache_instructor = FieldDataCache.cache_for_descriptor_descendents( self.course.id, self.instructor, self.descriptor, )
def test__catalog_visibility(self): """ Tests the catalog visibility tri-states """ user = UserFactory.create() course_id = SlashSeparatedCourseKey('edX', 'test', '2012_Fall') staff = StaffFactory.create(course_key=course_id) course = Mock(id=course_id, catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT) self.assertTrue( access._has_access_course_desc(user, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(user, 'see_about_page', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_about_page', course)) # Now set visibility to just about page course = Mock(id=SlashSeparatedCourseKey('edX', 'test', '2012_Fall'), catalog_visibility=CATALOG_VISIBILITY_ABOUT) self.assertFalse( access._has_access_course_desc(user, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(user, 'see_about_page', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_about_page', course)) # Now set visibility to none, which means neither in catalog nor about pages course = Mock(id=SlashSeparatedCourseKey('edX', 'test', '2012_Fall'), catalog_visibility=CATALOG_VISIBILITY_NONE) self.assertFalse( access._has_access_course_desc(user, 'see_in_catalog', course)) self.assertFalse( access._has_access_course_desc(user, 'see_about_page', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_about_page', course))
def setUp(self): self.course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall') self.location = self.course_key.make_usage_key('chapter', 'Overview') self.toy_course = modulestore().get_course(self.course_key) self.mock_user = UserFactory() self.mock_user.id = 1 self.request_factory = RequestFactory() # Construct a mock module for the modulestore to return self.mock_module = MagicMock() self.mock_module.id = 1 self.dispatch = 'score_update' # Construct a 'standard' xqueue_callback url self.callback_url = reverse( 'xqueue_callback', kwargs=dict(course_id=self.course_key.to_deprecated_string(), userid=str(self.mock_user.id), mod_id=self.mock_module.id, dispatch=self.dispatch))
def setUp(self): self.user = UserFactory.create() self.request = RequestFactory().get('/') self.request.user = self.user self.request.session = {} self.course = CourseFactory.create() self.content_string = '<p>This is the content<p>' self.rewrite_link = '<a href="/static/foo/content">Test rewrite</a>' self.rewrite_bad_link = '<img src="/static//file.jpg" />' self.course_link = '<a href="/course/bar/content">Test course rewrite</a>' self.descriptor = ItemFactory.create( category='html', data=self.content_string + self.rewrite_link + self.rewrite_bad_link + self.course_link ) self.location = self.descriptor.location self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents( self.course.id, self.user, self.descriptor )
def setUp(self): self.user = UserFactory.create() self.request = RequestFactory().get('/') self.request.user = self.user self.request.session = {} self.course = CourseFactory.create() problem_xml = OptionResponseXMLFactory().build_xml( question_text='The correct answer is Correct', num_inputs=2, weight=2, options=['Correct', 'Incorrect'], correct_option='Correct') self.descriptor = ItemFactory.create( category='problem', data=problem_xml, display_name='Option Response Problem') self.location = self.descriptor.location self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents( self.course.id, self.user, self.descriptor)
def test_histogram_enabled_for_scored_xmodules(self): """Histograms should display for xmodules which are scored.""" StudentModuleFactory.create( course_id=self.course.id, module_state_key=self.location, student=UserFactory(), grade=1, max_grade=1, state="{}", ) with patch('xmodule_modifiers.grade_histogram') as mock_grade_histogram: mock_grade_histogram.return_value = [] module = render.get_module( self.user, self.request, self.location, self.field_data_cache, ) module.render(STUDENT_VIEW) self.assertTrue(mock_grade_histogram.called)
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 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 = [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 test_access_student_progress_ccx(self): """ Assert that only a coach can see progress of student. """ ccx_locator = self.make_ccx() student = UserFactory() # Enroll user CourseEnrollment.enroll(student, ccx_locator) # Test for access of a coach resp = self.client.get( reverse('student_progress', args=[six.text_type(ccx_locator), student.id])) self.assertEqual(resp.status_code, 200) # Assert access of a student self.client.login(username=student.username, password='******') resp = self.client.get( reverse('student_progress', args=[six.text_type(ccx_locator), self.coach.id])) self.assertEqual(resp.status_code, 404)
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( 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(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(user, 'view_courseware_with_prerequisites', course))
def setUp(self): super(InlineAnalyticsAnswerDistribution, self).setUp() self.user = UserFactory.create() self.factory = RequestFactory() self.course = CourseFactory.create( org='A', number='B', display_name='C', ) self.instructor = InstructorFactory(course_key=self.course.id) analytics_data = { 'module_id': '123', 'question_types_by_part': 'radio', 'num_options_by_part': 6, 'course_id': 'A/B/C', } json_analytics_data = json.dumps(analytics_data) self.data = json_analytics_data self.zendesk_response = ( 'A problem has occurred retrieving the data, to report the problem click ' '<a href="{ZENDESK_URL}/hc/en-us/requests/new">here</a>' ).format(ZENDESK_URL=ZENDESK_URL)
def setUp(self): super(GenerateCertificatesInstructorApiTest, self).setUp() self.global_staff = GlobalStaffFactory() self.instructor = InstructorFactory(course_key=self.course.id) self.user = UserFactory() CourseEnrollment.enroll(self.user, self.course.id) certificate_exception = CertificateWhitelistFactory.create( user=self.user, course_id=self.course.id, ) self.certificate_exception = dict( id=certificate_exception.id, user_name=certificate_exception.user.username, notes=certificate_exception.notes, user_email=certificate_exception.user.email, user_id=certificate_exception.user.id, ) # Enable certificate generation cache.clear() CertificateGenerationConfiguration.objects.create(enabled=True) self.client.login(username=self.global_staff.username, password='******')
def setUp(self): super(InlineAnalyticsAnswerDistribution, self).setUp() self.user = UserFactory.create() self.factory = RequestFactory() self.course = CourseFactory.create( org='A', number='B', display_name='C', ) self.instructor = InstructorFactory(course_key=self.course.id) analytics_data = { 'module_id': '123', 'question_types_by_part': 'radio', 'num_options_by_part': 6, 'course_id': 'A/B/C', } json_analytics_data = json.dumps(analytics_data) self.data = json_analytics_data self.zendesk_response = ( 'A problem has occurred retrieving the data, to report the problem click ' '<a href="{ZENDESK_URL}/hc/en-us/requests/new">here</a>').format( ZENDESK_URL=ZENDESK_URL)
def build_course(self): """ Build up a course tree with an html control """ self.global_staff = UserFactory(is_staff=True) self.course = CourseFactory.create( org='Elasticsearch', course='ES101', run='test_run', display_name='Elasticsearch test course', ) self.section = ItemFactory.create( parent=self.course, category='chapter', display_name='Test Section', ) self.subsection = ItemFactory.create( parent=self.section, category='sequential', display_name='Test Subsection', ) self.vertical = ItemFactory.create( parent=self.subsection, category='vertical', display_name='Test Unit', ) self.html = ItemFactory.create( parent=self.vertical, category='html', display_name='Test Html control 1', ) self.html = ItemFactory.create( parent=self.vertical, category='html', display_name='Test Html control 2', )
def test__catalog_visibility(self): """ Tests the catalog visibility tri-states """ user = UserFactory.create() course_id = CourseLocator('edX', 'test', '2012_Fall') staff = StaffFactory.create(course_key=course_id) course = Mock( id=course_id, catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT ) self.assertTrue(access._has_access_course(user, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(user, 'see_about_page', course)) self.assertTrue(access._has_access_course(staff, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(staff, 'see_about_page', course)) # Now set visibility to just about page course = Mock( id=CourseLocator('edX', 'test', '2012_Fall'), catalog_visibility=CATALOG_VISIBILITY_ABOUT ) self.assertFalse(access._has_access_course(user, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(user, 'see_about_page', course)) self.assertTrue(access._has_access_course(staff, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(staff, 'see_about_page', course)) # Now set visibility to none, which means neither in catalog nor about pages course = Mock( id=CourseLocator('edX', 'test', '2012_Fall'), catalog_visibility=CATALOG_VISIBILITY_NONE ) self.assertFalse(access._has_access_course(user, 'see_in_catalog', course)) self.assertFalse(access._has_access_course(user, 'see_about_page', course)) self.assertTrue(access._has_access_course(staff, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(staff, 'see_about_page', course))
def setUp(self): """ Set up the course and user context """ super(ModuleRenderTestCase, self).setUp() self.course_key = self.create_toy_course() self.toy_course = modulestore().get_course(self.course_key) self.mock_user = UserFactory() self.mock_user.id = 1 self.request_factory = RequestFactory() # Construct a mock module for the modulestore to return self.mock_module = MagicMock() self.mock_module.id = 1 self.dispatch = 'score_update' # Construct a 'standard' xqueue_callback url self.callback_url = reverse( 'xqueue_callback', kwargs=dict(course_id=self.course_key.to_deprecated_string(), userid=str(self.mock_user.id), mod_id=self.mock_module.id, dispatch=self.dispatch))
def setUp(self): super(TestVideoOutline, self).setUp() self.user = UserFactory.create() self.course = CourseFactory.create(mobile_available=True) self.section = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name=u"test factory section omega \u03a9", ) self.sub_section = ItemFactory.create( parent_location=self.section.location, category="sequential", display_name=u"test subsection omega \u03a9", ) self.unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={ 'graded': True, 'format': 'Homework' }, display_name=u"test unit omega \u03a9", ) self.other_unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={ 'graded': True, 'format': 'Homework' }, display_name=u"test unit omega 2 \u03a9", ) self.nameless_unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={ 'graded': True, 'format': 'Homework' }, display_name=None, ) self.edx_video_id = 'testing-123' self.video_url = 'http://val.edx.org/val/video.mp4' self.html5_video_url = 'http://video.edx.org/html5/video.mp4' api.create_profile({ 'profile_name': 'youtube', 'extension': 'mp4', 'width': 1280, 'height': 720 }) api.create_profile({ 'profile_name': 'mobile_low', 'extension': 'mp4', 'width': 640, 'height': 480 }) # create the video in VAL api.create_video({ 'edx_video_id': self.edx_video_id, 'client_video_id': u"test video omega \u03a9", 'duration': 12, 'courses': [unicode(self.course.id)], 'encoded_videos': [{ 'profile': 'youtube', 'url': 'xyz123', 'file_size': 0, 'bitrate': 1500 }, { 'profile': 'mobile_low', 'url': self.video_url, 'file_size': 12345, 'bitrate': 250 }] }) self.client.login(username=self.user.username, password='******')
def setUp(self): super(TestUserApi, self).setUp() self.course = CourseFactory.create(mobile_available=True) self.user = UserFactory.create() self.password = '******' self.username = self.user.username
def test_spoc_gradebook_mongo_calls(self): """ Test that the MongoDB cache is used in API to return grades """ # prepare course structure course = ItemFactory.create( parent_location=self.course.location, category="course", display_name="Test course", ) students = [] for i in range(20): username = "******" % i student = UserFactory.create(username=username) CourseEnrollmentFactory.create(user=student, course_id=self.course.id) students.append(student) chapter = ItemFactory.create( parent=course, category='chapter', display_name="Chapter", publish_item=True, start=datetime.datetime(2015, 3, 1, tzinfo=UTC), ) sequential = ItemFactory.create( parent=chapter, category='sequential', display_name="Lesson", publish_item=True, start=datetime.datetime(2015, 3, 1, tzinfo=UTC), metadata={'graded': True, 'format': 'Homework'}, ) vertical = ItemFactory.create( parent=sequential, category='vertical', display_name='Subsection', publish_item=True, start=datetime.datetime(2015, 4, 1, tzinfo=UTC), ) for i in range(10): problem = ItemFactory.create( category="problem", parent=vertical, display_name=u"A Problem Block %d" % i, weight=1, publish_item=False, metadata={'rerandomize': 'always'}, ) for j in students: grade = i % 2 StudentModuleFactory.create( grade=grade, max_grade=1, student=j, course_id=self.course.id, module_state_key=problem.location ) # check MongoDB calls count url = reverse('spoc_gradebook', kwargs={'course_id': self.course.id}) with check_mongo_calls(9): response = self.client.get(url) self.assertEqual(response.status_code, 200)
def setUp(self): """ Test case scaffolding """ super(EntranceExamTestCases, self).setUp() self.course = CourseFactory.create(metadata={ 'entrance_exam_enabled': True, }) chapter = ItemFactory.create(parent=self.course, display_name='Overview') ItemFactory.create(parent=chapter, display_name='Welcome') ItemFactory.create(parent=self.course, category='chapter', display_name="Week 1") ItemFactory.create(parent=chapter, category='sequential', display_name="Lesson 1") 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") self.exam_1 = ItemFactory.create( parent=self.entrance_exam, category='sequential', display_name="Exam Sequential - Subsection 1", graded=True, metadata={'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") milestone_namespace = generate_milestone_namespace( NAMESPACE_CHOICES['ENTRANCE_EXAM'], self.course.id) self.milestone = { 'name': 'Test Milestone', 'namespace': milestone_namespace, 'description': 'Testing Courseware Entrance Exam Chapter', } MilestoneRelationshipType.objects.create(name='requires', active=True) MilestoneRelationshipType.objects.create(name='fulfills', active=True) self.milestone_relationship_types = milestones_api.get_milestone_relationship_types( ) self.milestone = milestones_api.add_milestone(self.milestone) milestones_api.add_course_milestone( unicode(self.course.id), self.milestone_relationship_types['REQUIRES'], self.milestone) milestones_api.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.entrance_exam.is_entrance_exam = True self.entrance_exam.in_entrance_exam = True 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
def test_entrance_exam_gating(self): """ Unit Test: test_entrance_exam_gating """ # This user helps to cover a discovered bug in the milestone fulfillment logic chaos_user = UserFactory() 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' }]) locked_toc = toc_for_course(self.request, self.course, self.entrance_exam.url_name, self.exam_1.url_name, self.field_data_cache) for toc_section in expected_locked_toc: self.assertIn(toc_section, locked_toc) # Set up the chaos user # pylint: disable=maybe-no-member,no-member grade_dict = {'value': 1, 'max_value': 1, 'user_id': chaos_user.id} field_data_cache = FieldDataCache.cache_for_descriptor_descendents( self.course.id, chaos_user, self.course, depth=2) # pylint: disable=protected-access module = get_module( chaos_user, self.request, self.problem_1.scope_ids.usage_id, field_data_cache, )._xmodule module.system.publish(self.problem_1, 'grade', grade_dict) # pylint: disable=maybe-no-member,no-member grade_dict = { 'value': 1, 'max_value': 1, 'user_id': self.request.user.id } field_data_cache = FieldDataCache.cache_for_descriptor_descendents( self.course.id, self.request.user, self.course, depth=2) # pylint: disable=protected-access module = get_module( self.request.user, self.request, self.problem_1.scope_ids.usage_id, field_data_cache, )._xmodule module.system.publish(self.problem_1, 'grade', grade_dict) module = get_module( self.request.user, self.request, self.problem_2.scope_ids.usage_id, field_data_cache, )._xmodule # pylint: disable=protected-access module.system.publish(self.problem_2, 'grade', grade_dict) 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' }]) unlocked_toc = toc_for_course(self.request, self.course, self.entrance_exam.url_name, self.exam_1.url_name, self.field_data_cache) for toc_section in expected_unlocked_toc: self.assertIn(toc_section, unlocked_toc)
def setUp(self): self.user = UserFactory()
def setUp(self): super(TestRebindModule, self).setUp() self.homework = self.add_graded_section_to_course('homework') self.lti = ItemFactory.create(category='lti', parent=self.homework) self.user = UserFactory.create() self.anon_user = AnonymousUser()
def setUp(self): super(TestVideoOutline, self).setUp() self.user = UserFactory.create() self.course = CourseFactory.create(mobile_available=True) self.client.login(username=self.user.username, password='******')
def setUp(self): # Toy courses should be loaded self.course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall') self.toy_course = modulestore().get_course(self.course_key) self.portal_user = UserFactory()
def setUp(self): super(GroupAccessTestCase, self).setUp() UserPartition.scheme_extensions = ExtensionManager.make_test_instance( [ Extension("memory", USER_PARTITION_SCHEME_NAMESPACE, MemoryUserPartitionScheme(), None), Extension("random", USER_PARTITION_SCHEME_NAMESPACE, MemoryUserPartitionScheme(), None) ], namespace=USER_PARTITION_SCHEME_NAMESPACE) self.cat_group = Group(10, 'cats') self.dog_group = Group(20, 'dogs') self.worm_group = Group(30, 'worms') self.animal_partition = UserPartition( 0, 'Pet Partition', 'which animal are you?', [self.cat_group, self.dog_group, self.worm_group], scheme=UserPartition.get_scheme("memory"), ) self.red_group = Group(1000, 'red') self.blue_group = Group(2000, 'blue') self.gray_group = Group(3000, 'gray') self.color_partition = UserPartition( 100, 'Color Partition', 'what color are you?', [self.red_group, self.blue_group, self.gray_group], scheme=UserPartition.get_scheme("memory"), ) self.course = CourseFactory.create( user_partitions=[self.animal_partition, self.color_partition], ) with self.store.bulk_operations(self.course.id, emit_signals=False): chapter = ItemFactory.create(category='chapter', parent=self.course) section = ItemFactory.create(category='sequential', parent=chapter) vertical = ItemFactory.create(category='vertical', parent=section) component = ItemFactory.create(category='problem', parent=vertical) self.chapter_location = chapter.location self.section_location = section.location self.vertical_location = vertical.location self.component_location = component.location self.red_cat = UserFactory() # student in red and cat groups self.set_user_group(self.red_cat, self.animal_partition, self.cat_group) self.set_user_group(self.red_cat, self.color_partition, self.red_group) self.blue_dog = UserFactory() # student in blue and dog groups self.set_user_group(self.blue_dog, self.animal_partition, self.dog_group) self.set_user_group(self.blue_dog, self.color_partition, self.blue_group) self.white_mouse = UserFactory() # student in no group self.gray_worm = UserFactory() # student in deleted group self.set_user_group(self.gray_worm, self.animal_partition, self.worm_group) self.set_user_group(self.gray_worm, self.color_partition, self.gray_group) # delete the gray/worm groups from the partitions now so we can test scenarios # for user whose group is missing. self.animal_partition.groups.pop() self.color_partition.groups.pop() # add a staff user, whose access will be unconditional in spite of group access. self.staff = StaffFactory.create(course_key=self.course.id)
def setUp(self): super(InstructorTaskModuleSubmitTest, self).setUp() self.initialize_course() self.student = UserFactory.create(username="******", email="*****@*****.**") self.instructor = UserFactory.create(username="******", email="*****@*****.**")
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' ) 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_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): self.initialize_course() self.student = UserFactory.create(username="******", email="*****@*****.**") self.instructor = UserFactory.create(username="******", email="*****@*****.**")
def setUp(self): # Toy courses should be loaded self.course_name = 'edX/toy/2012_Fall' self.toy_course = modulestore().get_course(self.course_name) self.portal_user = UserFactory()
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' }])