diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 5adcbf55f75ba21faee4374affd4fcc7745c6d57..851eb4bac878d703d80b1a63ed66cca2978e3964 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -4,18 +4,24 @@ Tests courseware views.py """ +import html import itertools import json import unittest from datetime import datetime, timedelta -from pytz import utc from uuid import uuid4 -import crum -import ddt import six +from markupsafe import escape +from mock import MagicMock, PropertyMock, call, create_autospec, patch +from pytz import UTC, utc +from six import text_type +from six.moves import range +from six.moves.urllib.parse import quote, urlencode + from completion.test_utils import CompletionWaffleTestMixin from crum import set_current_request +import ddt from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.http import Http404, HttpResponseBadRequest @@ -24,32 +30,17 @@ from django.test.client import Client from django.test.utils import override_settings from django.urls import reverse, reverse_lazy from freezegun import freeze_time -from markupsafe import escape from milestones.tests.utils import MilestonesTestCaseMixin -from mock import MagicMock, PropertyMock, call, create_autospec, patch +from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator -from pytz import UTC -from six import text_type -from six.moves import range -from six.moves.html_parser import HTMLParser -from six.moves.urllib.parse import quote, urlencode from web_fragments.fragment import Fragment from xblock.core import XBlock from xblock.fields import Scope, String - import lms.djangoapps.courseware.views.views as views from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory from course_modes.models import CourseMode from course_modes.tests.factories import CourseModeFactory -from lms.djangoapps.courseware.access_utils import check_course_open_for_learner -from lms.djangoapps.courseware.model_data import FieldDataCache, set_score -from lms.djangoapps.courseware.module_render import get_module, handle_xblock_callback -from lms.djangoapps.courseware.tests.factories import GlobalStaffFactory, RequestFactoryNoCsrf, StudentModuleFactory -from lms.djangoapps.courseware.tests.helpers import get_expiration_banner_text -from lms.djangoapps.courseware.testutils import RenderXBlockTestMixin -from lms.djangoapps.courseware.url_helpers import get_redirect_url -from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient from lms.djangoapps.certificates import api as certs_api from lms.djangoapps.certificates.models import ( CertificateGenerationConfiguration, @@ -59,17 +50,23 @@ from lms.djangoapps.certificates.models import ( from lms.djangoapps.certificates.tests.factories import CertificateInvalidationFactory, GeneratedCertificateFactory from lms.djangoapps.commerce.models import CommerceConfiguration from lms.djangoapps.commerce.utils import EcommerceService -from lms.djangoapps.courseware.views.index import show_courseware_mfe_link +from lms.djangoapps.courseware.access_utils import check_course_open_for_learner +from lms.djangoapps.courseware.model_data import FieldDataCache, set_score +from lms.djangoapps.courseware.module_render import get_module, handle_xblock_callback +from lms.djangoapps.courseware.tests.factories import GlobalStaffFactory, RequestFactoryNoCsrf, StudentModuleFactory +from lms.djangoapps.courseware.tests.helpers import get_expiration_banner_text +from lms.djangoapps.courseware.testutils import RenderXBlockTestMixin from lms.djangoapps.courseware.toggles import ( COURSEWARE_MICROFRONTEND_COURSE_TEAM_PREVIEW, - REDIRECT_TO_COURSEWARE_MICROFRONTEND, + REDIRECT_TO_COURSEWARE_MICROFRONTEND ) -from lms.djangoapps.courseware.url_helpers import get_microfrontend_url +from lms.djangoapps.courseware.url_helpers import get_microfrontend_url, get_redirect_url +from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient +from lms.djangoapps.courseware.views.index import show_courseware_mfe_link from lms.djangoapps.grades.config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT from lms.djangoapps.grades.config.waffle import waffle as grades_waffle from lms.djangoapps.verify_student.models import VerificationDeadline from lms.djangoapps.verify_student.services import IDVerificationService -from opaque_keys.edx.keys import CourseKey, UsageKey from openedx.core.djangoapps.catalog.tests.factories import CourseFactory as CatalogCourseFactory from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory, ProgramFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview @@ -100,7 +97,6 @@ from xmodule.course_module import COURSE_VISIBILITY_PRIVATE, COURSE_VISIBILITY_P from xmodule.graders import ShowCorrectness from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore - from xmodule.modulestore.tests.django_utils import ( TEST_DATA_MIXED_MODULESTORE, TEST_DATA_SPLIT_MODULESTORE, @@ -694,7 +690,7 @@ class ViewsTestCase(BaseViewsTestCase): 'location': six.text_type(usage_key), }) response = self.client.get(url) - response_content = HTMLParser().unescape(response.content.decode('utf-8')) + response_content = html.unescape(response.content.decode('utf-8')) # We have update the state 4 times: twice to change content, and twice # to set the scores. We'll check that the identifying content from each is diff --git a/openedx/core/djangoapps/credit/email_utils.py b/openedx/core/djangoapps/credit/email_utils.py index c113ccbe31195944913f2e0ce440dc90ebaf6681..9433021ee8f9c814370a188de59431f8c0a6768a 100644 --- a/openedx/core/djangoapps/credit/email_utils.py +++ b/openedx/core/djangoapps/credit/email_utils.py @@ -6,6 +6,7 @@ This file contains utility functions which will responsible for sending emails. import logging import os import uuid +import html from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart @@ -106,8 +107,7 @@ def send_credit_notifications(username, course_key): cur_text = cur_file.read() # use html parser to unescape html characters which are changed # by the 'pynliner' while adding inline css to html content - html_parser = six.moves.html_parser.HTMLParser() - email_body_content = html_parser.unescape(with_inline_css(cur_text)) + email_body_content = html.unescape(with_inline_css(cur_text)) # cache the email body content before rendering it since the # email context will change for each user e.g., 'full_name' cache.set('credit.email.css-email-body', email_body_content, settings.CREDIT_NOTIFICATION_CACHE_TIMEOUT) diff --git a/openedx/core/djangolib/tests/test_js_utils.py b/openedx/core/djangolib/tests/test_js_utils.py index 024a11c89bedc1fc2d85e9cfff33555d6c7338cb..f427335cab8da8caaa514d9c3d8a02b64f6da6c5 100644 --- a/openedx/core/djangolib/tests/test_js_utils.py +++ b/openedx/core/djangolib/tests/test_js_utils.py @@ -6,6 +6,7 @@ Tests for js_utils.py import json import re +import html from unittest import TestCase import six @@ -184,9 +185,8 @@ class TestJSUtils(TestCase): should be parseable into a near equivalent to test_dict. """ - html_parser = six.moves.html_parser.HTMLParser() - expected_json = html_parser.unescape(expected_json_for_html_string) + expected_json = html.unescape(expected_json_for_html_string) parsed_expected_dict = json.loads(expected_json) # tuples become arrays in json, so it is parsed to a list that is # switched back to a tuple before comparing diff --git a/openedx/tests/xblock_integration/xblock_testcase.py b/openedx/tests/xblock_integration/xblock_testcase.py index 40ff73e74fea19ceed12474a072cbaf1cfd2d992..961d0d8b8b7525986d9ea12e24007a1f30396717 100644 --- a/openedx/tests/xblock_integration/xblock_testcase.py +++ b/openedx/tests/xblock_integration/xblock_testcase.py @@ -41,6 +41,7 @@ import json import sys import unittest from datetime import datetime, timedelta +import html import mock import pytz @@ -466,7 +467,7 @@ class XBlockTestCase(XBlockStudentTestCaseMixin, print("Dice 2", repr(xblock_html.split('<')[1].split('>')[1]), file=sys.stderr) raise # Finally, we unescape the contents - decoded_html = six.moves.html_parser.HTMLParser().unescape(escaped_html).strip() + decoded_html = html.unescape(escaped_html).strip() return decoded_html