INCR-274 Run python-modernize on lms/djangoapps/badges/events and lms/djangoapps/badges/tests (#20585)
* run python modernize * run isort * Fix quality
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
"""
|
||||
Helper functions for the course complete event that was originally included with the Badging MVP.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import hashlib
|
||||
import logging
|
||||
|
||||
import six
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
@@ -29,8 +32,8 @@ def course_slug(course_key, mode):
|
||||
Badgr's max slug length is 255.
|
||||
"""
|
||||
# Seven digits should be enough to realistically avoid collisions. That's what git services use.
|
||||
digest = hashlib.sha256(u"{}{}".format(unicode(course_key), unicode(mode))).hexdigest()[:7]
|
||||
base_slug = slugify(unicode(course_key) + u'_{}_'.format(mode))[:248]
|
||||
digest = hashlib.sha256(u"{}{}".format(six.text_type(course_key), six.text_type(mode))).hexdigest()[:7]
|
||||
base_slug = slugify(six.text_type(course_key) + u'_{}_'.format(mode))[:248]
|
||||
return base_slug + digest
|
||||
|
||||
|
||||
@@ -57,15 +60,16 @@ def evidence_url(user_id, course_key):
|
||||
Generates a URL to the user's Certificate HTML view, along with a GET variable that will signal the evidence visit
|
||||
event.
|
||||
"""
|
||||
course_id = six.text_type(course_key)
|
||||
return site_prefix() + reverse(
|
||||
'certificates:html_view', kwargs={'user_id': user_id, 'course_id': unicode(course_key)}) + '?evidence_visit=1'
|
||||
'certificates:html_view', kwargs={'user_id': user_id, 'course_id': course_id}) + '?evidence_visit=1'
|
||||
|
||||
|
||||
def criteria(course_key):
|
||||
"""
|
||||
Constructs the 'criteria' URL from the course about page.
|
||||
"""
|
||||
about_path = reverse('about_course', kwargs={'course_id': unicode(course_key)})
|
||||
about_path = reverse('about_course', kwargs={'course_id': six.text_type(course_key)})
|
||||
return u'{}{}'.format(site_prefix(), about_path)
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ Events which have to do with a user doing something with more than one course, s
|
||||
as enrolling in a certain number, completing a certain number, or completing a specific set of courses.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from badges.models import BadgeClass, CourseEventBadgesConfiguration
|
||||
from badges.utils import requires_badges_enabled
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Tests for the course completion helper functions.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from badges.events import course_complete
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
"""
|
||||
Tests the course meta badging events
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from six.moves import range, zip
|
||||
from ddt import data, ddt, unpack
|
||||
from django.conf import settings
|
||||
from django.test.utils import override_settings
|
||||
@@ -142,11 +146,11 @@ class CourseGroupBadgeTest(ModuleStoreTestCase):
|
||||
self.courses = []
|
||||
for _badge_class in self.badge_classes:
|
||||
self.courses.append([CourseFactory().location.course_key for _i in range(3)])
|
||||
lines = [badge_class.slug + ',' + ','.join([unicode(course_key) for course_key in keys])
|
||||
lines = [badge_class.slug + ',' + ','.join([six.text_type(course_key) for course_key in keys])
|
||||
for badge_class, keys in zip(self.badge_classes, self.courses)]
|
||||
config = '\r'.join(lines)
|
||||
self.config = CourseEventBadgesConfigurationFactory(course_groups=config)
|
||||
self.config_map = dict(zip(self.badge_classes, self.courses))
|
||||
self.config_map = dict(list(zip(self.badge_classes, self.courses)))
|
||||
|
||||
def test_no_match(self):
|
||||
"""
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Factories for Badge tests
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from random import random
|
||||
|
||||
import factory
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"""
|
||||
Tests for the Badges app models.
|
||||
"""
|
||||
from path import Path
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files.images import ImageFile
|
||||
from django.core.files.storage import default_storage
|
||||
@@ -9,6 +10,8 @@ from django.db.utils import IntegrityError
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from mock import Mock, patch
|
||||
from path import Path
|
||||
from six.moves import range
|
||||
|
||||
from badges.models import (
|
||||
BadgeAssertion,
|
||||
|
||||
Reference in New Issue
Block a user