pyupgrade in program_enrollments (#26597)

This commit is contained in:
M. Zulqarnain
2021-02-22 12:58:16 +05:00
committed by GitHub
parent b6a2b91dd5
commit f4a5af29d3
40 changed files with 176 additions and 196 deletions

View File

@@ -8,10 +8,8 @@ from `lms.djangoapps.program_enrollments.api`.
import logging
from six import text_type
from lms.djangoapps.grades.api import CourseGradeFactory, clear_prefetched_course_grades, prefetch_course_grades
from common.djangoapps.util.query import read_replica_or_default
from lms.djangoapps.grades.api import CourseGradeFactory, clear_prefetched_course_grades, prefetch_course_grades
from .reading import fetch_program_course_enrollments
@@ -74,7 +72,7 @@ def _generate_grades(course_key, enrollments):
error_string = error_template.format(
user.id,
course_key,
text_type(exception) if exception else 'Unknown error'
str(exception) if exception else 'Unknown error'
)
logger.error(error_string)
yield ProgramCourseGradeError(enrollment, exception)
@@ -82,7 +80,7 @@ def _generate_grades(course_key, enrollments):
clear_prefetched_course_grades(course_key)
class BaseProgramCourseGrade(object):
class BaseProgramCourseGrade:
"""
Base for either a courserun grade or grade-loading failure.
@@ -109,7 +107,7 @@ class ProgramCourseGradeOk(BaseProgramCourseGrade):
Given a ProgramCourseEnrollment and course grade object,
create a ProgramCourseGradeOk.
"""
super(ProgramCourseGradeOk, self).__init__( # lint-amnesty, pylint: disable=super-with-arguments
super().__init__(
program_course_enrollment
)
self.passed = course_grade.passed
@@ -129,7 +127,7 @@ class ProgramCourseGradeError(BaseProgramCourseGrade):
Given a ProgramCourseEnrollment and an Exception,
create a ProgramCourseGradeError.
"""
super(ProgramCourseGradeError, self).__init__( # lint-amnesty, pylint: disable=super-with-arguments
super().__init__(
program_course_enrollment
)
self.error = text_type(exception) if exception else "Unknown error"
self.error = str(exception) if exception else "Unknown error"

View File

@@ -9,9 +9,9 @@ from `lms.djangoapps.program_enrollments.api`.
from organizations.models import Organization
from social_django.models import UserSocialAuth
from openedx.core.djangoapps.catalog.utils import get_programs
from common.djangoapps.student.roles import CourseStaffRole
from common.djangoapps.third_party_auth.models import SAMLProviderConfig
from openedx.core.djangoapps.catalog.utils import get_programs
from ..constants import ProgramCourseEnrollmentRoles
from ..exceptions import (

View File

@@ -3,23 +3,23 @@ Tests for account linking Python API.
"""
from unittest.mock import patch
from uuid import uuid4
from unittest.mock import patch
from django.test import TestCase
from edx_django_utils.cache import RequestCache
from opaque_keys.edx.keys import CourseKey
from testfixtures import LogCapture
from common.djangoapps.student.api import get_course_access_role
from common.djangoapps.student.roles import CourseStaffRole
from common.djangoapps.student.tests.factories import CourseAccessRoleFactory, UserFactory
from lms.djangoapps.program_enrollments.tests.factories import (
CourseAccessRoleAssignmentFactory,
ProgramCourseEnrollmentFactory,
ProgramEnrollmentFactory
)
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
from common.djangoapps.student.api import get_course_access_role
from common.djangoapps.student.roles import CourseStaffRole
from common.djangoapps.student.tests.factories import CourseAccessRoleFactory, UserFactory
from ..linking import (
NO_LMS_USER_TEMPLATE,
@@ -31,7 +31,7 @@ from ..linking import (
LOG_PATH = 'lms.djangoapps.program_enrollments.api.linking'
class TestLinkProgramEnrollmentsMixin(object):
class TestLinkProgramEnrollmentsMixin:
""" Utility methods and test data for testing linking """
@classmethod

View File

@@ -14,6 +14,9 @@ from organizations.tests.factories import OrganizationFactory
from social_django.models import UserSocialAuth
from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.student.roles import CourseStaffRole
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from common.djangoapps.third_party_auth.tests.factories import SAMLProviderConfigFactory
from lms.djangoapps.program_enrollments.constants import ProgramCourseEnrollmentStatuses as PCEStatuses
from lms.djangoapps.program_enrollments.constants import ProgramEnrollmentStatuses as PEStatuses
from lms.djangoapps.program_enrollments.exceptions import (
@@ -33,9 +36,6 @@ from openedx.core.djangoapps.catalog.tests.factories import OrganizationFactory
from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
from common.djangoapps.student.roles import CourseStaffRole
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from common.djangoapps.third_party_auth.tests.factories import SAMLProviderConfigFactory
from ..reading import (
fetch_program_course_enrollments,
@@ -78,7 +78,7 @@ class ProgramEnrollmentReadingTests(TestCase):
@classmethod
def setUpTestData(cls):
super(ProgramEnrollmentReadingTests, cls).setUpTestData()
super().setUpTestData()
cls.user_0 = UserFactory(username=cls.username_0) # No enrollments
cls.user_1 = UserFactory(username=cls.username_1)
cls.user_2 = UserFactory(username=cls.username_2)
@@ -495,7 +495,7 @@ class GetUsersByExternalKeysTests(CacheIsolationTestCase):
@classmethod
def setUpTestData(cls):
super(GetUsersByExternalKeysTests, cls).setUpTestData()
super().setUpTestData()
cls.program_uuid = UUID('e7a82f8d-d485-486b-b733-a28222af92bf')
cls.organization_key = 'ufo'
cls.external_user_id = '1234'
@@ -504,7 +504,7 @@ class GetUsersByExternalKeysTests(CacheIsolationTestCase):
cls.user_2 = UserFactory(username='user-2')
def setUp(self):
super(GetUsersByExternalKeysTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
super().setUp()
catalog_org = CatalogOrganizationFactory.create(key=self.organization_key)
program = ProgramFactory.create(
uuid=self.program_uuid,
@@ -518,7 +518,7 @@ class GetUsersByExternalKeysTests(CacheIsolationTestCase):
"""
UserSocialAuth.objects.create(
user=user,
uid='{0}:{1}'.format(provider.slug, external_id),
uid=f'{provider.slug}:{external_id}',
provider=provider.backend_name,
)
@@ -637,7 +637,7 @@ class IsCourseStaffEnrollmentTest(TestCase):
@classmethod
def setUpTestData(cls):
super(IsCourseStaffEnrollmentTest, cls).setUpTestData()
super().setUpTestData()
cls.user_0 = UserFactory(username=cls.username_0) # No enrollments
CourseOverviewFactory(id=cls.course_key_p)
CourseOverviewFactory(id=cls.course_key_q)

View File

@@ -17,6 +17,9 @@ from opaque_keys.edx.keys import CourseKey
from organizations.tests.factories import OrganizationFactory
from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.student.roles import CourseStaffRole
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from common.djangoapps.third_party_auth.tests.factories import SAMLProviderConfigFactory
from lms.djangoapps.program_enrollments.constants import ProgramCourseEnrollmentRoles
from lms.djangoapps.program_enrollments.constants import ProgramCourseOperationStatuses as CourseStatuses
from lms.djangoapps.program_enrollments.constants import ProgramEnrollmentStatuses as PEStatuses
@@ -32,9 +35,6 @@ from openedx.core.djangoapps.catalog.tests.factories import OrganizationFactory
from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
from common.djangoapps.student.roles import CourseStaffRole
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from common.djangoapps.third_party_auth.tests.factories import SAMLProviderConfigFactory
from ..writing import write_program_course_enrollments, write_program_enrollments
@@ -56,7 +56,7 @@ class EnrollmentTestMixin(CacheIsolationTestCase):
"""
Set up test data
"""
super(EnrollmentTestMixin, cls).setUpClass()
super().setUpClass()
catalog_org = CatalogOrganizationFactory.create(key=cls.organization_key)
cls.program = ProgramFactory.create(
uuid=cls.program_uuid,
@@ -66,7 +66,7 @@ class EnrollmentTestMixin(CacheIsolationTestCase):
SAMLProviderConfigFactory.create(organization=organization)
catalog_course_id_str = 'course-v1:edX+ToyX'
course_run_id_str = '{}+Toy_Course'.format(catalog_course_id_str)
course_run_id_str = f'{catalog_course_id_str}+Toy_Course'
cls.course_id = CourseKey.from_string(course_run_id_str)
CourseOverviewFactory(id=cls.course_id)
course_run = CourseRunFactory(key=course_run_id_str)
@@ -75,7 +75,7 @@ class EnrollmentTestMixin(CacheIsolationTestCase):
cls.student_2 = UserFactory(username='student-2')
def setUp(self):
super(EnrollmentTestMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
super().setUp()
cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid), self.program, None)
def create_program_enrollment(self, external_user_key, user=False):

View File

@@ -11,9 +11,9 @@ import logging
from simple_history.utils import bulk_create_with_history
from common.djangoapps.course_modes.models import CourseMode
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from common.djangoapps.student.models import CourseEnrollment, NonExistentCourseError
from common.djangoapps.student.roles import CourseStaffRole
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from ..constants import ProgramCourseEnrollmentRoles, ProgramCourseEnrollmentStatuses
from ..constants import ProgramCourseOperationStatuses as ProgramCourseOpStatuses
@@ -390,7 +390,7 @@ def enroll_in_masters_track(user, course_key, status):
"""
_ensure_course_exists(course_key, user.id)
if status not in ProgramCourseEnrollmentStatuses.__ALL__:
raise ValueError("invalid ProgramCourseEnrollmentStatus: {}".format(status))
raise ValueError(f"invalid ProgramCourseEnrollmentStatus: {status}")
if CourseEnrollment.is_enrolled(user, course_key):
course_enrollment = CourseEnrollment.objects.get(
user=user,
@@ -552,8 +552,8 @@ def _get_conflicting_active_course_enrollments(
and str(existing_enrollment.program_enrollment.program_uuid) != str(program_uuid)
):
logger.error(
u'Detected conflicting active ProgramCourseEnrollment. This is happening on'
u' The program_uuid [{}] with course_key [{}] for external_user_key [{}]'.format(
'Detected conflicting active ProgramCourseEnrollment. This is happening on'
' The program_uuid [{}] with course_key [{}] for external_user_key [{}]'.format(
program_uuid,
course_key,
external_user_key