diff --git a/lms/djangoapps/courseware/tests/factories.py b/lms/djangoapps/courseware/tests/factories.py
index 9e116b7655..bb81bc1d9a 100644
--- a/lms/djangoapps/courseware/tests/factories.py
+++ b/lms/djangoapps/courseware/tests/factories.py
@@ -31,7 +31,7 @@ from common.djangoapps.student.tests.factories import UserProfileFactory as Stud
# TODO fix this (course_id and location are invalid names as constants, and course_id should really be COURSE_KEY)
# pylint: disable=invalid-name
course_id = CourseKey.from_string('edX/test_course/test')
-location = partial(course_id.make_usage_key, u'problem')
+location = partial(course_id.make_usage_key, 'problem')
class UserProfileFactory(StudentUserProfileFactory):
@@ -126,7 +126,7 @@ class GlobalStaffFactory(UserFactory):
class StudentModuleFactory(DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
- class Meta(object):
+ class Meta:
model = StudentModule
module_type = "problem"
@@ -139,7 +139,7 @@ class StudentModuleFactory(DjangoModelFactory): # lint-amnesty, pylint: disable
class UserStateSummaryFactory(DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
- class Meta(object):
+ class Meta:
model = XModuleUserStateSummaryField
field_name = 'existing_field'
@@ -148,7 +148,7 @@ class UserStateSummaryFactory(DjangoModelFactory): # lint-amnesty, pylint: disa
class StudentPrefsFactory(DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
- class Meta(object):
+ class Meta:
model = XModuleStudentPrefsField
field_name = 'existing_field'
@@ -158,7 +158,7 @@ class StudentPrefsFactory(DjangoModelFactory): # lint-amnesty, pylint: disable=
class StudentInfoFactory(DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
- class Meta(object):
+ class Meta:
model = XModuleStudentInfoField
field_name = 'existing_field'
@@ -171,6 +171,6 @@ class RequestFactoryNoCsrf(RequestFactory):
RequestFactory, which disables csrf checks.
"""
def request(self, **kwargs):
- request = super(RequestFactoryNoCsrf, self).request(**kwargs) # lint-amnesty, pylint: disable=super-with-arguments
+ request = super().request(**kwargs)
setattr(request, '_dont_enforce_csrf_checks', True) # pylint: disable=literal-used-as-attribute
return request
diff --git a/lms/djangoapps/courseware/tests/helpers.py b/lms/djangoapps/courseware/tests/helpers.py
index b634a59c0f..7bb65476f7 100644
--- a/lms/djangoapps/courseware/tests/helpers.py
+++ b/lms/djangoapps/courseware/tests/helpers.py
@@ -8,15 +8,12 @@ import json
from collections import OrderedDict
from datetime import timedelta
-import six
from django.contrib import messages
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.test import TestCase
from django.test.client import Client, RequestFactory
from django.urls import reverse
from django.utils.timezone import now
-from six import text_type
-from six.moves import range
from xblock.field_data import DictFieldData
from common.djangoapps.edxmako.shortcuts import render_to_string
@@ -94,7 +91,7 @@ class BaseTestXmodule(ModuleStoreTestCase):
self.item_descriptor.xmodule_runtime = self.new_module_runtime()
- self.item_url = six.text_type(self.item_descriptor.location)
+ self.item_url = str(self.item_descriptor.location)
def setup_course(self): # lint-amnesty, pylint: disable=missing-function-docstring
self.course = CourseFactory.create(data=self.COURSE_DATA)
@@ -132,7 +129,7 @@ class BaseTestXmodule(ModuleStoreTestCase):
assert all(self.login_statuses)
def setUp(self):
- super(BaseTestXmodule, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
+ super().setUp()
self.setup_course()
self.initialize_module(metadata=self.METADATA, data=self.DATA)
@@ -140,7 +137,7 @@ class BaseTestXmodule(ModuleStoreTestCase):
"""Return item url with dispatch."""
return reverse(
'xblock_handler',
- args=(six.text_type(self.course.id), quote_slashes(self.item_url), 'xmodule_handler', dispatch)
+ args=(str(self.course.id), quote_slashes(self.item_url), 'xmodule_handler', dispatch)
)
@@ -150,7 +147,7 @@ class XModuleRenderingTestBase(BaseTestXmodule): # lint-amnesty, pylint: disabl
"""
Create a runtime that actually does html rendering
"""
- runtime = super(XModuleRenderingTestBase, self).new_module_runtime() # lint-amnesty, pylint: disable=super-with-arguments
+ runtime = super().new_module_runtime()
runtime.render_template = render_to_string
return runtime
@@ -185,7 +182,7 @@ class LoginEnrollmentTestCase(TestCase):
"""
make_request = getattr(self.client, method.lower())
response = make_request(url, **kwargs)
- assert response.status_code == status_code, u'{method} request to {url} returned status code {actual}, expected status code {expected}'.format(method=method, url=url, actual=response.status_code, expected=status_code) # pylint: disable=line-too-long
+ assert response.status_code == status_code, f'{method} request to {url} returned status code {response.status_code}, expected status code {status_code}' # pylint: disable=line-too-long
return response
def assert_account_activated(self, url, method="GET", **kwargs): # lint-amnesty, pylint: disable=missing-function-docstring
@@ -257,7 +254,7 @@ class LoginEnrollmentTestCase(TestCase):
"""
resp = self.client.post(reverse('change_enrollment'), {
'enrollment_action': 'enroll',
- 'course_id': text_type(course.id),
+ 'course_id': str(course.id),
'check_access': True,
})
result = resp.status_code == 200
@@ -273,7 +270,7 @@ class LoginEnrollmentTestCase(TestCase):
url = reverse('change_enrollment')
request_data = {
'enrollment_action': 'unenroll',
- 'course_id': text_type(course.id),
+ 'course_id': str(course.id),
}
self.assert_request_status_code(200, url, method="POST", data=request_data)
@@ -387,7 +384,7 @@ def masquerade_as_group_member(user, course, partition_id, group_id):
user,
data={"role": "student", "user_partition_id": partition_id, "group_id": group_id}
)
- response = MasqueradeView.as_view()(request, six.text_type(course.id))
+ response = MasqueradeView.as_view()(request, str(course.id))
setup_masquerade(request, course.id, True)
return response.status_code
@@ -419,7 +416,7 @@ def get_expiration_banner_text(user, course, language='en'): # lint-amnesty, py
if upgrade_deadline:
formatted_upgrade_deadline = strftime_localized_html(upgrade_deadline, 'SHORT_DATE')
- bannerText = u'Audit Access Expires {expiration_date}
\
+ bannerText = 'Audit Access Expires {expiration_date}
\
You lose all access to this course, including your progress, on {expiration_date}.\
Upgrade by {upgrade_deadline} to get unlimited access to the course as long as it exists\
on the site. Upgrade now to retain access past\
@@ -429,7 +426,7 @@ def get_expiration_banner_text(user, course, language='en'): # lint-amnesty, py
upgrade_deadline=formatted_upgrade_deadline
)
else:
- bannerText = u'Audit Access Expires {expiration_date}
\
+ bannerText = 'Audit Access Expires {expiration_date}
\
You lose all access to this course, including your progress, on {expiration_date}.\
'.format(
expiration_date=formatted_expiration_date
diff --git a/lms/djangoapps/courseware/tests/test_about.py b/lms/djangoapps/courseware/tests/test_about.py
index 36f539f9d1..6beca7ec82 100644
--- a/lms/djangoapps/courseware/tests/test_about.py
+++ b/lms/djangoapps/courseware/tests/test_about.py
@@ -5,17 +5,15 @@ Test the about xblock
import datetime
+from unittest import mock
+from unittest.mock import patch
import ddt
-import mock
import pytz
-import six
from ccx_keys.locator import CCXLocator
from django.conf import settings
from django.test.utils import override_settings
from django.urls import reverse
from milestones.tests.utils import MilestonesTestCaseMixin
-from mock import patch
-from six import text_type
from waffle.testutils import override_switch
from common.djangoapps.course_modes.models import CourseMode
@@ -59,7 +57,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
@classmethod
def setUpClass(cls):
- super(AboutTestCase, cls).setUpClass()
+ super().setUpClass()
cls.course = CourseFactory.create()
cls.course_without_about = CourseFactory.create(catalog_visibility=CATALOG_VISIBILITY_NONE)
cls.course_with_about = CourseFactory.create(catalog_visibility=CATALOG_VISIBILITY_ABOUT)
@@ -78,7 +76,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
)
def setUp(self):
- super(AboutTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
+ super().setUp()
self.course_mode = CourseMode(
course_id=self.purchase_course.id,
@@ -92,7 +90,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
"""
This test asserts that a non-logged in user can visit the course about page
"""
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
self.assertContains(resp, "OOGIE BLOOGIE")
@@ -104,7 +102,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
This test asserts that a logged-in user can visit the course about page
"""
self.setup_user()
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
self.assertContains(resp, "OOGIE BLOOGIE")
@@ -115,7 +113,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
"""
self.setup_user()
self.enroll(self.course, True)
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
self.assertContains(resp, "You are enrolled in this course")
self.assertContains(resp, "View Course")
@@ -125,25 +123,25 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
"""
Verify that the About Page honors the permission settings in the course module
"""
- url = reverse('about_course', args=[text_type(self.course_with_about.id)])
+ url = reverse('about_course', args=[str(self.course_with_about.id)])
resp = self.client.get(url)
self.assertContains(resp, "WITH ABOUT")
- url = reverse('about_course', args=[text_type(self.course_without_about.id)])
+ url = reverse('about_course', args=[str(self.course_without_about.id)])
resp = self.client.get(url)
assert resp.status_code == 404
@patch.dict(settings.FEATURES, {'ENABLE_MKTG_SITE': True})
def test_logged_in_marketing(self):
self.setup_user()
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
# should be redirected
assert resp.status_code == 302
# follow this time, and check we're redirected to the course home page
resp = self.client.get(url, follow=True)
target_url = resp.redirect_chain[-1][0]
- course_home_url = reverse('openedx.course_experience.course_home', args=[text_type(self.course.id)])
+ course_home_url = reverse('openedx.course_experience.course_home', args=[str(self.course.id)])
assert target_url.endswith(course_home_url)
@patch.dict(settings.FEATURES, {'ENABLE_COURSE_HOME_REDIRECT': False})
@@ -154,7 +152,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
ENABLE_COURSE_HOME_REDIRECT is set to False
"""
self.setup_user()
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
# should not be redirected
self.assertContains(resp, "OOGIE BLOOGIE")
@@ -167,7 +165,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
ENABLE_MKTG_SITE is set to False
"""
self.setup_user()
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
# should not be redirected
self.assertContains(resp, "OOGIE BLOOGIE")
@@ -175,14 +173,14 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
@patch.dict(settings.FEATURES, {'ENABLE_PREREQUISITE_COURSES': True})
def test_pre_requisite_course(self):
pre_requisite_course = CourseFactory.create(org='edX', course='900', display_name='pre requisite course')
- course = CourseFactory.create(pre_requisite_courses=[text_type(pre_requisite_course.id)])
+ course = CourseFactory.create(pre_requisite_courses=[str(pre_requisite_course.id)])
self.setup_user()
- url = reverse('about_course', args=[text_type(course.id)])
+ url = reverse('about_course', args=[str(course.id)])
resp = self.client.get(url)
assert resp.status_code == 200
pre_requisite_courses = get_prerequisite_courses_display(course)
- pre_requisite_course_about_url = reverse('about_course', args=[text_type(pre_requisite_courses[0]['key'])])
- assert u'{}'.format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']) in resp.content.decode(resp.charset).strip('\n') # pylint: disable=line-too-long
+ pre_requisite_course_about_url = reverse('about_course', args=[str(pre_requisite_courses[0]['key'])])
+ assert '{}'.format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']) in resp.content.decode(resp.charset).strip('\n') # pylint: disable=line-too-long
@patch.dict(settings.FEATURES, {'ENABLE_PREREQUISITE_COURSES': True})
def test_about_page_unfulfilled_prereqs(self):
@@ -192,7 +190,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
display_name='pre requisite course',
)
- pre_requisite_courses = [text_type(pre_requisite_course.id)]
+ pre_requisite_courses = [str(pre_requisite_course.id)]
# for this failure to occur, the enrollment window needs to be in the past
course = CourseFactory.create(
@@ -211,14 +209,14 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
self.enroll(self.course, True)
self.enroll(pre_requisite_course, True)
- url = reverse('about_course', args=[text_type(course.id)])
+ url = reverse('about_course', args=[str(course.id)])
resp = self.client.get(url)
assert resp.status_code == 200
pre_requisite_courses = get_prerequisite_courses_display(course)
- pre_requisite_course_about_url = reverse('about_course', args=[text_type(pre_requisite_courses[0]['key'])])
- assert u'{}'.format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']) in resp.content.decode(resp.charset).strip('\n') # pylint: disable=line-too-long
+ pre_requisite_course_about_url = reverse('about_course', args=[str(pre_requisite_courses[0]['key'])])
+ assert '{}'.format(pre_requisite_course_about_url, pre_requisite_courses[0]['display']) in resp.content.decode(resp.charset).strip('\n') # pylint: disable=line-too-long
- url = reverse('about_course', args=[six.text_type(pre_requisite_course.id)])
+ url = reverse('about_course', args=[str(pre_requisite_course.id)])
resp = self.client.get(url)
assert resp.status_code == 200
@@ -235,7 +233,7 @@ class AboutTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase, EventTra
"""
with mock.patch('xmodule.course_module.CourseBlock.course_visibility', course_visibility):
with override_waffle_flag(COURSE_ENABLE_UNENROLLED_ACCESS_FLAG, active=True):
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
if course_visibility == COURSE_VISIBILITY_PUBLIC or course_visibility == COURSE_VISIBILITY_PUBLIC_OUTLINE: # lint-amnesty, pylint: disable=consider-using-in
self.assertContains(resp, "View Course")
@@ -253,7 +251,7 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Set up the tests
"""
- super(AboutTestCaseXML, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
+ super().setUp()
# The following test course (which lives at common/test/data/2014)
# is closed; we're testing that an about page still appears when
@@ -277,13 +275,13 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
@patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
def test_logged_in_xml(self):
self.setup_user()
- url = reverse('about_course', args=[text_type(self.xml_course_id)])
+ url = reverse('about_course', args=[str(self.xml_course_id)])
resp = self.client.get(url)
self.assertContains(resp, self.xml_data)
@patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
def test_anonymous_user_xml(self):
- url = reverse('about_course', args=[text_type(self.xml_course_id)])
+ url = reverse('about_course', args=[str(self.xml_course_id)])
resp = self.client.get(url)
self.assertContains(resp, self.xml_data)
@@ -294,7 +292,7 @@ class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, SharedModuleSt
"""
@classmethod
def setUpClass(cls):
- super(AboutWithCappedEnrollmentsTestCase, cls).setUpClass()
+ super().setUpClass()
cls.course = CourseFactory.create(metadata={"max_student_enrollments_allowed": 1})
cls.about = ItemFactory.create(
category="about", parent_location=cls.course.location,
@@ -306,7 +304,7 @@ class AboutWithCappedEnrollmentsTestCase(LoginEnrollmentTestCase, SharedModuleSt
This test will make sure that enrollment caps are enforced
"""
self.setup_user()
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
self.assertContains(resp, '')
@@ -339,7 +337,7 @@ class AboutWithInvitationOnly(SharedModuleStoreTestCase):
"""
@classmethod
def setUpClass(cls):
- super(AboutWithInvitationOnly, cls).setUpClass()
+ super().setUpClass()
cls.course = CourseFactory.create(metadata={"invitation_only": True})
cls.about = ItemFactory.create(
category="about", parent_location=cls.course.location,
@@ -351,7 +349,7 @@ class AboutWithInvitationOnly(SharedModuleStoreTestCase):
Test for user not logged in, invitation only course.
"""
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
self.assertContains(resp, "Enrollment in this course is by invitation only")
@@ -368,9 +366,9 @@ class AboutWithInvitationOnly(SharedModuleStoreTestCase):
CourseEnrollmentAllowedFactory(email=user.email, course_id=self.course.id)
self.client.login(username=user.username, password='test')
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
- self.assertContains(resp, u"Enroll Now")
+ self.assertContains(resp, "Enroll Now")
# Check that registration button is present
self.assertContains(resp, REG_STR)
@@ -382,7 +380,7 @@ class AboutWithClosedEnrollment(ModuleStoreTestCase):
set but it is currently outside of that period.
"""
def setUp(self):
- super(AboutWithClosedEnrollment, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
+ super().setUp()
self.course = CourseFactory.create(metadata={"invitation_only": False})
@@ -401,7 +399,7 @@ class AboutWithClosedEnrollment(ModuleStoreTestCase):
)
def test_closed_enrollmement(self):
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
self.assertContains(resp, "Enrollment is Closed")
@@ -409,7 +407,7 @@ class AboutWithClosedEnrollment(ModuleStoreTestCase):
self.assertNotContains(resp, REG_STR)
def test_course_price_is_not_visble_in_sidebar(self):
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
# course price is not visible ihe course_about page when the course
# mode is not set to honor
@@ -422,7 +420,7 @@ class AboutSidebarHTMLTestCase(SharedModuleStoreTestCase):
This test case will check the About page for the content in the HTML sidebar.
"""
def setUp(self):
- super(AboutSidebarHTMLTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
+ super().setUp()
self.course = CourseFactory.create()
@ddt.data(
@@ -449,7 +447,7 @@ class AboutSidebarHTMLTestCase(SharedModuleStoreTestCase):
display_name=itemfactory_display_name,
data=itemfactory_data,
)
- url = reverse('about_course', args=[text_type(self.course.id)])
+ url = reverse('about_course', args=[str(self.course.id)])
resp = self.client.get(url)
if waffle_switch_value and itemfactory_display_name and itemfactory_data:
self.assertContains(resp, '
ViewCheckerPassed: {}
\n{}".format( - six.text_type(self.scope_ids.usage_id), + content="ViewCheckerPassed: {}
\n{}".format( + str(self.scope_ids.usage_id), "\n".join(fragment.content for fragment in fragments), ) ) @@ -2307,7 +2301,7 @@ class TestIndexView(ModuleStoreTestCase): student=user, course_id=course.id, module_state_key=item.scope_ids.usage_id, - state=json.dumps({'state': six.text_type(item.scope_ids.usage_id)}) + state=json.dumps({'state': str(item.scope_ids.usage_id)}) ) CourseOverview.load_from_module_store(course.id) @@ -2318,7 +2312,7 @@ class TestIndexView(ModuleStoreTestCase): reverse( 'courseware_section', kwargs={ - 'course_id': six.text_type(course.id), + 'course_id': str(course.id), 'chapter': chapter.url_name, 'section': section.url_name, } @@ -2346,7 +2340,7 @@ class TestIndexView(ModuleStoreTestCase): reverse( 'courseware_section', kwargs={ - 'course_id': six.text_type(course.id), + 'course_id': str(course.id), 'chapter': chapter.url_name, 'section': section.url_name, } @@ -2569,7 +2563,7 @@ class TestIndexViewCompleteOnView(ModuleStoreTestCase, CompletionWaffleTestMixin self.section_1_url = reverse( 'courseware_section', kwargs={ - 'course_id': six.text_type(self.course.id), + 'course_id': str(self.course.id), 'chapter': self.chapter.url_name, 'section': self.section_1.url_name, } @@ -2578,7 +2572,7 @@ class TestIndexViewCompleteOnView(ModuleStoreTestCase, CompletionWaffleTestMixin self.section_2_url = reverse( 'courseware_section', kwargs={ - 'course_id': six.text_type(self.course.id), + 'course_id': str(self.course.id), 'chapter': self.chapter.url_name, 'section': self.section_2.url_name, } @@ -2619,8 +2613,8 @@ class TestIndexViewCompleteOnView(ModuleStoreTestCase, CompletionWaffleTestMixin request.user = self.user response = handle_xblock_callback( request, - six.text_type(self.course.id), - quote_slashes(six.text_type(self.html_1_1.scope_ids.usage_id)), + str(self.course.id), + quote_slashes(str(self.html_1_1.scope_ids.usage_id)), 'publish_completion', ) assert json.loads(response.content.decode('utf-8')) == {'result': 'ok'} @@ -2637,8 +2631,8 @@ class TestIndexViewCompleteOnView(ModuleStoreTestCase, CompletionWaffleTestMixin request.user = self.user response = handle_xblock_callback( request, - six.text_type(self.course.id), - quote_slashes(six.text_type(self.html_1_2.scope_ids.usage_id)), + str(self.course.id), + quote_slashes(str(self.html_1_2.scope_ids.usage_id)), 'publish_completion', ) assert json.loads(response.content.decode('utf-8')) == {'result': 'ok'} @@ -2661,7 +2655,7 @@ class TestIndexViewWithVerticalPositions(ModuleStoreTestCase): """ Set up initial test data """ - super(TestIndexViewWithVerticalPositions, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = UserFactory() @@ -2687,7 +2681,7 @@ class TestIndexViewWithVerticalPositions(ModuleStoreTestCase): reverse( 'courseware_position', kwargs={ - 'course_id': six.text_type(self.course.id), + 'course_id': str(self.course.id), 'chapter': self.chapter.url_name, 'section': self.section.url_name, 'position': input_position, @@ -2699,7 +2693,7 @@ class TestIndexViewWithVerticalPositions(ModuleStoreTestCase): """ Asserts that the expected position and the position in the response are the same """ - self.assertContains(response, 'data-position="{}"'.format(expected_position)) + self.assertContains(response, f'data-position="{expected_position}"') @ddt.data(("-1", 1), ("0", 1), ("-0", 1), ("2", 2), ("5", 1)) @ddt.unpack @@ -2724,7 +2718,7 @@ class TestIndexViewWithGating(ModuleStoreTestCase, MilestonesTestCaseMixin): """ Set up the initial test data """ - super(TestIndexViewWithGating, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = UserFactory() self.course = CourseFactory.create() @@ -2756,7 +2750,7 @@ class TestIndexViewWithGating(ModuleStoreTestCase, MilestonesTestCaseMixin): reverse( 'courseware_section', kwargs={ - 'course_id': six.text_type(self.course.id), + 'course_id': str(self.course.id), 'chapter': self.chapter.url_name, 'section': self.gated_seq.url_name, } @@ -2775,7 +2769,7 @@ class TestIndexViewWithCourseDurationLimits(ModuleStoreTestCase): """ Set up the initial test data. """ - super(TestIndexViewWithCourseDurationLimits, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = UserFactory() self.course = CourseFactory.create(start=datetime.now() - timedelta(weeks=1)) @@ -2799,7 +2793,7 @@ class TestIndexViewWithCourseDurationLimits(ModuleStoreTestCase): reverse( 'courseware_section', kwargs={ - 'course_id': six.text_type(self.course.id), + 'course_id': str(self.course.id), 'chapter': self.chapter.url_name, 'section': self.sequential.url_name, } @@ -2825,7 +2819,7 @@ class TestIndexViewWithCourseDurationLimits(ModuleStoreTestCase): reverse( 'courseware_section', kwargs={ - 'course_id': six.text_type(self.course.id), + 'course_id': str(self.course.id), 'chapter': self.chapter.url_name, 'section': self.sequential.url_name, } @@ -2843,7 +2837,7 @@ class TestRenderXBlock(RenderXBlockTestMixin, ModuleStoreTestCase, CompletionWaf """ def setUp(self): reload_django_url_config() - super(TestRenderXBlock, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() def test_render_xblock_with_invalid_usage_key(self): """ @@ -2895,8 +2889,8 @@ class TestRenderXBlock(RenderXBlockTestMixin, ModuleStoreTestCase, CompletionWaf request.user = self.user response = handle_xblock_callback( request, - six.text_type(self.course.id), - quote_slashes(six.text_type(self.html_block.location)), + str(self.course.id), + quote_slashes(str(self.html_block.location)), 'publish_completion', ) assert response.status_code == 200 @@ -2963,10 +2957,10 @@ class TestRenderXBlockSelfPaced(TestRenderXBlock): # lint-amnesty, pylint: disa count assertions in the tests defined by RenderXBlockMixin. """ def setUp(self): # lint-amnesty, pylint: disable=useless-super-delegation - super(TestRenderXBlockSelfPaced, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() def course_options(self): - options = super(TestRenderXBlockSelfPaced, self).course_options() # lint-amnesty, pylint: disable=super-with-arguments + options = super().course_options() options['self_paced'] = True return options @@ -2983,7 +2977,7 @@ class TestIndexViewCrawlerStudentStateWrites(SharedModuleStoreTestCase): """Set up the simplest course possible.""" # setUpClassAndTestData() already calls setUpClass on SharedModuleStoreTestCase # pylint: disable=super-method-not-called - with super(TestIndexViewCrawlerStudentStateWrites, cls).setUpClassAndTestData(): + with super().setUpClassAndTestData(): cls.course = CourseFactory.create() with cls.store.bulk_operations(cls.course.id): cls.chapter = ItemFactory.create(category='chapter', parent_location=cls.course.location) @@ -2998,7 +2992,7 @@ class TestIndexViewCrawlerStudentStateWrites(SharedModuleStoreTestCase): def setUp(self): """Do the client login.""" - super(TestIndexViewCrawlerStudentStateWrites, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.client.login(username=self.user.username, password=TEST_PASSWORD) def test_write_by_default(self): @@ -3038,9 +3032,9 @@ class TestIndexViewCrawlerStudentStateWrites(SharedModuleStoreTestCase): url = reverse( 'courseware_section', kwargs={ - 'course_id': six.text_type(self.course.id), - 'chapter': six.text_type(self.chapter.location.block_id), - 'section': six.text_type(self.section.location.block_id), + 'course_id': str(self.course.id), + 'chapter': str(self.chapter.location.block_id), + 'section': str(self.section.location.block_id), } ) response = self.client.get(url, HTTP_USER_AGENT=user_agent) @@ -3054,7 +3048,7 @@ class EnterpriseConsentTestCase(EnterpriseTestConsentRequired, ModuleStoreTestCa Ensure that the Enterprise Data Consent redirects are in place only when consent is required. """ def setUp(self): - super(EnterpriseConsentTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.user = UserFactory.create() assert self.client.login(username=self.user.username, password='test') self.course = CourseFactory.create() @@ -3069,7 +3063,7 @@ class EnterpriseConsentTestCase(EnterpriseTestConsentRequired, ModuleStoreTestCa # ENT-924: Temporary solution to replace sensitive SSO usernames. mock_enterprise_customer_for_request.return_value = None - course_id = six.text_type(self.course.id) + course_id = str(self.course.id) for url in ( reverse("courseware", kwargs=dict(course_id=course_id)), reverse("progress", kwargs=dict(course_id=course_id)), @@ -3104,7 +3098,7 @@ class DatesTabTestCase(ModuleStoreTestCase): """ def setUp(self): - super(DatesTabTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() now = datetime.now(utc) self.course = CourseFactory.create(start=now + timedelta(days=-1), self_paced=True) @@ -3128,7 +3122,7 @@ class DatesTabTestCase(ModuleStoreTestCase): def _get_response(self, course): """ Returns the HTML for the dates page """ - return self.client.get(reverse('dates', args=[six.text_type(course.id)])) + return self.client.get(reverse('dates', args=[str(course.id)])) def test_tab_redirects_if_not_logged_in(self): self.client.logout() @@ -3201,7 +3195,7 @@ class DatesTabTestCase(ModuleStoreTestCase): } expected_calls = [ - call('course_id', text_type(self.course.id)), + call('course_id', str(self.course.id)), call('user_id', self.user.id), call('is_staff', self.user.is_staff), ] @@ -3409,7 +3403,7 @@ class ContentOptimizationTestCase(ModuleStoreTestCase): self.math_html_usage_keys = [] with self.store.default_store(ModuleStoreEnum.Type.split): - self.course = CourseFactory.create(display_name=u'teꜱᴛ course', run="Testing_course") + self.course = CourseFactory.create(display_name='teꜱᴛ course', run="Testing_course") with self.store.bulk_operations(self.course.id): chapter = ItemFactory.create( category='chapter', diff --git a/lms/djangoapps/courseware/tests/test_word_cloud.py b/lms/djangoapps/courseware/tests/test_word_cloud.py index 6eaa82cc32..e80c73332d 100644 --- a/lms/djangoapps/courseware/tests/test_word_cloud.py +++ b/lms/djangoapps/courseware/tests/test_word_cloud.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Word cloud integration tests using mongo modulestore.""" @@ -63,7 +62,7 @@ class TestWordCloud(BaseTestXmodule): # We should compare top_words for manually, # because they are unsorted. - keys_to_compare = set(content.keys()).difference(set(['top_words'])) + keys_to_compare = set(content.keys()).difference({'top_words'}) self.assertDictEqual( {k: content[k] for k in keys_to_compare}, {k: correct_jsons[username][k] for k in keys_to_compare}) @@ -90,12 +89,12 @@ class TestWordCloud(BaseTestXmodule): # correct initial data: correct_initial_data = { - u'status': u'success', - u'student_words': {}, - u'total_count': 0, - u'submitted': False, - u'top_words': {}, - u'display_student_percents': False + 'status': 'success', + 'student_words': {}, + 'total_count': 0, + 'submitted': False, + 'top_words': {}, + 'display_student_percents': False } for _, response_content in users_state.items(): @@ -113,10 +112,10 @@ class TestWordCloud(BaseTestXmodule): ] correct_words = [ - u"small", - u"big", - u"spaced", - u"few words", + "small", + "big", + "spaced", + "few words", ] users_state = self._post_words(input_words) @@ -127,15 +126,15 @@ class TestWordCloud(BaseTestXmodule): for index, user in enumerate(self.users): correct_state[user.username] = { - u'status': u'success', - u'submitted': True, - u'display_student_percents': True, - u'student_words': {word: 1 + index for word in correct_words}, - u'total_count': len(input_words) * (1 + index), - u'top_words': [ + 'status': 'success', + 'submitted': True, + 'display_student_percents': True, + 'student_words': {word: 1 + index for word in correct_words}, + 'total_count': len(input_words) * (1 + index), + 'top_words': [ { - u'text': word, u'percent': 100 / len(input_words), - u'size': (1 + index) + 'text': word, 'percent': 100 / len(input_words), + 'size': (1 + index) } for word in correct_words ] @@ -186,8 +185,8 @@ class TestWordCloud(BaseTestXmodule): self._check_response(users_state_before_fail, current_users_state) def test_unicode(self): - input_words = [u" this is unicode Юникод"] - correct_words = [u"this is unicode юникод"] + input_words = [" this is unicode Юникод"] + correct_words = ["this is unicode юникод"] users_state = self._post_words(input_words) diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py index 67e68e60c1..88ff4562b0 100644 --- a/lms/djangoapps/courseware/tests/tests.py +++ b/lms/djangoapps/courseware/tests/tests.py @@ -6,10 +6,9 @@ Test for LMS courseware app. from textwrap import dedent from unittest import TestCase -import mock +from unittest import mock from django.urls import reverse from opaque_keys.edx.keys import CourseKey -from six import text_type from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from lms.djangoapps.lms_xblock.field_data import LmsFieldData @@ -24,7 +23,7 @@ class ActivateLoginTest(LoginEnrollmentTestCase): Test logging in and logging out. """ def setUp(self): - super(ActivateLoginTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.setup_user() def test_activate_login(self): @@ -76,22 +75,22 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): if descriptor.location.category == 'about': self._assert_loads('about_course', - {'course_id': text_type(course_key)}, + {'course_id': str(course_key)}, descriptor) elif descriptor.location.category == 'static_tab': - kwargs = {'course_id': text_type(course_key), + kwargs = {'course_id': str(course_key), 'tab_slug': descriptor.location.name} self._assert_loads('static_tab', kwargs, descriptor) elif descriptor.location.category == 'course_info': - self._assert_loads('info', {'course_id': text_type(course_key)}, + self._assert_loads('info', {'course_id': str(course_key)}, descriptor) else: - kwargs = {'course_id': text_type(course_key), - 'location': text_type(descriptor.location)} + kwargs = {'course_id': str(course_key), + 'location': str(descriptor.location)} self._assert_loads('jump_to', kwargs, descriptor, expect_redirect=True, @@ -111,7 +110,7 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): response = self.client.get(url, follow=True) if response.status_code != 200: - self.fail(u'Status %d for page %s' % + self.fail('Status %d for page %s' % (response.status_code, descriptor.location)) if expect_redirect: @@ -129,7 +128,7 @@ class TestMongoCoursesLoad(ModuleStoreTestCase, PageLoaderTestCase): MODULESTORE = TEST_DATA_MIXED_MODULESTORE def setUp(self): - super(TestMongoCoursesLoad, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments + super().setUp() self.setup_user() self.toy_course_key = ToyCourseFactory.create().id