Pyupgrade in common/djangoapps/coursemodes.

This commit is contained in:
Awais Qureshi
2021-03-18 11:19:46 +05:00
parent 3b65406a0d
commit 356f169a47
27 changed files with 134 additions and 168 deletions

View File

@@ -29,7 +29,7 @@ class CourseModeSerializer(serializers.Serializer):
sku = serializers.CharField(required=False)
bulk_sku = serializers.CharField(required=False)
class Meta(object):
class Meta:
# For disambiguating within the drf-yasg swagger schema
ref_name = 'course_modes.CourseMode'

View File

@@ -66,7 +66,7 @@ class CourseModesViewTestBase(AuthAndScopesTestMixin):
cls.other_mode.delete()
def setUp(self):
super(CourseModesViewTestBase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
super().setUp()
# overwrite self.student to be a staff member, since only staff
# should be able to access the course_modes API endpoints.
# This is needed to make a handful of tests inherited from AuthAndScopesTestMixin pass.
@@ -89,7 +89,7 @@ class CourseModesViewTestBase(AuthAndScopesTestMixin):
jwt_token = self._create_jwt_token(self.student, auth_type, include_me_filter=True)
# include_me_filter=True means a JWT filter will require the username
# of the requesting user to be in the requested URL
url = self.get_url(self.student) + '?username={}'.format(self.student.username)
url = self.get_url(self.student) + f'?username={self.student.username}'
resp = self.get_response(AuthType.jwt, token=jwt_token, url=url)
assert status.HTTP_200_OK == resp.status_code
@@ -108,7 +108,7 @@ class TestCourseModesListViews(CourseModesViewTestBase, ModuleStoreTestCase, API
Required method to implement AuthAndScopesTestMixin.
"""
kwargs = {
'course_id': text_type(course_id or self.course_key)
'course_id': str(course_id or self.course_key)
}
return reverse(self.view_name, kwargs=kwargs)
@@ -130,7 +130,7 @@ class TestCourseModesListViews(CourseModesViewTestBase, ModuleStoreTestCase, API
actual_results = self._sorted_results(response)
expected_results = [
{
'course_id': text_type(self.course_key),
'course_id': str(self.course_key),
'mode_slug': 'audit',
'mode_display_name': 'Audit',
'min_price': 0,
@@ -142,7 +142,7 @@ class TestCourseModesListViews(CourseModesViewTestBase, ModuleStoreTestCase, API
'bulk_sku': None,
},
{
'course_id': text_type(self.course_key),
'course_id': str(self.course_key),
'mode_slug': 'verified',
'mode_display_name': 'Verified',
'min_price': 25,
@@ -165,7 +165,7 @@ class TestCourseModesListViews(CourseModesViewTestBase, ModuleStoreTestCase, API
other_actual_results = self._sorted_results(other_response)
other_expected_results = [
{
'course_id': text_type(self.other_course_key),
'course_id': str(self.other_course_key),
'mode_slug': 'other-audit',
'mode_display_name': 'Other Audit',
'min_price': 0,
@@ -199,7 +199,7 @@ class TestCourseModesListViews(CourseModesViewTestBase, ModuleStoreTestCase, API
url = self.get_url(course_id=self.course_key)
request_payload = {
'course_id': text_type(self.course_key),
'course_id': str(self.course_key),
'mode_slug': 'masters',
'mode_display_name': 'Masters',
'currency': 'usd',
@@ -220,7 +220,7 @@ class TestCourseModesListViews(CourseModesViewTestBase, ModuleStoreTestCase, API
url = self.get_url(course_id=self.course_key)
request_payload = {
'course_id': text_type(self.course_key),
'course_id': str(self.course_key),
'mode_slug': 'phd',
}
@@ -252,7 +252,7 @@ class TestCourseModesDetailViews(CourseModesViewTestBase, APITestCase):
Required method to implement AuthAndScopesTestMixin.
"""
kwargs = {
'course_id': text_type(course_id or self.course_key),
'course_id': str(course_id or self.course_key),
'mode_slug': mode_slug or 'audit',
}
return reverse(self.view_name, kwargs=kwargs)
@@ -282,7 +282,7 @@ class TestCourseModesDetailViews(CourseModesViewTestBase, APITestCase):
assert status.HTTP_200_OK == response.status_code
actual_data = dict(response.data)
expected_data = {
'course_id': text_type(self.course_key),
'course_id': str(self.course_key),
'mode_slug': 'audit',
'mode_display_name': 'Audit',
'min_price': 0,

View File

@@ -12,12 +12,12 @@ app_name = 'v1'
urlpatterns = [
url(
r'^courses/{course_id}/$'.format(course_id=settings.COURSE_ID_PATTERN),
fr'^courses/{settings.COURSE_ID_PATTERN}/$',
views.CourseModesView.as_view(),
name='course_modes_list'
),
url(
r'^courses/{course_id}/(?P<mode_slug>.*)$'.format(course_id=settings.COURSE_ID_PATTERN),
fr'^courses/{settings.COURSE_ID_PATTERN}/(?P<mode_slug>.*)$',
views.CourseModesDetailView.as_view(),
name='course_modes_detail'
),

View File

@@ -22,7 +22,7 @@ from openedx.core.lib.api.parsers import MergePatchParser
log = logging.getLogger(__name__)
class CourseModesMixin(object):
class CourseModesMixin:
"""
A base class for course modes views that specifies authentication, permissions,
serialization, pagination, and the base queryset.