Skip to content
Snippets Groups Projects
Unverified Commit 6214f2de authored by Awais Qureshi's avatar Awais Qureshi Committed by GitHub
Browse files

Merge pull request #26940 from edx/course-bookmarks

pyupgrade in course-bookmarks, course-duration 
parents 2c0a8242 e92bdc5d
No related branches found
No related tags found
No related merge requests found
Showing
with 28 additions and 37 deletions
......@@ -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):
......
......@@ -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)
......
# -*- 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,8 +41,9 @@ 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
additional_context_user_message)
# lint-amnesty, pylint: disable=super-with-arguments
super().__init__(error_code, developer_message, user_message, additional_context_user_message)
def get_user_course_duration(user, course):
......@@ -219,7 +219,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
......
# -*- coding: utf-8 -*-
"""
Django Admin pages for CourseDurationLimitConfig.
"""
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-08 19:43
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-19 14:59
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-28 19:07
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-28 20:21
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-06 15:46
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-08 14:47
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-11 19:19
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-13 16:34
......
......@@ -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)
......
......@@ -3,15 +3,18 @@ Contains tests to verify correctness of course expiration functionality
"""
from datetime import timedelta
from unittest import mock
import ddt
import mock
import six
from django.conf import settings
from django.urls import reverse
from django.utils.timezone import now
from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.student.models import CourseEnrollment, FBEEnrollmentExclusion
from common.djangoapps.student.roles import CourseInstructorRole
from common.djangoapps.student.tests.factories import TEST_PASSWORD, CourseEnrollmentFactory, UserFactory
from lms.djangoapps.courseware.tests.factories import (
BetaTesterFactory,
GlobalStaffFactory,
......@@ -35,9 +38,6 @@ from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITIO
from openedx.features.course_duration_limits.access import get_user_course_expiration_date
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
from openedx.features.course_experience.tests.views.helpers import add_course_mode
from common.djangoapps.student.models import CourseEnrollment, FBEEnrollmentExclusion
from common.djangoapps.student.roles import CourseInstructorRole
from common.djangoapps.student.tests.factories import TEST_PASSWORD, CourseEnrollmentFactory, UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID
......@@ -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)
......@@ -4,13 +4,13 @@ Tests of CourseDurationLimitConfig.
import itertools
from datetime import datetime, timedelta
from unittest.mock import Mock
import ddt
import pytest
import pytz
from django.utils import timezone
from edx_django_utils.cache import RequestCache
from 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment