Пример #1
0
 def test_substitution_without_anonymous_student_id(self):
     sample_xml = '''%%USER_ID%%'''
     field_data = DictFieldData({'data': sample_xml})
     module_system = get_test_system()
     module_system.anonymous_student_id = None
     module = HtmlBlock(module_system, field_data, Mock())
     assert module.get_html() == sample_xml
Пример #2
0
 def test_substitution_user_id(self):
     sample_xml = '''%%USER_ID%%'''
     field_data = DictFieldData({'data': sample_xml})
     module_system = get_test_system()
     module = HtmlBlock(module_system, field_data, Mock())
     self.assertEqual(module.get_html(),
                      str(module_system.anonymous_student_id))
Пример #3
0
 def test_substitution_without_magic_string(self):
     sample_xml = '''
         <html>
             <p>Hi USER_ID!11!</p>
         </html>
     '''
     field_data = DictFieldData({'data': sample_xml})
     module_system = get_test_system()
     module = HtmlBlock(module_system, field_data, Mock())
     assert module.get_html() == sample_xml
Пример #4
0
    def test_disabled(self, settings):
        """
        Ensure that student_view_data does not return html if the ENABLE_HTML_XBLOCK_STUDENT_VIEW_DATA feature flag
        is not set.
        """
        field_data = DictFieldData({'data': '<h1>Some HTML</h1>'})
        module_system = get_test_system()
        module = HtmlBlock(module_system, field_data, Mock())

        with override_settings(**settings):
            assert module.student_view_data() ==\
                   dict(enabled=False, message='To enable, set FEATURES["ENABLE_HTML_XBLOCK_STUDENT_VIEW_DATA"]')
Пример #5
0
 def test_substitution_course_id(self):
     sample_xml = '''%%COURSE_ID%%'''
     field_data = DictFieldData({'data': sample_xml})
     module_system = get_test_system()
     module = HtmlBlock(module_system, field_data, Mock())
     course_key = CourseLocator(org='some_org',
                                course='some_course',
                                run='some_run')
     usage_key = BlockUsageLocator(course_key=course_key,
                                   block_type='problem',
                                   block_id='block_id')
     module.scope_ids.usage_id = usage_key
     assert module.get_html() == str(course_key)
Пример #6
0
    def test_common_values(self, html):
        """
        Ensure that student_view_data will return HTML data when enabled,
        can handle likely input,
        and doesn't modify the HTML in any way.

        This means that it does NOT protect against XSS, escape HTML tags, etc.

        Note that the %%USER_ID%% substitution is tested below.
        """
        field_data = DictFieldData({'data': html})
        module_system = get_test_system()
        module = HtmlBlock(module_system, field_data, Mock())
        assert module.student_view_data() == dict(enabled=True, html=html)
Пример #7
0
 def test_student_preview_view(self, view):
     """
     Ensure that student_view and public_view renders correctly.
     """
     html = '<p>This is a test</p>'
     field_data = DictFieldData({'data': html})
     module_system = get_test_system()
     module = HtmlBlock(module_system, field_data, Mock())
     rendered = module_system.render(module, view, {}).content
     assert html in rendered
def _section_send_email(course, access):
    """ Provide data for the corresponding bulk email section """
    course_key = course.id

    # Monkey-patch applicable_aside_types to return no asides for the duration of this render
    with patch.object(course.runtime, 'applicable_aside_types', null_applicable_aside_types):
        # This HtmlBlock is only being used to generate a nice text editor.
        html_module = HtmlBlock(
            course.system,
            DictFieldData({'data': ''}),
            ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake'))
        )
        fragment = course.system.render(html_module, 'studio_view')
    fragment = wrap_xblock(
        'LmsRuntime', html_module, 'studio_view', fragment, None,
        extra_data={"course-id": str(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(str(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().hex
    )
    cohorts = []
    if is_course_cohorted(course_key):
        cohorts = get_course_cohorts(course)
    course_modes = []
    if not VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key):
        course_modes = CourseMode.modes_for_course(course_key, include_expired=True, only_selectable=False)
    email_editor = fragment.content
    section_data = {
        'section_key': 'send_email',
        'section_display_name': _('Email'),
        'access': access,
        'send_email': reverse('send_email', kwargs={'course_id': str(course_key)}),
        'editor': email_editor,
        'cohorts': cohorts,
        'course_modes': course_modes,
        'default_cohort_name': DEFAULT_COHORT_NAME,
        'list_instructor_tasks_url': reverse(
            'list_instructor_tasks', kwargs={'course_id': str(course_key)}
        ),
        'email_background_tasks_url': reverse(
            'list_background_email_tasks', kwargs={'course_id': str(course_key)}
        ),
        'email_content_history_url': reverse(
            'list_email_content', kwargs={'course_id': str(course_key)}
        ),
    }
    if settings.FEATURES.get("ENABLE_NEW_BULK_EMAIL_EXPERIENCE", False) is not False:
        section_data[
            "communications_mfe_url"
        ] = f"{settings.COMMUNICATIONS_MICROFRONTEND_URL}/courses/{str(course_key)}/bulk_email"
    return section_data
Пример #9
0
 def test_get_some_templates(self):
     self.assertEqual(len(SequenceBlock.templates()), 0)
     self.assertGreater(len(HtmlBlock.templates()), 0)
     self.assertIsNone(SequenceBlock.get_template('doesntexist.yaml'))
     self.assertIsNone(HtmlBlock.get_template('doesntexist.yaml'))
     self.assertIsNotNone(HtmlBlock.get_template('announcement.yaml'))