def setUp(self): """ Set up courses and enrollments. """ super(TestStudentViewsWithCCX, self).setUp() # Create a Draft Mongo and a Split Mongo course and enroll a student user in them. self.student_password = "******" self.student = UserFactory.create(username="******", password=self.student_password, is_staff=False) self.draft_course = SampleCourseFactory.create(default_store=ModuleStoreEnum.Type.mongo) self.split_course = SampleCourseFactory.create(default_store=ModuleStoreEnum.Type.split) CourseEnrollment.enroll(self.student, self.draft_course.id) CourseEnrollment.enroll(self.student, self.split_course.id) # Create a CCX coach. self.coach = AdminFactory.create() role = CourseCcxCoachRole(self.split_course.id) role.add_users(self.coach) # Create a CCX course and enroll the user in it. self.ccx = CcxFactory(course_id=self.split_course.id, coach=self.coach) last_week = datetime.datetime.now(UTC()) - datetime.timedelta(days=7) override_field_for_ccx(self.ccx, self.split_course, 'start', last_week) # Required by self.ccx.has_started(). self.ccx_course_key = CCXLocator.from_course_locator(self.split_course.id, self.ccx.id) CourseEnrollment.enroll(self.student, self.ccx_course_key)
def setUp(self): super(TestBlockCountsTransformer, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course_key = SampleCourseFactory.create().id self.course_usage_key = self.store.make_course_usage_key( self.course_key) self.block_structure = BlockStructureFactory.create_from_modulestore( self.course_usage_key, self.store)
def setUp(self): super(TestBlockCountsTransformer, self).setUp() self.course_key = SampleCourseFactory.create().id self.course_usage_key = self.store.make_course_usage_key( self.course_key) self.block_structure = BlockStructureFactory.create_from_modulestore( self.course_usage_key, self.store)
def setUpClass(cls): super(TestGetBlocks, cls).setUpClass() cls.course = SampleCourseFactory.create() # hide the html block cls.html_block = cls.store.get_item(cls.course.id.make_usage_key("html", "html_x1a_1")) cls.html_block.visible_to_staff_only = True cls.store.update_item(cls.html_block, ModuleStoreEnum.UserID.test)
def setUpClass(cls): super(TestGetBlocks, cls).setUpClass() cls.course = SampleCourseFactory.create() # hide the html block cls.html_block = cls.store.get_item(cls.course.id.make_usage_key('html', 'html_x1a_1')) cls.html_block.visible_to_staff_only = True cls.store.update_item(cls.html_block, ModuleStoreEnum.UserID.test)
def setUpClass(cls): super(TestGetBlocks, cls).setUpClass() with cls.store.default_store(ModuleStoreEnum.Type.split): cls.course = SampleCourseFactory.create() # hide the html block cls.html_block = cls.store.get_item(cls.course.id.make_usage_key('html', 'html_x1a_1')) cls.html_block.visible_to_staff_only = True cls.store.update_item(cls.html_block, ModuleStoreEnum.UserID.test)
def setUp(self): super().setUp() self.course = SampleCourseFactory.create( other_course_settings=self.OTHER_COURSE_SETTINGS_DEFAULT) self.course_key = self.course.id self.course_usage_key = self.store.make_course_usage_key( self.course_key) self.block_structure = BlockStructureFactory.create_from_modulestore( self.course_usage_key, self.store)
def setUp(self): super(TestExtraFieldsTransformer, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = SampleCourseFactory.create( other_course_settings=self.OTHER_COURSE_SETTINGS_DEFAULT) self.course_key = self.course.id self.course_usage_key = self.store.make_course_usage_key( self.course_key) self.block_structure = BlockStructureFactory.create_from_modulestore( self.course_usage_key, self.store)
def test_hide_from_toc(self): course_key = SampleCourseFactory.create().id course_usage_key = self.store.make_course_usage_key(course_key) # hide chapter_x from TOC chapter_x_key = course_key.make_usage_key('chapter', 'chapter_x') chapter_x = self.store.get_item(chapter_x_key) chapter_x.hide_from_toc = True self.store.update_item(chapter_x, ModuleStoreEnum.UserID.test) block_structure = BlockStructureFactory.create_from_modulestore( course_usage_key, self.store) # collect phase BlockDepthTransformer.collect(block_structure) BlockNavigationTransformer.collect(block_structure) block_structure._collect_requested_xblock_fields() self.assertIn(chapter_x_key, block_structure) # transform phase BlockDepthTransformer().transform(usage_info=None, block_structure=block_structure) BlockNavigationTransformer(0).transform( usage_info=None, block_structure=block_structure) block_structure._prune_unreachable() self.assertIn(chapter_x_key, block_structure) course_descendants = block_structure.get_transformer_block_field( course_usage_key, BlockNavigationTransformer, BlockNavigationTransformer.BLOCK_NAVIGATION, ) # chapter_y and its descendants should be included for block_key in [ course_key.make_usage_key('chapter', 'chapter_y'), course_key.make_usage_key('sequential', 'sequential_y1'), course_key.make_usage_key('vertical', 'vertical_y1a'), course_key.make_usage_key('problem', 'problem_y1a_1'), ]: self.assertIn(six.text_type(block_key), course_descendants) # chapter_x and its descendants should not be included for block_key in [ chapter_x_key, course_key.make_usage_key('sequential', 'sequential_x1'), course_key.make_usage_key('vertical', 'vertical_x1a'), course_key.make_usage_key('problem', 'problem_x1a_1'), ]: self.assertNotIn(six.text_type(block_key), course_descendants)
def test_hide_from_toc(self): course_key = SampleCourseFactory.create().id course_usage_key = self.store.make_course_usage_key(course_key) # hide chapter_x from TOC chapter_x_key = course_key.make_usage_key('chapter', 'chapter_x') chapter_x = self.store.get_item(chapter_x_key) chapter_x.hide_from_toc = True self.store.update_item(chapter_x, ModuleStoreEnum.UserID.test) block_structure = BlockStructureFactory.create_from_modulestore(course_usage_key, self.store) # collect phase BlockDepthTransformer.collect(block_structure) BlockNavigationTransformer.collect(block_structure) block_structure._collect_requested_xblock_fields() self.assertIn(chapter_x_key, block_structure) # transform phase BlockDepthTransformer().transform(usage_info=None, block_structure=block_structure) BlockNavigationTransformer(0).transform(usage_info=None, block_structure=block_structure) block_structure._prune_unreachable() self.assertIn(chapter_x_key, block_structure) course_descendants = block_structure.get_transformer_block_field( course_usage_key, BlockNavigationTransformer, BlockNavigationTransformer.BLOCK_NAVIGATION, ) # chapter_y and its descendants should be included for block_key in [ course_key.make_usage_key('chapter', 'chapter_y'), course_key.make_usage_key('sequential', 'sequential_y1'), course_key.make_usage_key('vertical', 'vertical_y1a'), course_key.make_usage_key('problem', 'problem_y1a_1'), ]: self.assertIn(unicode(block_key), course_descendants) # chapter_x and its descendants should not be included for block_key in [ chapter_x_key, course_key.make_usage_key('sequential', 'sequential_x1'), course_key.make_usage_key('vertical', 'vertical_x1a'), course_key.make_usage_key('problem', 'problem_x1a_1'), ]: self.assertNotIn(unicode(block_key), course_descendants)
def setUpClass(cls): super(TestGetBlocksMobileHack, cls).setUpClass() with cls.store.default_store(ModuleStoreEnum.Type.split): cls.course = SampleCourseFactory.create(block_info_tree=[ BlockInfo('empty_chapter', 'chapter', {}, [ BlockInfo('empty_sequential', 'sequential', {}, [ BlockInfo('empty_vertical', 'vertical', {}, []), ]), ]), BlockInfo('full_chapter', 'chapter', {}, [ BlockInfo('full_sequential', 'sequential', {}, [ BlockInfo('full_vertical', 'vertical', {}, [ BlockInfo('html', 'html', {}, []), ]), ]), ]) ])
def setUpClass(cls): super(TestGetBlocksMobileHack, cls).setUpClass() with cls.store.default_store(ModuleStoreEnum.Type.split): cls.course = SampleCourseFactory.create( block_info_tree=[ BlockInfo('empty_chapter', 'chapter', {}, [ BlockInfo('empty_sequential', 'sequential', {}, [ BlockInfo('empty_vertical', 'vertical', {}, []), ]), ]), BlockInfo('full_chapter', 'chapter', {}, [ BlockInfo('full_sequential', 'sequential', {}, [ BlockInfo('full_vertical', 'vertical', {}, [ BlockInfo('html', 'html', {}, []), ]), ]), ]) ] )
def setUp(self): super(TestCourseMixin, self).setUp() with modulestore().default_store(ModuleStoreEnum.Type.split): self.course = SampleCourseFactory.create( block_info_tree=TEST_COURSE) # And upload the course static asssets: asset_key = StaticContent.compute_location(self.course.id, 'sample_handout.txt') content = StaticContent(asset_key, "Fake asset", "application/text", "test".encode('utf8')) contentstore().save(content) asset_key = StaticContent.compute_location(self.course.id, 'edx.svg') content = StaticContent( asset_key, "Fake image", "image/svg+xml", """ <svg viewBox="0 0 403 403" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" > <title>edX</title> <desc> the edX logo is comprised of a red letter e, grey d, and blue uppercase X, all slightly overlapping each other. The d is slightly transparent. </desc> <g transform="translate(0,100)"> <path id="e-path" stroke-width="1" stroke="none" fill="rgb(185, 0, 88)" fill-rule="evenodd" d="M32.1,127 H141.9 A71,71.5 0 1,0 137.3,143 H103 A42,42 0 0,1 32.1,127 M32.1,102.5 H112 A42,42 0 0,0 32.1,102.5"/> <path id="x-path" stroke-width="1" stroke="none" fill="rgb(0, 162, 228)" fill-rule="evenodd" d="M228,1 H302 V31 H286 L315,67 L344,31 H328 V1 H401.5 V31 H385 L335.2,92.4 L387.5,156.8 H401.5 V187 H328 V156.8 H346.5 L315,117.4 L283,156.8 H302.0 V187 H228.5 V156.8 H243 L294.3,92.4 L244,30.5 H228 V1"/> <path id="d-path" stroke-width="1" stroke="none" fill="rgb(55, 55, 60)" fill-rule="evenodd" opacity="0.55" d="M198.5,1 L248,1 V156.5 H269.8 V187 H217.5 V174 A71.7,71.7 0 1,1 218,55.5 V30.5 H198.5 V1 M218,114 A41,41.5 0 1,1 136.1,114 A40.5,40.5 0 1,1 218,114"/> </g> </svg> """.strip().encode('utf8')) contentstore().save(content) # And the video data + transcript must also be stored in edx-val for the video export to work: edxval_api.create_video(VIDEO_B_VAL_DATA) edxval_api.create_video_transcript(**VIDEO_B_SRT_TRANSCRIPT_DATA)
def _create_course(self, store_type): """ Creates the sample course in the given store type. """ with self.store.default_store(store_type): return SampleCourseFactory.create()
def setUp(self): super(TestGetBlocks, self).setUp() self.course = SampleCourseFactory.create() self.user = UserFactory.create() self.request = RequestFactory().get("/dummy") self.request.user = self.user
def setUp(self): super().setUp() block_info_tree = [ BlockInfo('Section', 'chapter', {}, [ BlockInfo('Subsection', 'sequential', {}, [ BlockInfo('Vertical', 'vertical', {}, [ BlockInfo( 'Clip', 'video', { 'edx_video_id': 'edxval1', 'start_time': timedelta(seconds=20), 'end_time': timedelta(seconds=60) }, []), BlockInfo('Video', 'video', {'edx_video_id': 'edxval2'}, []), BlockInfo('Web', 'video', { 'edx_video_id': 'edxval3', 'only_on_web': True }, []), BlockInfo('HTML', 'html', {'data': 'Hello World'}, []), BlockInfo('Problem1', 'problem', {}, []), BlockInfo('Problem2', 'problem', {}, []), ]), ]), ]), ] self.course_key = SampleCourseFactory.create( block_info_tree=block_info_tree).id self.course_usage_key = self.store.make_course_usage_key( self.course_key) self.block_structure = BlockStructureFactory.create_from_modulestore( self.course_usage_key, self.store) self.section_key = self.course_key.make_usage_key('chapter', 'Section') self.subsection_key = self.course_key.make_usage_key( 'sequential', 'Subsection') self.vertical_key = self.course_key.make_usage_key( 'vertical', 'Vertical') self.video_clip_key = self.course_key.make_usage_key('video', 'Clip') self.video_normal_key = self.course_key.make_usage_key( 'video', 'Video') self.video_web_key = self.course_key.make_usage_key('video', 'Web') self.html_key = self.course_key.make_usage_key('html', 'HTML') # Set edxval data create_video({ 'edx_video_id': 'edxval1', 'status': 'uploaded', 'client_video_id': 'Clip Video', 'duration': 200, 'encoded_videos': [], 'courses': [str(self.course_key)], }) create_video({ 'edx_video_id': 'edxval2', 'status': 'uploaded', 'client_video_id': 'Normal Video', 'duration': 30, 'encoded_videos': [], 'courses': [str(self.course_key)], }) create_video({ 'edx_video_id': 'edxval3', 'status': 'uploaded', 'client_video_id': 'Web Video', 'duration': 50, 'encoded_videos': [], 'courses': [str(self.course_key)], })
def setUp(self): super(TestBlockCountsTransformer, self).setUp() self.course_key = SampleCourseFactory.create().id self.course_usage_key = self.store.make_course_usage_key(self.course_key) self.block_structure = BlockStructureFactory.create_from_modulestore(self.course_usage_key, self.store)