INCR-166 Run python-modernize on openedx/core/djangolib (#20473)
* INCR-166 Run python-modernize on openedx/core/djangolib * INCR-166 disabled harmless errors and added docstring
This commit is contained in:
committed by
Jeremy Bowman
parent
d03f970be6
commit
140fb1394e
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Custom Django fields.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from django.db import models
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Utilities for dealing with Javascript and JSON.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
import json
|
||||
|
||||
from django.utils.html import escapejs
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
Utilities for use in Mako markup.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import markupsafe
|
||||
import bleach
|
||||
from mako.filters import decode
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
Removes user PII from OAuth2 models.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from oauth2_provider.models import (
|
||||
AccessToken as DOTAccessToken,
|
||||
Application as DOTApplication,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Test that testing utils do what they say.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from crum import set_current_request
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
@@ -8,6 +8,7 @@ Utility classes for testing django applications.
|
||||
A TestCase baseclass that has per-test isolated caches.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import copy
|
||||
import re
|
||||
from unittest import skipUnless
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
"""
|
||||
Tests for js_utils.py
|
||||
"""
|
||||
import HTMLParser
|
||||
from __future__ import absolute_import
|
||||
import six.moves.html_parser # pylint: disable=import-error
|
||||
import json
|
||||
from unittest import TestCase
|
||||
|
||||
from mako.template import Template
|
||||
|
||||
from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_string
|
||||
import six # pylint: disable=ungrouped-imports
|
||||
|
||||
|
||||
class TestJSUtils(TestCase):
|
||||
@@ -71,7 +73,7 @@ class TestJSUtils(TestCase):
|
||||
"""
|
||||
malicious_js_string = "</script><script>alert('hello, ');</script>"
|
||||
|
||||
expected_escaped_string_for_js = unicode(
|
||||
expected_escaped_string_for_js = six.text_type(
|
||||
r"\u003C/script\u003E\u003Cscript\u003Ealert(\u0027hello, \u0027)\u003B\u003C/script\u003E"
|
||||
)
|
||||
escaped_string_for_js = js_escaped_string(malicious_js_string)
|
||||
@@ -179,7 +181,7 @@ class TestJSUtils(TestCase):
|
||||
should be parseable into a near equivalent to test_dict.
|
||||
|
||||
"""
|
||||
html_parser = HTMLParser.HTMLParser()
|
||||
html_parser = six.moves.html_parser.HTMLParser()
|
||||
|
||||
expected_json = html_parser.unescape(expected_json_for_html_string)
|
||||
parsed_expected_dict = json.loads(expected_json)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
Tests for openedx.core.djangolib.markup
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import unittest
|
||||
|
||||
import ddt
|
||||
@@ -11,6 +12,7 @@ from django.utils.translation import ungettext
|
||||
from mako.template import Template
|
||||
|
||||
from openedx.core.djangolib.markup import HTML, Text, strip_all_tags_but_br
|
||||
import six
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@@ -27,8 +29,8 @@ class FormatHtmlTest(unittest.TestCase):
|
||||
)
|
||||
def test_simple(self, before_after):
|
||||
(before, after) = before_after
|
||||
self.assertEqual(unicode(Text(_(before))), after)
|
||||
self.assertEqual(unicode(Text(before)), after)
|
||||
self.assertEqual(six.text_type(Text(_(before))), after) # pylint: disable=translation-of-non-string
|
||||
self.assertEqual(six.text_type(Text(before)), after)
|
||||
|
||||
def test_formatting(self):
|
||||
# The whole point of this function is to make sure this works:
|
||||
@@ -37,7 +39,7 @@ class FormatHtmlTest(unittest.TestCase):
|
||||
end=HTML("</a>"),
|
||||
)
|
||||
self.assertEqual(
|
||||
unicode(out),
|
||||
six.text_type(out),
|
||||
u"Point & click <a href='http://edx.org'>here</a>!",
|
||||
)
|
||||
|
||||
@@ -49,7 +51,7 @@ class FormatHtmlTest(unittest.TestCase):
|
||||
end=HTML("</a>"),
|
||||
)
|
||||
self.assertEqual(
|
||||
unicode(out),
|
||||
six.text_type(out),
|
||||
u"Send <a href='mailto:A&B'>email</a>",
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
Contains tests for OAuth2 model-retirement methods.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import datetime
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
Tests for openedx.core.djangolib.translation_utils
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import unittest
|
||||
|
||||
import datetime
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
i18n utility functions
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from django.utils.translation import ugettext as _, override
|
||||
from django.utils.formats import dateformat, get_format
|
||||
|
||||
|
||||
Reference in New Issue
Block a user