Merge pull request #21337 from edx/feanil/fix_lms_test_collection

Get LMS test collection working in python 3.
This commit is contained in:
Feanil Patel
2019-08-14 14:44:10 -04:00
committed by GitHub
4 changed files with 13 additions and 11 deletions

View File

@@ -4,7 +4,6 @@ Tests for Blocks Views
from __future__ import absolute_import
from datetime import datetime
from string import join
import six
from six.moves.urllib.parse import urlencode, urlunparse # pylint: disable=import-error
@@ -239,7 +238,7 @@ class TestBlocksView(SharedModuleStoreTestCase):
query = urlencode(list(self.query_params.items()) + [
('requested_fields', self.requested_fields[0]),
('requested_fields', self.requested_fields[1]),
('requested_fields', join(self.requested_fields[1:], ',')),
('requested_fields', ",".join(self.requested_fields[1:])),
])
self.query_params = None
response = self.verify_response(

View File

@@ -6,6 +6,7 @@ from __future__ import absolute_import
import json
import re
import six
from django.conf import settings
from django.contrib.auth.models import User
@@ -36,7 +37,8 @@ class BaseI18nTestCase(CacheIsolationTestCase):
def assert_tag_has_attr(self, content, tag, attname, value):
"""Assert that a tag in `content` has a certain value in a certain attribute."""
regex = ur"""<{tag} [^>]*\b{attname}=['"]([\w\d\- ]+)['"][^>]*>""".format(tag=tag, attname=attname)
regex_string = six.text_type(r"""<{tag} [^>]*\b{attname}=['"]([\w\d\- ]+)['"][^>]*>""") # noqa: W605,E501 pylint: disable=unicode-format-string
regex = regex_string.format(tag=tag, attname=attname)
match = re.search(regex, content)
self.assertTrue(match, u"Couldn't find desired tag '%s' with attr '%s' in %r" % (tag, attname, content))
attvalues = match.group(1).split()

View File

@@ -34,7 +34,7 @@ from .test_video_xml import SOURCE_XML
TRANSCRIPT = {"start": [10], "end": [100], "text": ["Hi, welcome to Edx."]}
BUMPER_TRANSCRIPT = {"start": [1], "end": [10], "text": ["A bumper"]}
SRT_content = textwrap.dedent("""
SRT_content = textwrap.dedent(u"""
0
00:00:00,12 --> 00:00:00,100
Привіт, edX вітає вас.
@@ -46,9 +46,10 @@ def _create_srt_file(content=None):
Create srt file in filesystem.
"""
content = content or SRT_content
srt_file = tempfile.NamedTemporaryFile(suffix=".srt")
srt_file.content_type = 'application/x-subrip; charset=utf-8'
srt_file.write(content)
srt_file.write(content.encode('utf-8'))
srt_file.seek(0)
return srt_file
@@ -258,7 +259,7 @@ class TestTranscriptAvailableTranslationsDispatch(TestVideo):
self.assertEqual(json.loads(response.body), ['en'])
def test_available_translation_non_en(self):
_upload_file(self.srt_file, self.item_descriptor.location, os.path.split(self.srt_file.name)[1])
_upload_file(_create_srt_file(), self.item_descriptor.location, os.path.split(self.srt_file.name)[1])
request = Request.blank('/available_translations')
response = self.item.transcript(request=request, dispatch='available_translations')
@@ -985,7 +986,7 @@ class TestStudioTranscriptTranslationPostDispatch(TestVideo):
"edx_video_id": "",
"language_code": "ar",
"new_language_code": "uk",
"file": ("filename.srt", SRT_content.decode("utf8").encode("cp1251"))
"file": ("filename.srt", SRT_content.encode("cp1251"))
}
request = Request.blank("/translation", POST=post_data)

View File

@@ -1321,10 +1321,10 @@ class UserProfileTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTestCase)
self.assertRegexpMatches(html, r'data-num-pages="1"')
self.assertRegexpMatches(html, r'<span class="discussion-count">1</span> discussion started')
self.assertRegexpMatches(html, r'<span class="discussion-count">2</span> comments')
self.assertRegexpMatches(html, ur'&#39;id&#39;: &#39;{}&#39;'.format(self.TEST_THREAD_ID))
self.assertRegexpMatches(html, ur'&#39;title&#39;: &#39;{}&#39;'.format(self.TEST_THREAD_TEXT))
self.assertRegexpMatches(html, ur'&#39;body&#39;: &#39;{}&#39;'.format(self.TEST_THREAD_TEXT))
self.assertRegexpMatches(html, ur'&#39;username&#39;: u&#39;{}&#39;'.format(self.student.username))
self.assertRegexpMatches(html, u'&#39;id&#39;: &#39;{}&#39;'.format(self.TEST_THREAD_ID))
self.assertRegexpMatches(html, u'&#39;title&#39;: &#39;{}&#39;'.format(self.TEST_THREAD_TEXT))
self.assertRegexpMatches(html, u'&#39;body&#39;: &#39;{}&#39;'.format(self.TEST_THREAD_TEXT))
self.assertRegexpMatches(html, u'&#39;username&#39;: u&#39;{}&#39;'.format(self.student.username))
def check_ajax(self, mock_request, **params):
response = self.get_response(mock_request, params, HTTP_X_REQUESTED_WITH="XMLHttpRequest")