INCR-237 Run python modernize on openedx/tests (#20494)

This commit is contained in:
aliciaerwin
2019-05-24 14:46:18 -05:00
committed by Jeremy Bowman
parent 99aa4bfd88
commit ddeb7c4204
9 changed files with 46 additions and 25 deletions

View File

@@ -2,16 +2,18 @@
Test signal handlers for completion.
"""
from __future__ import absolute_import
from datetime import datetime
import ddt
import six
from completion import handlers
from completion.models import BlockCompletion
from completion.test_utils import CompletionSetUpMixin
import ddt
from django.test import TestCase
from mock import patch
from pytz import utc
import six
from xblock.completable import XBlockCompletionMode
from xblock.core import XBlock

View File

@@ -4,11 +4,13 @@ Test models, managers, and validators.
from __future__ import absolute_import, division, unicode_literals
import six
from completion import models, waffle
from completion.test_utils import CompletionWaffleTestMixin, submit_completions_for_testing
from django.core.exceptions import ValidationError
from django.test import TestCase
from opaque_keys.edx.keys import CourseKey, UsageKey
from six.moves import range, zip
from openedx.core.djangolib.testing.utils import skip_unless_lms
from student.tests.factories import CourseEnrollmentFactory, UserFactory
@@ -161,7 +163,7 @@ class SubmitBatchCompletionTestCase(CompletionWaffleTestMixin, TestCase):
self.block_key = UsageKey.from_string('block-v1:edx+test+run+type@video+block@doggos')
self.course_key_obj = CourseKey.from_string('course-v1:edx+test+run')
self.user = UserFactory()
CourseEnrollmentFactory.create(user=self.user, course_id=unicode(self.course_key_obj))
CourseEnrollmentFactory.create(user=self.user, course_id=six.text_type(self.course_key_obj))
def test_submit_batch_completion(self):
blocks = [(self.block_key, 1.0)]
@@ -204,7 +206,7 @@ class BatchCompletionMethodTests(CompletionWaffleTestMixin, TestCase):
self.other_user = UserFactory.create()
self.course_key = CourseKey.from_string("edX/MOOC101/2049_T2")
self.other_course_key = CourseKey.from_string("course-v1:ReedX+Hum110+1904")
self.block_keys = [UsageKey.from_string("i4x://edX/MOOC101/video/{}".format(number)) for number in xrange(5)]
self.block_keys = [UsageKey.from_string("i4x://edX/MOOC101/video/{}".format(number)) for number in range(5)]
submit_completions_for_testing(self.user, self.course_key, self.block_keys[:3])
submit_completions_for_testing(self.other_user, self.course_key, self.block_keys[2:])
@@ -213,7 +215,7 @@ class BatchCompletionMethodTests(CompletionWaffleTestMixin, TestCase):
def test_get_course_completions_missing_runs(self):
actual_completions = models.BlockCompletion.get_course_completions(self.user, self.course_key)
expected_block_keys = [key.replace(course_key=self.course_key) for key in self.block_keys[:3]]
expected_completions = dict(zip(expected_block_keys, [1.0, 0.8, 0.6]))
expected_completions = dict(list(zip(expected_block_keys, [1.0, 0.8, 0.6])))
self.assertEqual(expected_completions, actual_completions)
def test_get_course_completions_empty_result_set(self):

View File

@@ -1,11 +1,14 @@
"""
Tests of completion xblock runtime services
"""
from __future__ import absolute_import
import ddt
from completion.models import BlockCompletion
from completion.services import CompletionService
from completion.test_utils import CompletionWaffleTestMixin
import ddt
from opaque_keys.edx.keys import CourseKey
from six.moves import range
from openedx.core.djangolib.testing.utils import skip_unless_lms
from student.tests.factories import UserFactory

View File

@@ -2,16 +2,18 @@
"""
Test models, managers, and validators.
"""
from __future__ import absolute_import
import ddt
from completion import waffle
from completion.test_utils import CompletionWaffleTestMixin
import ddt
from django.urls import reverse
from rest_framework.test import APIClient
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from openedx.core.djangolib.testing.utils import skip_unless_lms
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from openedx.core.djangolib.testing.utils import skip_unless_lms
@ddt.ddt

View File

@@ -1,12 +1,15 @@
"""
Test scenarios for the crowdsource hinter xblock.
"""
from __future__ import absolute_import
import json
import unittest
from django.conf import settings
from django.urls import reverse
from six import text_type
from six.moves import range
from lms.djangoapps.courseware.tests.factories import GlobalStaffFactory
from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase

View File

@@ -4,6 +4,8 @@ Tests for the DoneXBlock.
This is nice as a simple example of the edX XBlock test framework.
'''
from __future__ import absolute_import
from openedx.tests.xblock_integration.xblock_testcase import XBlockTestCase

View File

@@ -7,7 +7,8 @@ run v1 tests only.
That be the dragon here.
"""
from __future__ import print_function
from __future__ import absolute_import, print_function
import pkg_resources

View File

@@ -3,19 +3,23 @@ This test file will run through some XBlock test scenarios regarding the
recommender system
"""
from __future__ import absolute_import
import itertools
import json
import StringIO
import unittest
from copy import deepcopy
import six
from ddt import data, ddt
from django.conf import settings
from django.urls import reverse
from six import text_type
from six.moves import range
from ddt import data, ddt
from lms.djangoapps.courseware.tests.factories import GlobalStaffFactory
from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase
from six import text_type
from openedx.core.lib.url_utils import quote_slashes
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
@@ -205,7 +209,7 @@ class TestRecommenderCreateFromEmpty(TestRecommender):
"""
self.enroll_student(self.STUDENTS[0]['email'], self.STUDENTS[0]['password'])
# Check whether adding new resource is successful
for resource_id, resource in self.test_recommendations.iteritems():
for resource_id, resource in six.iteritems(self.test_recommendations):
for xblock_name in self.XBLOCK_NAMES:
result = self.call_event('add_resource', resource, xblock_name)
@@ -237,7 +241,7 @@ class TestRecommenderResourceBase(TestRecommender):
self.logout()
self.enroll_staff(self.staff_user)
# Add resources, assume correct here, tested in test_add_resource
for resource, xblock_name in itertools.product(self.test_recommendations.values(), self.XBLOCK_NAMES):
for resource, xblock_name in itertools.product(list(self.test_recommendations.values()), self.XBLOCK_NAMES):
self.call_event('add_resource', resource, xblock_name)
def generate_edit_resource(self, resource_id):
@@ -247,7 +251,7 @@ class TestRecommenderResourceBase(TestRecommender):
"""
resource = {"id": resource_id}
edited_recommendations = {
key: value + "edited" for key, value in self.test_recommendations[self.resource_id].iteritems()
key: value + "edited" for key, value in six.iteritems(self.test_recommendations[self.resource_id])
}
resource.update(edited_recommendations)
return resource

View File

@@ -34,10 +34,9 @@ Our next steps would be to:
* Move more blocks out of the platform, and more tests into the
blocks themselves.
"""
from __future__ import print_function
from __future__ import absolute_import, print_function
import collections
import HTMLParser
import json
import sys
import unittest
@@ -45,9 +44,12 @@ from datetime import datetime, timedelta
import mock
import pytz
import six
import six.moves.html_parser
from bs4 import BeautifulSoup
from django.conf import settings
from django.urls import reverse
from six.moves import range
from xblock.plugin import Plugin
import lms.djangoapps.lms_xblock.runtime
@@ -273,10 +275,10 @@ class XBlockScenarioTestCaseMixin(object):
)
cls.xblocks[xblock_config['urlname']] = xblock
scenario_url = unicode(reverse(
scenario_url = six.text_type(reverse(
'courseware_section',
kwargs={
'course_id': unicode(cls.course.id),
'course_id': six.text_type(cls.course.id),
'chapter': "ch_" + chapter_config['urlname'],
'section': "sec_" + chapter_config['urlname']
}
@@ -372,8 +374,8 @@ class XBlockTestCase(XBlockStudentTestCaseMixin,
Get url for the specified xblock handler
"""
return reverse('xblock_handler', kwargs={
'course_id': unicode(self.course.id),
'usage_id': unicode(
'course_id': six.text_type(self.course.id),
'usage_id': six.text_type(
self.course.id.make_usage_key('done', xblock_name)
),
'handler': handler,
@@ -413,9 +415,9 @@ class XBlockTestCase(XBlockStudentTestCaseMixin,
if block["urlname"] == xblock_name:
xblock_type = block["blocktype"]
key = unicode(self.course.id.make_usage_key(xblock_type, xblock_name))
key = six.text_type(self.course.id.make_usage_key(xblock_type, xblock_name))
return reverse('xblock_handler', kwargs={
'course_id': unicode(self.course.id),
'course_id': six.text_type(self.course.id),
'usage_id': key,
'handler': handler,
'suffix': ''
@@ -449,7 +451,7 @@ class XBlockTestCase(XBlockStudentTestCaseMixin,
usage_id = self.xblocks[urlname].scope_ids.usage_id
# First, we get out our <div>
soup_html = BeautifulSoup(content)
xblock_html = unicode(soup_html.find(id="seq_contents_0"))
xblock_html = six.text_type(soup_html.find(id="seq_contents_0"))
# Now, we get out the text of the <div>
try:
escaped_html = xblock_html.split('<')[1].split('>')[1]
@@ -465,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 = HTMLParser.HTMLParser().unescape(escaped_html).strip()
decoded_html = six.moves.html_parser.HTMLParser().unescape(escaped_html).strip()
return decoded_html