pyupgrade in course-bookmarks, course-duration
This commit is contained in:
Awais Qureshi
2021-03-10 18:35:45 +05:00
parent ba4708edd0
commit 805e10a5ac
15 changed files with 23 additions and 33 deletions

View File

@@ -24,7 +24,7 @@ class TestCourseBookmarksTool(SharedModuleStoreTestCase):
Set up a course to be used for testing.
"""
# pylint: disable=super-method-not-called
with super(TestCourseBookmarksTool, cls).setUpClassAndTestData():
with super().setUpClassAndTestData():
with cls.store.default_store(ModuleStoreEnum.Type.split):
cls.course = CourseFactory.create()
with cls.store.bulk_operations(cls.course.id):

View File

@@ -43,7 +43,7 @@ class CourseBookmarksView(View):
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
course_url_name = default_course_url_name(course.id)
course_url = reverse(course_url_name, kwargs={'course_id': six.text_type(course.id)})
course_url = reverse(course_url_name, kwargs={'course_id': str(course.id)})
# Render the bookmarks list as a fragment
bookmarks_fragment = CourseBookmarksFragmentView().render_to_fragment(request, course_id=course_id)

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Contains code related to computing content gating course duration limits
and course access based on these limits.
@@ -28,7 +27,7 @@ class AuditExpiredError(AccessError):
"""
def __init__(self, user, course, expiration_date):
error_code = 'audit_expired'
developer_message = 'User {} had access to {} until {}'.format(user, course, expiration_date)
developer_message = f'User {user} had access to {course} until {expiration_date}'
expiration_date = strftime_localized(expiration_date, 'SHORT_DATE')
user_message = _('Access expired on {expiration_date}').format(expiration_date=expiration_date)
try:
@@ -42,7 +41,7 @@ class AuditExpiredError(AccessError):
' for expired on {expiration_date}').format(
expiration_date=expiration_date
)
super(AuditExpiredError, self).__init__(error_code, developer_message, user_message, # lint-amnesty, pylint: disable=super-with-arguments
super().__init__(error_code, developer_message, user_message, # lint-amnesty, pylint: disable=super-with-arguments
additional_context_user_message)
@@ -219,7 +218,7 @@ def generate_course_expired_fragment_from_key(user, course_key):
shouldn't show a course expired message for this user.
"""
request_cache = RequestCache('generate_course_expired_fragment_from_key')
cache_key = 'message:{},{}'.format(user.id, course_key)
cache_key = f'message:{user.id},{course_key}'
cache_response = request_cache.get_cached_response(cache_key)
if cache_response.is_found:
cached_message = cache_response.value

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Django Admin pages for CourseDurationLimitConfig.
"""

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-08 19:43

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-19 14:59

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-28 19:07

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-28 20:21

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-06 15:46

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-08 14:47

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-11 19:19

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-13 16:34

View File

@@ -32,7 +32,7 @@ from common.djangoapps.util.date_utils import strftime_localized
class TestAccess(CacheIsolationTestCase):
"""Tests of openedx.features.course_duration_limits.access"""
def setUp(self):
super(TestAccess, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
super().setUp() # lint-amnesty, pylint: disable=super-with-arguments
CourseDurationLimitConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1, tzinfo=UTC))
DynamicUpgradeDeadlineConfiguration.objects.create(enabled=True)

View File

@@ -5,7 +5,7 @@ Contains tests to verify correctness of course expiration functionality
from datetime import timedelta
import ddt
import mock
from unittest import mock
import six
from django.conf import settings
from django.urls import reverse
@@ -48,7 +48,7 @@ from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID
class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin):
"""Tests to verify the get_user_course_expiration_date function is working correctly"""
def setUp(self):
super(CourseExpirationTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
super().setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.course = CourseFactory(
start=now() - timedelta(weeks=10),
)
@@ -61,7 +61,7 @@ class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin):
def tearDown(self):
CourseEnrollment.unenroll(self.user, self.course.id)
super(CourseExpirationTestCase, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments
super().tearDown() # lint-amnesty, pylint: disable=super-with-arguments
def test_enrollment_mode(self):
"""Tests that verified enrollments do not have an expiration"""
@@ -236,10 +236,10 @@ class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin):
self.update_masquerade(**masquerade_config)
course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)])
course_home_url = reverse('openedx.course_experience.course_home', args=[str(self.course.id)])
response = self.client.get(course_home_url, follow=True)
assert response.status_code == 200
six.assertCountEqual(self, response.redirect_chain, [])
self.assertCountEqual(response.redirect_chain, [])
banner_text = 'You lose all access to this course, including your progress,'
if show_expiration_banner:
self.assertContains(response, banner_text)
@@ -273,10 +273,10 @@ class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin):
self.update_masquerade(username='audit')
course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)])
course_home_url = reverse('openedx.course_experience.course_home', args=[str(self.course.id)])
response = self.client.get(course_home_url, follow=True)
assert response.status_code == 200
six.assertCountEqual(self, response.redirect_chain, [])
self.assertCountEqual(response.redirect_chain, [])
banner_text = 'You lose all access to this course, including your progress,'
self.assertNotContains(response, banner_text)
@@ -309,10 +309,10 @@ class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin):
self.update_masquerade(username='audit')
course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)])
course_home_url = reverse('openedx.course_experience.course_home', args=[str(self.course.id)])
response = self.client.get(course_home_url, follow=True)
assert response.status_code == 200
six.assertCountEqual(self, response.redirect_chain, [])
self.assertCountEqual(response.redirect_chain, [])
banner_text = 'This learner does not have access to this course. Their access expired on'
self.assertContains(response, banner_text)
@@ -360,10 +360,10 @@ class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin):
self.update_masquerade(username=expired_staff.username)
course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)])
course_home_url = reverse('openedx.course_experience.course_home', args=[str(self.course.id)])
response = self.client.get(course_home_url, follow=True)
assert response.status_code == 200
six.assertCountEqual(self, response.redirect_chain, [])
self.assertCountEqual(response.redirect_chain, [])
banner_text = 'This learner does not have access to this course. Their access expired on'
self.assertNotContains(response, banner_text)
@@ -409,9 +409,9 @@ class CourseExpirationTestCase(ModuleStoreTestCase, MasqueradeMixin):
self.update_masquerade(username=expired_staff.username)
course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)])
course_home_url = reverse('openedx.course_experience.course_home', args=[str(self.course.id)])
response = self.client.get(course_home_url, follow=True)
assert response.status_code == 200
six.assertCountEqual(self, response.redirect_chain, [])
self.assertCountEqual(response.redirect_chain, [])
banner_text = 'This learner does not have access to this course. Their access expired on'
self.assertNotContains(response, banner_text)

View File

@@ -10,7 +10,7 @@ import pytest
import pytz
from django.utils import timezone
from edx_django_utils.cache import RequestCache
from mock import Mock
from unittest.mock import Mock
from opaque_keys.edx.locator import CourseLocator
from common.djangoapps.course_modes.tests.factories import CourseModeFactory
@@ -35,7 +35,7 @@ class TestCourseDurationLimitConfig(CacheIsolationTestCase):
CourseModeFactory.create(course_id=self.course_overview.id, mode_slug='audit')
CourseModeFactory.create(course_id=self.course_overview.id, mode_slug='verified')
self.user = UserFactory.create()
super(TestCourseDurationLimitConfig, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
super().setUp() # lint-amnesty, pylint: disable=super-with-arguments
@ddt.data(
(True, True),
@@ -188,7 +188,7 @@ class TestCourseDurationLimitConfig(CacheIsolationTestCase):
)
for org_setting in (True, False, None):
test_org = "{}-{}".format(test_site_cfg.id, org_setting)
test_org = f"{test_site_cfg.id}-{org_setting}"
test_site_cfg.site_values['course_org_filter'].append(test_org)
test_site_cfg.save()
@@ -199,7 +199,7 @@ class TestCourseDurationLimitConfig(CacheIsolationTestCase):
for course_setting in (True, False, None):
test_course = CourseOverviewFactory.create(
org=test_org,
id=CourseLocator(test_org, 'test_course', 'run-{}'.format(course_setting))
id=CourseLocator(test_org, 'test_course', f'run-{course_setting}')
)
CourseDurationLimitConfig.objects.create(
course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1, tzinfo=pytz.UTC) # lint-amnesty, pylint: disable=line-too-long