INCR-160 (#20490)
* INCR-160: Run python-modernize on openedx/core/djangoapps/verified_track_content * INCR-160: [FIX] line over length limit, datetime - pytz import
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Django admin page for verified track configuration
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Forms for configuring courses for verified track cohorting
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext as _
|
||||
from opaque_keys import InvalidKeyError
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"""Management command to migrate a course's xblock's group_access from Verified Track Cohorts to Enrollment Tracks"""
|
||||
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
from contentstore.course_group_config import GroupConfiguration
|
||||
from django.conf import settings
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from opaque_keys.edx.django.models import CourseKeyField
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
"""
|
||||
Models for verified track selections.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import six
|
||||
|
||||
from config_models.models import ConfigurationModel
|
||||
from django.db import models
|
||||
@@ -49,7 +52,7 @@ def move_to_verified_cohort(sender, instance, **kwargs): # pylint: disable=unus
|
||||
# cohort yet exist.
|
||||
random_cohort = get_random_cohort(course_key)
|
||||
args = {
|
||||
'course_id': unicode(course_key),
|
||||
'course_id': six.text_type(course_key),
|
||||
'user_id': instance.user.id,
|
||||
'verified_cohort_name': verified_cohort_name,
|
||||
'default_cohort_name': random_cohort.name
|
||||
@@ -107,7 +110,7 @@ class VerifiedTrackCohortedCourse(models.Model):
|
||||
CACHE_NAMESPACE = u"verified_track_content.VerifiedTrackCohortedCourse.cache."
|
||||
|
||||
def __unicode__(self):
|
||||
return u"Course: {}, enabled: {}".format(unicode(self.course_key), self.enabled)
|
||||
return u"Course: {}, enabled: {}".format(six.text_type(self.course_key), self.enabled)
|
||||
|
||||
@classmethod
|
||||
def verified_cohort_name_for_course(cls, course_key):
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
"""
|
||||
UserPartitionScheme for enrollment tracks.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import six
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from courseware.masquerade import (
|
||||
@@ -45,7 +48,7 @@ class EnrollmentTrackUserPartition(UserPartition):
|
||||
return []
|
||||
|
||||
return [
|
||||
Group(ENROLLMENT_GROUP_IDS[mode.slug]["id"], unicode(mode.name))
|
||||
Group(ENROLLMENT_GROUP_IDS[mode.slug]["id"], six.text_type(mode.name))
|
||||
for mode in CourseMode.modes_for_course(course_key, include_expired=True)
|
||||
]
|
||||
|
||||
@@ -92,7 +95,7 @@ class EnrollmentTrackPartitionScheme(object):
|
||||
course_mode = CourseMode.verified_mode_for_course(course_key, include_expired=True)
|
||||
if not course_mode:
|
||||
course_mode = CourseMode.DEFAULT_MODE
|
||||
return Group(ENROLLMENT_GROUP_IDS[course_mode.slug]["id"], unicode(course_mode.name))
|
||||
return Group(ENROLLMENT_GROUP_IDS[course_mode.slug]["id"], six.text_type(course_mode.name))
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -112,7 +115,15 @@ class EnrollmentTrackPartitionScheme(object):
|
||||
Any group access rule referencing inactive partitions will be ignored
|
||||
when performing access checks.
|
||||
"""
|
||||
return EnrollmentTrackUserPartition(id, unicode(name), unicode(description), [], cls, parameters, active)
|
||||
return EnrollmentTrackUserPartition(
|
||||
id,
|
||||
six.text_type(name),
|
||||
six.text_type(description),
|
||||
[],
|
||||
cls,
|
||||
parameters,
|
||||
active
|
||||
)
|
||||
|
||||
|
||||
def is_course_using_cohort_instead(course_key):
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
"""
|
||||
Celery task for Automatic Verifed Track Cohorting MVP feature.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
|
||||
from celery.task import task
|
||||
from celery.utils.log import get_task_logger
|
||||
from django.contrib.auth.models import User
|
||||
@@ -54,6 +58,6 @@ def sync_cohort_with_mode(self, course_id, user_id, verified_cohort_name, defaul
|
||||
except Exception as exc:
|
||||
LOGGER.warning(
|
||||
u"SYNC_COHORT_WITH_MODE_RETRY: Exception encountered for course '%s' and user '%s': %s",
|
||||
course_id, user.id, unicode(exc)
|
||||
course_id, user.id, six.text_type(exc)
|
||||
)
|
||||
raise self.retry(exc=exc)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
"""
|
||||
Test for forms helpers.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
|
||||
|
||||
from openedx.core.djangoapps.verified_track_content.forms import VerifiedTrackCourseForm
|
||||
import six
|
||||
|
||||
|
||||
class TestVerifiedTrackCourseForm(SharedModuleStoreTestCase):
|
||||
@@ -22,7 +24,7 @@ class TestVerifiedTrackCourseForm(SharedModuleStoreTestCase):
|
||||
|
||||
def test_form_validation_success(self):
|
||||
form_data = {
|
||||
'course_key': unicode(self.course.id), 'verified_cohort_name': 'Verified Learners', 'enabled': True
|
||||
'course_key': six.text_type(self.course.id), 'verified_cohort_name': 'Verified Learners', 'enabled': True
|
||||
}
|
||||
form = VerifiedTrackCourseForm(data=form_data)
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
@@ -3,9 +3,11 @@ Tests for Verified Track Cohorting models
|
||||
"""
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
from mock import patch
|
||||
import six
|
||||
|
||||
from django.test import TestCase
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
@@ -52,7 +54,7 @@ class TestVerifiedTrackCohortedCourse(TestCase):
|
||||
# Enable for a course
|
||||
config = VerifiedTrackCohortedCourse.objects.create(course_key=course_key, enabled=True)
|
||||
config.save()
|
||||
self.assertEqual(unicode(config), u"Course: {}, enabled: True".format(self.SAMPLE_COURSE))
|
||||
self.assertEqual(six.text_type(config), u"Course: {}, enabled: True".format(self.SAMPLE_COURSE))
|
||||
|
||||
def test_verified_cohort_name(self):
|
||||
cohort_name = 'verified cohort'
|
||||
@@ -83,7 +85,7 @@ class TestMoveToVerified(SharedModuleStoreTestCase):
|
||||
super(TestMoveToVerified, self).setUp()
|
||||
self.user = UserFactory()
|
||||
# Spy on number of calls to celery task.
|
||||
celery_task_patcher = patch.object(
|
||||
celery_task_patcher = mock.patch.object(
|
||||
sync_cohort_with_mode, 'apply_async',
|
||||
mock.Mock(wraps=sync_cohort_with_mode.apply_async)
|
||||
)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
"""
|
||||
Tests for verified_track_content/partition_scheme.py.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytz
|
||||
import six
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from student.models import CourseEnrollment
|
||||
@@ -104,7 +107,7 @@ class EnrollmentTrackPartitionSchemeTest(SharedModuleStoreTestCase):
|
||||
|
||||
def test_create_user_partition(self):
|
||||
user_partition = UserPartition.get_scheme('enrollment_track').create_user_partition(
|
||||
301, "partition", "test partition", parameters={"course_id": unicode(self.course.id)}
|
||||
301, "partition", "test partition", parameters={"course_id": six.text_type(self.course.id)}
|
||||
)
|
||||
self.assertEqual(type(user_partition), EnrollmentTrackUserPartition)
|
||||
self.assertEqual(user_partition.name, "partition")
|
||||
@@ -183,7 +186,7 @@ def create_enrollment_track_partition(course):
|
||||
id=1,
|
||||
name="Test Enrollment Track Partition",
|
||||
description="Test partition for segmenting users by enrollment track",
|
||||
parameters={"course_id": unicode(course.id)}
|
||||
parameters={"course_id": six.text_type(course.id)}
|
||||
)
|
||||
return partition
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
Tests for verified track content views.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
import six
|
||||
|
||||
from django.http import Http404
|
||||
from django.test.client import RequestFactory
|
||||
@@ -34,14 +37,14 @@ class CohortingSettingsTestCase(SharedModuleStoreTestCase):
|
||||
request = RequestFactory().get("dummy_url")
|
||||
request.user = UserFactory()
|
||||
with self.assertRaises(Http404):
|
||||
cohorting_settings(request, unicode(self.course.id))
|
||||
cohorting_settings(request, six.text_type(self.course.id))
|
||||
|
||||
def test_cohorting_settings_enabled(self):
|
||||
"""
|
||||
Verify that cohorting_settings is working for HTTP GET when verified track cohorting is enabled.
|
||||
"""
|
||||
config = VerifiedTrackCohortedCourse.objects.create(
|
||||
course_key=unicode(self.course.id), enabled=True, verified_cohort_name="Verified Learners"
|
||||
course_key=six.text_type(self.course.id), enabled=True, verified_cohort_name="Verified Learners"
|
||||
)
|
||||
config.save()
|
||||
|
||||
@@ -64,6 +67,6 @@ class CohortingSettingsTestCase(SharedModuleStoreTestCase):
|
||||
""" Verify that the response was successful and matches the expected JSON payload. """
|
||||
request = RequestFactory().get("dummy_url")
|
||||
request.user = AdminFactory()
|
||||
response = cohorting_settings(request, unicode(self.course.id))
|
||||
response = cohorting_settings(request, six.text_type(self.course.id))
|
||||
self.assertEqual(200, response.status_code)
|
||||
self.assertEqual(expected_response, json.loads(response.content))
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
View methods for verified track content.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
|
||||
Reference in New Issue
Block a user