Merge pull request #20607 from edx/estute/INCR-316

INCR-316 Run python-modernize on lms/djangoapps/grades/rest_api/v1
This commit is contained in:
Christie Rice
2019-05-15 14:12:54 -04:00
committed by GitHub
8 changed files with 47 additions and 46 deletions

View File

@@ -1,51 +1,45 @@
"""
Defines an endpoint for gradebook data related to a course.
"""
from __future__ import absolute_import
import logging
from collections import namedtuple
from contextlib import contextmanager
from functools import wraps
import six
from django.urls import reverse
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey, UsageKey
from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from rest_framework.views import APIView
from six import text_type
from util.date_utils import to_timestamp
from courseware.courses import get_course_by_id
from lms.djangoapps.grades.api import (
CourseGradeFactory,
is_writable_gradebook_enabled,
prefetch_course_and_subsection_grades,
clear_prefetched_course_and_subsection_grades,
constants as grades_constants,
context as grades_context,
events as grades_events,
)
from lms.djangoapps.grades.api import CourseGradeFactory, clear_prefetched_course_and_subsection_grades
from lms.djangoapps.grades.api import constants as grades_constants
from lms.djangoapps.grades.api import context as grades_context
from lms.djangoapps.grades.api import events as grades_events
from lms.djangoapps.grades.api import is_writable_gradebook_enabled, prefetch_course_and_subsection_grades
from lms.djangoapps.grades.course_data import CourseData
from lms.djangoapps.grades.grade_utils import are_grades_frozen
# TODO these imports break abstraction of the core Grades layer. This code needs
# to be refactored so Gradebook views only access public Grades APIs.
from lms.djangoapps.grades.models import (
PersistentSubsectionGrade,
PersistentSubsectionGradeOverride,
PersistentSubsectionGradeOverrideHistory,
PersistentSubsectionGradeOverrideHistory
)
from lms.djangoapps.grades.rest_api.serializers import (
StudentGradebookEntrySerializer,
SubsectionGradeResponseSerializer,
)
from lms.djangoapps.grades.rest_api.v1.utils import (
USER_MODEL,
CourseEnrollmentPagination,
GradeViewMixin,
SubsectionGradeResponseSerializer
)
from lms.djangoapps.grades.rest_api.v1.utils import USER_MODEL, CourseEnrollmentPagination, GradeViewMixin
from lms.djangoapps.grades.subsection_grade import CreateSubsectionGrade
from lms.djangoapps.grades.tasks import recalculate_subsection_grade_v3
from lms.djangoapps.grades.grade_utils import are_grades_frozen
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey, UsageKey
from openedx.core.djangoapps.course_groups import cohorts
from openedx.core.djangoapps.util.forms import to_bool
from openedx.core.lib.api.view_utils import (
@@ -53,7 +47,7 @@ from openedx.core.lib.api.view_utils import (
PaginatedAPIView,
get_course_key,
verify_course_exists,
view_auth_classes,
view_auth_classes
)
from openedx.core.lib.cache_utils import request_cached
from student.auth import has_course_author_access
@@ -65,6 +59,7 @@ from track.event_transaction_utils import (
get_event_transaction_type,
set_event_transaction_type
)
from util.date_utils import to_timestamp
from xmodule.modulestore.django import modulestore
from xmodule.util.misc import get_default_short_labeler
@@ -740,8 +735,8 @@ class GradebookBulkUpdateView(GradeViewMixin, PaginatedAPIView):
only_if_higher=False,
expected_modified_time=to_timestamp(override.modified),
score_deleted=False,
event_transaction_id=unicode(get_event_transaction_id()),
event_transaction_type=unicode(get_event_transaction_type()),
event_transaction_id=six.text_type(get_event_transaction_id()),
event_transaction_type=six.text_type(get_event_transaction_type()),
score_db_table=grades_constants.ScoreDatabaseTableEnum.overrides,
force_update_subsections=True,
)

View File

@@ -1,15 +1,18 @@
"""
Mixins classes being used by all test classes within this folder
"""
from __future__ import absolute_import
from datetime import datetime
from pytz import UTC
from six.moves import range
from lms.djangoapps.courseware.tests.factories import GlobalStaffFactory
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE
class GradeViewTestMixin(SharedModuleStoreTestCase):
@@ -98,7 +101,7 @@ class GradeViewTestMixin(SharedModuleStoreTestCase):
# create a problem for each type and minimum count needed by the grading policy
# A section is not considered if the student answers less than "min_count" problems
for grading_type, min_count in (("Homework", 12), ("Lab", 12), ("Midterm Exam", 1), ("Final Exam", 1)):
for num in xrange(min_count):
for num in range(min_count):
section = ItemFactory.create(
category='sequential',
parent_location=chapter.location,

View File

@@ -1,7 +1,7 @@
"""
Tests for the course grading API view
"""
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
import json
from collections import OrderedDict, namedtuple
@@ -18,6 +18,7 @@ from rest_framework.test import APITestCase
from six import text_type
from course_modes.models import CourseMode
from lms.djangoapps.certificates.models import CertificateStatuses, GeneratedCertificate
from lms.djangoapps.courseware.tests.factories import InstructorFactory, StaffFactory
from lms.djangoapps.grades.config.waffle import WRITABLE_GRADEBOOK, waffle_flags
from lms.djangoapps.grades.constants import GradeOverrideFeatureEnum
@@ -28,14 +29,10 @@ from lms.djangoapps.grades.models import (
BlockRecordList,
PersistentSubsectionGrade,
PersistentSubsectionGradeOverride,
PersistentSubsectionGradeOverrideHistory,
PersistentSubsectionGradeOverrideHistory
)
from lms.djangoapps.grades.rest_api.v1.tests.mixins import GradeViewTestMixin
from lms.djangoapps.grades.rest_api.v1.views import CourseEnrollmentPagination
from lms.djangoapps.certificates.models import (
GeneratedCertificate,
CertificateStatuses,
)
from lms.djangoapps.grades.subsection_grade import ReadSubsectionGrade
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory

View File

@@ -1,9 +1,12 @@
"""
Tests for the views
"""
from __future__ import absolute_import
from datetime import datetime
import ddt
import six
from django.urls import reverse
from edx_oauth2_provider.tests.factories import AccessTokenFactory, ClientFactory
from pytz import UTC
@@ -36,7 +39,7 @@ class GradingPolicyTestMixin(object):
def create_course_data(cls):
cls.invalid_course_id = 'foo/bar/baz'
cls.course = CourseFactory.create(display_name='An Introduction to API Testing', raw_grader=cls.raw_grader)
cls.course_id = unicode(cls.course.id)
cls.course_id = six.text_type(cls.course.id)
with cls.store.bulk_operations(cls.course.id, emit_signals=False):
cls.sequential = ItemFactory.create(
category="sequential",
@@ -150,7 +153,7 @@ class GradingPolicyTestMixin(object):
org="MTD",
default_store=modulestore_type,
)
self.assert_get_for_course(course_id=unicode(course.id))
self.assert_get_for_course(course_id=six.text_type(course.id))
class CourseGradingPolicyTests(GradingPolicyTestMixin, SharedModuleStoreTestCase):

View File

@@ -1,7 +1,8 @@
"""
Tests for v1 views
"""
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
from collections import OrderedDict
import ddt

View File

@@ -1,10 +1,11 @@
""" Grades API v1 URLs. """
from __future__ import absolute_import
from django.conf import settings
from django.conf.urls import url
from lms.djangoapps.grades.rest_api.v1 import gradebook_views, views
app_name = 'lms.djangoapps.grades'
urlpatterns = [

View File

@@ -1,6 +1,8 @@
"""
Define some view level utility functions here that multiple view modules will share
"""
from __future__ import absolute_import
from contextlib import contextmanager
from django.contrib.auth import get_user_model

View File

@@ -1,22 +1,21 @@
""" API v0 views. """
from __future__ import absolute_import
import logging
from contextlib import contextmanager
from rest_framework import status
from rest_framework.generics import ListAPIView
from rest_framework.response import Response
from edx_rest_framework_extensions import permissions
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
from lms.djangoapps.courseware.access import has_access
from lms.djangoapps.grades.rest_api.serializers import GradingPolicySerializer
from lms.djangoapps.grades.rest_api.v1.utils import (
CourseEnrollmentPagination,
GradeViewMixin,
)
from lms.djangoapps.grades.api import CourseGradeFactory, prefetch_course_grades, clear_prefetched_course_grades
from opaque_keys import InvalidKeyError
from rest_framework import status
from rest_framework.generics import ListAPIView
from rest_framework.response import Response
from lms.djangoapps.courseware.access import has_access
from lms.djangoapps.grades.api import CourseGradeFactory, clear_prefetched_course_grades, prefetch_course_grades
from lms.djangoapps.grades.rest_api.serializers import GradingPolicySerializer
from lms.djangoapps.grades.rest_api.v1.utils import CourseEnrollmentPagination, GradeViewMixin
from openedx.core.lib.api.authentication import OAuth2AuthenticationAllowInactiveUser
from openedx.core.lib.api.view_utils import PaginatedAPIView, get_course_key, verify_course_exists
from xmodule.modulestore.django import modulestore