def test_preview_no_asides(self): """ Test for calling get_preview_html. Ensures data-usage-id is correctly set and asides are correctly excluded because they are not enabled. """ course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) html = ItemFactory.create( parent_location=course.location, category="html", data={'data': "<html>foobar</html>"} ) config = StudioConfig.current() config.enabled = False config.save() request = RequestFactory().get('/dummy-url') request.user = UserFactory() request.session = {} # Call get_preview_fragment directly. context = { 'reorderable_items': set(), 'read_only': True } html = get_preview_fragment(request, html, context).content self.assertNotRegexpMatches(html, r"data-block-type=[\"\']test_aside[\"\']") self.assertNotRegexpMatches(html, "Aside rendered")
def test_preview_no_asides(self): """ Test for calling get_preview_html. Ensures data-usage-id is correctly set and asides are correctly excluded because they are not enabled. """ course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) html = ItemFactory.create(parent_location=course.location, category="html", data={'data': "<html>foobar</html>"}) config = StudioConfig.current() config.enabled = False config.save() request = RequestFactory().get('/dummy-url') request.user = UserFactory() request.session = {} # Call get_preview_fragment directly. context = {'reorderable_items': set(), 'read_only': True} html = get_preview_fragment(request, html, context).content self.assertNotRegexpMatches(html, r"data-block-type=[\"\']test_aside[\"\']") self.assertNotRegexpMatches(html, "Aside rendered")
def applicable_aside_types(self, block): """ Remove acid_aside and honor the config record """ if not StudioConfig.asides_enabled(block.scope_ids.block_type): return [] return [ aside_type for aside_type in super(PreviewModuleSystem, self).applicable_aside_types(block) if aside_type != 'acid_aside' ]
def setUp(self): """ Preparation for the test execution """ self.user_password = super(StructuredTagsAsideTestCase, self).setUp() self.aside_name = 'tagging_aside' self.aside_tag = 'difficulty_tag' self.aside_tag_value = 'hard' course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) self.course = ItemFactory.create( parent_location=course.location, category="course", display_name="Test course", ) self.chapter = ItemFactory.create( parent_location=self.course.location, category='chapter', display_name="Week 1", publish_item=True, start=datetime(2015, 3, 1, tzinfo=UTC), ) self.sequential = ItemFactory.create( parent_location=self.chapter.location, category='sequential', display_name="Lesson 1", publish_item=True, start=datetime(2015, 3, 1, tzinfo=UTC), ) self.vertical = ItemFactory.create( parent_location=self.sequential.location, category='vertical', display_name='Subsection 1', publish_item=True, start=datetime(2015, 4, 1, tzinfo=UTC), ) self.problem = ItemFactory.create( category="problem", parent_location=self.vertical.location, display_name="A Problem Block", weight=1, user_id=self.user.id, publish_item=False, ) self.video = ItemFactory.create( parent_location=self.vertical.location, category='video', display_name='My Video', user_id=self.user.id ) config = StudioConfig.current() config.enabled = True config.save()
def setUp(self): """ Preparation for the test execution """ self.user_password = super(StructuredTagsAsideTestCase, self).setUp() self.aside_name = 'tagging_aside' self.aside_tag = 'difficulty_tag' self.aside_tag_value = 'hard' course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) self.course = ItemFactory.create( parent_location=course.location, category="course", display_name="Test course", ) self.chapter = ItemFactory.create( parent_location=self.course.location, category='chapter', display_name="Week 1", publish_item=True, start=datetime(2015, 3, 1, tzinfo=UTC), ) self.sequential = ItemFactory.create( parent_location=self.chapter.location, category='sequential', display_name="Lesson 1", publish_item=True, start=datetime(2015, 3, 1, tzinfo=UTC), ) self.vertical = ItemFactory.create( parent_location=self.sequential.location, category='vertical', display_name='Subsection 1', publish_item=True, start=datetime(2015, 4, 1, tzinfo=UTC), ) self.problem = ItemFactory.create( category="problem", parent_location=self.vertical.location, display_name="A Problem Block", weight=1, user_id=self.user.id, publish_item=False, ) self.video = ItemFactory.create(parent_location=self.vertical.location, category='video', display_name='My Video', user_id=self.user.id) config = StudioConfig.current() config.enabled = True config.save()
def applicable_aside_types(self, block): """ Remove acid_aside and honor the config record """ if not StudioConfig.asides_enabled(block.scope_ids.block_type): return [] # TODO: aside_type != 'acid_aside' check should be removed once AcidBlock is only installed during tests # (see https://openedx.atlassian.net/browse/TE-811) return [ aside_type for aside_type in super(PreviewModuleSystem, self). applicable_aside_types(block) if aside_type != 'acid_aside' ]
def applicable_aside_types(self, block): """ Remove acid_aside and honor the config record """ if not StudioConfig.asides_enabled(block.scope_ids.block_type): return [] # TODO: aside_type != 'acid_aside' check should be removed once AcidBlock is only installed during tests # (see https://openedx.atlassian.net/browse/TE-811) return [ aside_type for aside_type in super( PreviewModuleSystem, self).applicable_aside_types(block) if aside_type != 'acid_aside' ]
def test_preview_fragment(self): """ Test for calling get_preview_html. Ensures data-usage-id is correctly set and asides are correctly included. """ course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) html = ItemFactory.create( parent_location=course.location, category="html", data={'data': "<html>foobar</html>"} ) config = StudioConfig.current() config.enabled = True config.save() request = RequestFactory().get('/dummy-url') request.user = UserFactory() request.session = {} # Call get_preview_fragment directly. context = { 'reorderable_items': set(), 'read_only': True } html = get_preview_fragment(request, html, context).content # Verify student view html is returned, and the usage ID is as expected. html_pattern = re.escape(unicode(course.id.make_usage_key('html', 'replaceme'))).replace('replaceme', r'html_[0-9]*') self.assertRegexpMatches( html, 'data-usage-id="{}"'.format(html_pattern) ) self.assertRegexpMatches(html, '<html>foobar</html>') self.assertRegexpMatches(html, r"data-block-type=[\"\']test_aside[\"\']") self.assertRegexpMatches(html, "Aside rendered") # Now ensure the acid_aside is not in the result self.assertNotRegexpMatches(html, r"data-block-type=[\"\']acid_aside[\"\']") # Ensure about pages don't have asides about = modulestore().get_item(course.id.make_usage_key('about', 'overview')) html = get_preview_fragment(request, about, context).content self.assertNotRegexpMatches(html, r"data-block-type=[\"\']test_aside[\"\']") self.assertNotRegexpMatches(html, "Aside rendered")
def setUp(self): """ Preparation for the test execution """ super(StructuredTagsAsideTestCase, self).setUp() self.aside_name = 'tagging_aside' self.aside_tag_dif = 'difficulty' self.aside_tag_dif_value = 'Hard' self.aside_tag_lo = 'learning_outcome' course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) self.course = ItemFactory.create( parent_location=course.location, category="course", display_name="Test course", ) self.chapter = ItemFactory.create( parent_location=self.course.location, category='chapter', display_name="Week 1", publish_item=True, start=datetime(2015, 3, 1, tzinfo=UTC), ) self.sequential = ItemFactory.create( parent_location=self.chapter.location, category='sequential', display_name="Lesson 1", publish_item=True, start=datetime(2015, 3, 1, tzinfo=UTC), ) self.vertical = ItemFactory.create( parent_location=self.sequential.location, category='vertical', display_name='Subsection 1', publish_item=True, start=datetime(2015, 4, 1, tzinfo=UTC), ) self.problem = ItemFactory.create( category="problem", parent_location=self.vertical.location, display_name="A Problem Block", weight=1, user_id=self.user.id, publish_item=False, ) self.video = ItemFactory.create( parent_location=self.vertical.location, category='video', display_name='My Video', user_id=self.user.id ) _init_data = [ { 'name': 'difficulty', 'title': 'Difficulty', 'values': ['Easy', 'Medium', 'Hard'], }, { 'name': 'learning_outcome', 'title': 'Learning outcome', 'values': ['Learned nothing', 'Learned a few things', 'Learned everything'] } ] for tag in _init_data: category = TagCategories.objects.create(name=tag['name'], title=tag['title']) for val in tag['values']: TagAvailableValues.objects.create(category=category, value=val) config = StudioConfig.current() config.enabled = True config.save()