From 22edaf7d24d754857cf7c3086cc31a2eeef54660 Mon Sep 17 00:00:00 2001 From: Nimisha Asthagiri Date: Thu, 21 Sep 2017 21:05:00 -0400 Subject: [PATCH] Grades: move out of temporary new folder EDUCATOR-1400 --- common/djangoapps/student/tests/tests.py | 6 ++--- common/djangoapps/student/views.py | 2 +- lms/djangoapps/ccx/views.py | 2 +- .../management/commands/fix_ungraded_certs.py | 2 +- lms/djangoapps/certificates/queue.py | 2 +- lms/djangoapps/certificates/signals.py | 2 +- .../certificates/tests/test_signals.py | 2 +- .../tests/test_submitting_problems.py | 2 +- lms/djangoapps/courseware/tests/test_views.py | 18 ++++++------- lms/djangoapps/courseware/views/index.py | 2 +- lms/djangoapps/courseware/views/views.py | 2 +- .../gating/tests/test_integration.py | 2 +- lms/djangoapps/grades/api/views.py | 2 +- .../grades/{new => }/course_data.py | 2 +- .../grades/{new => }/course_grade.py | 0 .../grades/{new => }/course_grade_factory.py | 6 ++--- lms/djangoapps/grades/new/__init__.py | 0 lms/djangoapps/grades/signals/handlers.py | 15 ++++++----- .../grades/{new => }/subsection_grade.py | 2 +- .../{new => }/subsection_grade_factory.py | 0 lms/djangoapps/grades/tasks.py | 11 ++++---- .../grades/tests/integration/test_access.py | 2 +- .../grades/tests/test_course_data.py | 7 +++--- lms/djangoapps/grades/tests/test_grades.py | 11 ++++---- lms/djangoapps/grades/tests/test_new.py | 25 +++++++++---------- lms/djangoapps/grades/tests/test_tasks.py | 8 +++--- lms/djangoapps/grades/tests/utils.py | 6 ++--- .../instructor/tests/test_enrollment.py | 2 +- .../instructor/views/gradebook_api.py | 2 +- .../instructor_task/tasks_helper/grades.py | 2 +- .../instructor_task/tests/test_integration.py | 2 +- .../tests/test_tasks_helper.py | 6 ++--- lms/djangoapps/lti_provider/tasks.py | 2 +- 33 files changed, 76 insertions(+), 81 deletions(-) rename lms/djangoapps/grades/{new => }/course_data.py (98%) rename lms/djangoapps/grades/{new => }/course_grade.py (100%) rename lms/djangoapps/grades/{new => }/course_grade_factory.py (98%) delete mode 100644 lms/djangoapps/grades/new/__init__.py rename lms/djangoapps/grades/{new => }/subsection_grade.py (99%) rename lms/djangoapps/grades/{new => }/subsection_grade_factory.py (100%) diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index 5af0bb977a..f48b16979f 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -105,7 +105,7 @@ class CourseEndingTest(TestCase): ) cert_status = {'status': 'generating', 'grade': '0.67', 'mode': 'honor'} - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: patch_persisted_grade.return_value = Mock(percent=1.0) self.assertEqual( _cert_info(user, course, cert_status, course_mode), @@ -244,7 +244,7 @@ class CourseEndingTest(TestCase): else: cert_status = {'status': 'generating', 'mode': 'honor'} - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: patch_persisted_grade.return_value = Mock(percent=persisted_grade) self.assertEqual( _cert_info(user, course, cert_status, course_mode), @@ -277,7 +277,7 @@ class CourseEndingTest(TestCase): course_mode = 'honor' cert_status = {'status': 'generating', 'mode': 'honor'} - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: patch_persisted_grade.return_value = None self.assertEqual( _cert_info(user, course, cert_status, course_mode), diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 7404fc4688..634f5ae82f 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -67,7 +67,7 @@ from django_comment_common.models import assign_role from edxmako.shortcuts import render_to_response, render_to_string from eventtracking import tracker from lms.djangoapps.commerce.utils import EcommerceService # pylint: disable=import-error -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification # pylint: disable=import-error # Note that this lives in LMS, so this dependency should be refactored. from notification_prefs.views import enable_notifications diff --git a/lms/djangoapps/ccx/views.py b/lms/djangoapps/ccx/views.py index 80f9f96386..59a956f97c 100644 --- a/lms/djangoapps/ccx/views.py +++ b/lms/djangoapps/ccx/views.py @@ -48,7 +48,7 @@ from lms.djangoapps.ccx.utils import ( parse_date, prep_course_for_grading ) -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.instructor.enrollment import enroll_email, get_email_params from lms.djangoapps.instructor.views.api import _split_input_list from lms.djangoapps.instructor.views.gradebook_api import get_grade_book_page diff --git a/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py b/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py index 81dea83afa..34a017344f 100644 --- a/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py +++ b/lms/djangoapps/certificates/management/commands/fix_ungraded_certs.py @@ -8,7 +8,7 @@ from django.core.management.base import BaseCommand from certificates.models import GeneratedCertificate from courseware import courses -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory log = logging.getLogger(__name__) diff --git a/lms/djangoapps/certificates/queue.py b/lms/djangoapps/certificates/queue.py index c0de5d495d..3d82bc2859 100644 --- a/lms/djangoapps/certificates/queue.py +++ b/lms/djangoapps/certificates/queue.py @@ -21,7 +21,7 @@ from certificates.models import ( certificate_status_for_student ) from course_modes.models import CourseMode -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification from student.models import CourseEnrollment, UserProfile from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/certificates/signals.py b/lms/djangoapps/certificates/signals.py index 7372ef7e81..faa2444b38 100644 --- a/lms/djangoapps/certificates/signals.py +++ b/lms/djangoapps/certificates/signals.py @@ -13,7 +13,7 @@ from certificates.models import ( GeneratedCertificate ) from certificates.tasks import generate_certificate -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification from openedx.core.djangoapps.certificates.api import auto_certificate_generation_enabled from openedx.core.djangoapps.certificates.config import waffle diff --git a/lms/djangoapps/certificates/tests/test_signals.py b/lms/djangoapps/certificates/tests/test_signals.py index 5fba7260a0..41716de797 100644 --- a/lms/djangoapps/certificates/tests/test_signals.py +++ b/lms/djangoapps/certificates/tests/test_signals.py @@ -11,7 +11,7 @@ from certificates.models import ( GeneratedCertificate, CertificateStatuses, ) -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.grades.tests.utils import mock_passing_grade from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification from openedx.core.djangoapps.certificates.config import waffle diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py index db3ab50bf2..0fe41cd0e0 100644 --- a/lms/djangoapps/courseware/tests/test_submitting_problems.py +++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py @@ -28,7 +28,7 @@ from capa.tests.response_xml_factory import ( from course_modes.models import CourseMode from courseware.models import BaseStudentModuleHistory, StudentModule from courseware.tests.helpers import LoginEnrollmentTestCase -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from openedx.core.djangoapps.credit.api import get_credit_requirement_status, set_credit_requirements from openedx.core.djangoapps.credit.models import CreditCourse, CreditProvider from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 74a0e1bdbc..931d20c7ad 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -42,7 +42,7 @@ from django.test.utils import override_settings from lms.djangoapps.commerce.utils import EcommerceService # pylint: disable=import-error from lms.djangoapps.grades.config.waffle import waffle as grades_waffle from lms.djangoapps.grades.config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.grades.tests.utils import mock_get_score from milestones.tests.utils import MilestonesTestCaseMixin from opaque_keys.edx.keys import CourseKey @@ -1399,7 +1399,7 @@ class ProgressPageTests(ProgressPageBaseTests): self.course.save() self.store.update_item(self.course, self.user.id) - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.create') as mock_create: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.create') as mock_create: course_grade = mock_create.return_value course_grade.passed = True course_grade.summary = {'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [], 'grade_breakdown': {}} @@ -1442,7 +1442,7 @@ class ProgressPageTests(ProgressPageBaseTests): # Enable certificate generation for this course certs_api.set_cert_generation_enabled(self.course.id, True) - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.create') as mock_create: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.create') as mock_create: course_grade = mock_create.return_value course_grade.passed = True course_grade.summary = {'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [], 'grade_breakdown': {}} @@ -1504,7 +1504,7 @@ class ProgressPageTests(ProgressPageBaseTests): 'lms.djangoapps.verify_student.models.SoftwareSecurePhotoVerification.user_is_verified' ) as user_verify: user_verify.return_value = user_verified - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.create') as mock_create: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.create') as mock_create: course_grade = mock_create.return_value course_grade.passed = True course_grade.summary = { @@ -1548,7 +1548,7 @@ class ProgressPageTests(ProgressPageBaseTests): self.course.save() self.store.update_item(self.course, self.user.id) - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.create') as mock_create: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.create') as mock_create: course_grade = mock_create.return_value course_grade.passed = True course_grade.summary = { @@ -1568,7 +1568,7 @@ class ProgressPageTests(ProgressPageBaseTests): "http://www.example.com/certificate.pdf", "honor" ) - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.create') as mock_create: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.create') as mock_create: course_grade = mock_create.return_value course_grade.passed = True course_grade.summary = {'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [], 'grade_breakdown': {}} @@ -1586,7 +1586,7 @@ class ProgressPageTests(ProgressPageBaseTests): self.assertTrue(self.client.login(username=user.username, password='test')) CourseEnrollmentFactory(user=user, course_id=self.course.id, mode=CourseMode.AUDIT) - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.create') as mock_create: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.create') as mock_create: course_grade = mock_create.return_value course_grade.passed = True course_grade.summary = {'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [], 'grade_breakdown': {}} @@ -2090,7 +2090,7 @@ class GenerateUserCertTests(ModuleStoreTestCase): status=CertificateStatuses.generating, mode='verified' ) - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.create') as mock_create: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.create') as mock_create: course_grade = mock_create.return_value course_grade.passed = True course_grade.summary = {'grade': 'Pass', 'percent': 0.75} @@ -2111,7 +2111,7 @@ class GenerateUserCertTests(ModuleStoreTestCase): mode='verified' ) - with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.create') as mock_create: + with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.create') as mock_create: course_grade = mock_create.return_value course_grade.passed = True course_grade.summay = {'grade': 'Pass', 'percent': 0.75} diff --git a/lms/djangoapps/courseware/views/index.py b/lms/djangoapps/courseware/views/index.py index fe26f7f977..22a91e59be 100644 --- a/lms/djangoapps/courseware/views/index.py +++ b/lms/djangoapps/courseware/views/index.py @@ -24,7 +24,7 @@ from edxmako.shortcuts import render_to_response, render_to_string from lms.djangoapps.courseware.exceptions import CourseAccessRedirect from lms.djangoapps.experiments.utils import get_experiment_user_metadata_context from lms.djangoapps.gating.api import get_entrance_exam_score_ratio, get_entrance_exam_usage_key -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from openedx.core.djangoapps.crawlers.models import CrawlersConfig from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.monitoring_utils import set_custom_metrics_for_course_key diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 0f2ff76813..16bdb7b21c 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -63,7 +63,7 @@ from lms.djangoapps.ccx.custom_exception import CCXLocatorValidationException from lms.djangoapps.ccx.utils import prep_course_for_grading from lms.djangoapps.courseware.exceptions import CourseAccessRedirect, Redirect from lms.djangoapps.experiments.utils import get_experiment_user_metadata_context -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.instructor.enrollment import uses_shib from lms.djangoapps.instructor.views.api import require_global_staff from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification diff --git a/lms/djangoapps/gating/tests/test_integration.py b/lms/djangoapps/gating/tests/test_integration.py index f4b60dca3e..a572cb25dd 100644 --- a/lms/djangoapps/gating/tests/test_integration.py +++ b/lms/djangoapps/gating/tests/test_integration.py @@ -7,7 +7,7 @@ from milestones.tests.utils import MilestonesTestCaseMixin from nose.plugins.attrib import attr from lms.djangoapps.courseware.access import has_access -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.grades.tests.utils import answer_problem from openedx.core.djangolib.testing.utils import get_mock_request from openedx.core.lib.gating import api as gating_api diff --git a/lms/djangoapps/grades/api/views.py b/lms/djangoapps/grades/api/views.py index 9fcd57b4c3..4fd1f5d7c5 100644 --- a/lms/djangoapps/grades/api/views.py +++ b/lms/djangoapps/grades/api/views.py @@ -15,7 +15,7 @@ from lms.djangoapps.ccx.utils import prep_course_for_grading from lms.djangoapps.courseware import courses from lms.djangoapps.courseware.exceptions import CourseAccessRedirect from lms.djangoapps.grades.api.serializers import GradingPolicySerializer -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes from student.roles import CourseStaffRole diff --git a/lms/djangoapps/grades/new/course_data.py b/lms/djangoapps/grades/course_data.py similarity index 98% rename from lms/djangoapps/grades/new/course_data.py rename to lms/djangoapps/grades/course_data.py index 4ceb86dc2a..e7993b627f 100644 --- a/lms/djangoapps/grades/new/course_data.py +++ b/lms/djangoapps/grades/course_data.py @@ -2,7 +2,7 @@ from lms.djangoapps.course_blocks.api import get_course_blocks from openedx.core.djangoapps.content.block_structure.api import get_block_structure_manager from xmodule.modulestore.django import modulestore -from ..transformer import GradesTransformer +from .transformer import GradesTransformer class CourseData(object): diff --git a/lms/djangoapps/grades/new/course_grade.py b/lms/djangoapps/grades/course_grade.py similarity index 100% rename from lms/djangoapps/grades/new/course_grade.py rename to lms/djangoapps/grades/course_grade.py diff --git a/lms/djangoapps/grades/new/course_grade_factory.py b/lms/djangoapps/grades/course_grade_factory.py similarity index 98% rename from lms/djangoapps/grades/new/course_grade_factory.py rename to lms/djangoapps/grades/course_grade_factory.py index 68ea2bd3d7..aca54a20d6 100644 --- a/lms/djangoapps/grades/new/course_grade_factory.py +++ b/lms/djangoapps/grades/course_grade_factory.py @@ -6,11 +6,11 @@ import dogstats_wrapper as dog_stats_api from openedx.core.djangoapps.signals.signals import COURSE_GRADE_CHANGED, COURSE_GRADE_NOW_PASSED -from ..config import assume_zero_if_absent, should_persist_grades -from ..config.waffle import WRITE_ONLY_IF_ENGAGED, waffle -from ..models import PersistentCourseGrade, VisibleBlocks +from .config import assume_zero_if_absent, should_persist_grades +from .config.waffle import WRITE_ONLY_IF_ENGAGED, waffle from .course_data import CourseData from .course_grade import CourseGrade, ZeroCourseGrade +from .models import PersistentCourseGrade, VisibleBlocks log = getLogger(__name__) diff --git a/lms/djangoapps/grades/new/__init__.py b/lms/djangoapps/grades/new/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lms/djangoapps/grades/signals/handlers.py b/lms/djangoapps/grades/signals/handlers.py index 7ffefa44e2..b090aa58be 100644 --- a/lms/djangoapps/grades/signals/handlers.py +++ b/lms/djangoapps/grades/signals/handlers.py @@ -4,11 +4,9 @@ Grades related signals. from contextlib import contextmanager from logging import getLogger +from courseware.model_data import get_score, set_score from crum import get_current_user from django.dispatch import receiver -from xblock.scorable import ScorableXBlockMixin, Score - -from courseware.model_data import get_score, set_score from eventtracking import tracker from lms.djangoapps.instructor_task.tasks_helper.module_state import GRADES_OVERRIDE_EVENT_TYPE from openedx.core.djangoapps.course_groups.signals.signals import COHORT_MEMBERSHIP_UPDATED @@ -23,12 +21,8 @@ from track.event_transaction_utils import ( set_event_transaction_type ) from util.date_utils import to_timestamp +from xblock.scorable import ScorableXBlockMixin, Score -from ..config.waffle import waffle, WRITE_ONLY_IF_ENGAGED -from ..constants import ScoreDatabaseTableEnum -from ..new.course_grade_factory import CourseGradeFactory -from ..scores import weighted_score -from ..tasks import RECALCULATE_GRADE_DELAY, recalculate_subsection_grade_v3 from .signals import ( PROBLEM_RAW_SCORE_CHANGED, PROBLEM_WEIGHTED_SCORE_CHANGED, @@ -36,6 +30,11 @@ from .signals import ( SUBSECTION_SCORE_CHANGED, SUBSECTION_OVERRIDE_CHANGED, ) +from ..config.waffle import waffle, WRITE_ONLY_IF_ENGAGED +from ..constants import ScoreDatabaseTableEnum +from ..course_grade_factory import CourseGradeFactory +from ..scores import weighted_score +from ..tasks import RECALCULATE_GRADE_DELAY, recalculate_subsection_grade_v3 log = getLogger(__name__) diff --git a/lms/djangoapps/grades/new/subsection_grade.py b/lms/djangoapps/grades/subsection_grade.py similarity index 99% rename from lms/djangoapps/grades/new/subsection_grade.py rename to lms/djangoapps/grades/subsection_grade.py index e30424a111..5b06498d9c 100644 --- a/lms/djangoapps/grades/new/subsection_grade.py +++ b/lms/djangoapps/grades/subsection_grade.py @@ -11,7 +11,7 @@ from lms.djangoapps.grades.scores import get_score, possibly_scored from xmodule import block_metadata_utils, graders from xmodule.graders import AggregatedScore, ShowCorrectness -from ..config.waffle import WRITE_ONLY_IF_ENGAGED, waffle +from .config.waffle import WRITE_ONLY_IF_ENGAGED, waffle log = getLogger(__name__) diff --git a/lms/djangoapps/grades/new/subsection_grade_factory.py b/lms/djangoapps/grades/subsection_grade_factory.py similarity index 100% rename from lms/djangoapps/grades/new/subsection_grade_factory.py rename to lms/djangoapps/grades/subsection_grade_factory.py diff --git a/lms/djangoapps/grades/tasks.py b/lms/djangoapps/grades/tasks.py index 96ede14a84..ac33a77d67 100644 --- a/lms/djangoapps/grades/tasks.py +++ b/lms/djangoapps/grades/tasks.py @@ -8,17 +8,16 @@ import six from celery import task from celery_utils.logged_task import LoggedTask from celery_utils.persist_on_failure import PersistOnFailureTask +from courseware.model_data import get_score from django.conf import settings from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.db.utils import DatabaseError -from opaque_keys.edx.keys import CourseKey, UsageKey -from opaque_keys.edx.locator import CourseLocator - -from courseware.model_data import get_score from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.courseware import courses from lms.djangoapps.grades.config.models import ComputeGradesSetting +from opaque_keys.edx.keys import CourseKey, UsageKey +from opaque_keys.edx.locator import CourseLocator from openedx.core.djangoapps.monitoring_utils import set_custom_metric, set_custom_metrics_for_course_key from student.models import CourseEnrollment from submissions import api as sub_api @@ -28,11 +27,11 @@ from xmodule.modulestore.django import modulestore from .config.waffle import ESTIMATE_FIRST_ATTEMPTED, DISABLE_REGRADE_ON_POLICY_CHANGE, waffle from .constants import ScoreDatabaseTableEnum +from .course_grade_factory import CourseGradeFactory from .exceptions import DatabaseNotReadyError -from .new.course_grade_factory import CourseGradeFactory -from .new.subsection_grade_factory import SubsectionGradeFactory from .services import GradesService from .signals.signals import SUBSECTION_SCORE_CHANGED +from .subsection_grade_factory import SubsectionGradeFactory from .transformer import GradesTransformer log = getLogger(__name__) diff --git a/lms/djangoapps/grades/tests/integration/test_access.py b/lms/djangoapps/grades/tests/integration/test_access.py index 99f95b4675..a1271afcf8 100644 --- a/lms/djangoapps/grades/tests/integration/test_access.py +++ b/lms/djangoapps/grades/tests/integration/test_access.py @@ -14,7 +14,7 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from ...new.subsection_grade_factory import SubsectionGradeFactory +from ...subsection_grade_factory import SubsectionGradeFactory class GradesAccessIntegrationTest(ProblemSubmissionTestMixin, SharedModuleStoreTestCase): diff --git a/lms/djangoapps/grades/tests/test_course_data.py b/lms/djangoapps/grades/tests/test_course_data.py index 05ead22b3e..d9a4d35006 100644 --- a/lms/djangoapps/grades/tests/test_course_data.py +++ b/lms/djangoapps/grades/tests/test_course_data.py @@ -1,16 +1,15 @@ """ Tests for CourseData utility class. """ -from mock import patch - from lms.djangoapps.course_blocks.api import get_course_blocks +from mock import patch from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache from student.tests.factories import UserFactory from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from ..new.course_data import CourseData +from ..course_data import CourseData class CourseDataTest(ModuleStoreTestCase): @@ -37,7 +36,7 @@ class CourseDataTest(ModuleStoreTestCase): 'location': self.course.location, } - @patch('lms.djangoapps.grades.new.course_data.get_course_blocks') + @patch('lms.djangoapps.grades.course_data.get_course_blocks') def test_fill_course_data(self, mock_get_blocks): """ Tests to ensure that course data is fully filled with just a single input. diff --git a/lms/djangoapps/grades/tests/test_grades.py b/lms/djangoapps/grades/tests/test_grades.py index 371062adff..2b6769a98e 100644 --- a/lms/djangoapps/grades/tests/test_grades.py +++ b/lms/djangoapps/grades/tests/test_grades.py @@ -6,11 +6,10 @@ import datetime import itertools import ddt -from mock import patch -from nose.plugins.attrib import attr - from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory from lms.djangoapps.course_blocks.api import get_course_blocks +from mock import patch +from nose.plugins.attrib import attr from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory from openedx.core.djangolib.testing.utils import get_mock_request from student.models import CourseEnrollment @@ -20,8 +19,8 @@ from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory -from ..new.course_grade_factory import CourseGradeFactory -from ..new.subsection_grade_factory import SubsectionGradeFactory +from ..course_grade_factory import CourseGradeFactory +from ..subsection_grade_factory import SubsectionGradeFactory from .utils import answer_problem @@ -80,7 +79,7 @@ class TestGradeIteration(SharedModuleStoreTestCase): self.assertIsNone(course_grade.letter_grade) self.assertEqual(course_grade.percent, 0.0) - @patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.create') + @patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.create') def test_grading_exception(self, mock_course_grade): """Test that we correctly capture exception messages that bubble up from grading. Note that we only see errors at this level if the grading diff --git a/lms/djangoapps/grades/tests/test_new.py b/lms/djangoapps/grades/tests/test_new.py index 425f012110..c2b87a6273 100644 --- a/lms/djangoapps/grades/tests/test_new.py +++ b/lms/djangoapps/grades/tests/test_new.py @@ -8,14 +8,13 @@ import itertools import ddt import pytz -from django.conf import settings -from mock import patch - from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory from courseware.access import has_access from courseware.tests.test_submitting_problems import ProblemSubmissionTestMixin +from django.conf import settings from lms.djangoapps.course_blocks.api import get_course_blocks from lms.djangoapps.grades.config.tests.utils import persistent_grades_feature_flags +from mock import patch from openedx.core.djangolib.testing.utils import get_mock_request from student.models import CourseEnrollment from student.tests.factories import UserFactory @@ -25,12 +24,12 @@ from xmodule.modulestore.tests.utils import TEST_DATA_DIR from xmodule.modulestore.xml_importer import import_course_from_xml from ..config.waffle import ASSUME_ZERO_GRADE_IF_ABSENT, WRITE_ONLY_IF_ENGAGED, waffle +from ..course_data import CourseData +from ..course_grade import CourseGrade, ZeroCourseGrade +from ..course_grade_factory import CourseGradeFactory from ..models import PersistentSubsectionGrade -from ..new.course_data import CourseData -from ..new.course_grade import CourseGrade, ZeroCourseGrade -from ..new.course_grade_factory import CourseGradeFactory -from ..new.subsection_grade import SubsectionGrade, ZeroSubsectionGrade -from ..new.subsection_grade_factory import SubsectionGradeFactory +from ..subsection_grade import SubsectionGrade, ZeroSubsectionGrade +from ..subsection_grade_factory import SubsectionGradeFactory from .utils import mock_get_score, mock_get_submissions_score @@ -248,7 +247,7 @@ class TestCourseGradeFactory(GradeTestBase): @ddt.data(True, False) def test_iter_force_update(self, force_update): - base_string = 'lms.djangoapps.grades.new.subsection_grade_factory.SubsectionGradeFactory.{}' + base_string = 'lms.djangoapps.grades.subsection_grade_factory.SubsectionGradeFactory.{}' desired_method_name = base_string.format('update' if force_update else 'create') undesired_method_name = base_string.format('create' if force_update else 'update') with patch(desired_method_name) as desired_call: @@ -295,11 +294,11 @@ class TestSubsectionGradeFactory(ProblemSubmissionTestMixin, GradeTestBase): created, saved, then fetched on re-request. """ with patch( - 'lms.djangoapps.grades.new.subsection_grade.PersistentSubsectionGrade.create_grade', + 'lms.djangoapps.grades.subsection_grade.PersistentSubsectionGrade.create_grade', wraps=PersistentSubsectionGrade.create_grade ) as mock_create_grade: with patch( - 'lms.djangoapps.grades.new.subsection_grade_factory.SubsectionGradeFactory._get_bulk_cached_grade', + 'lms.djangoapps.grades.subsection_grade_factory.SubsectionGradeFactory._get_bulk_cached_grade', wraps=self.subsection_grade_factory._get_bulk_cached_grade ) as mock_get_bulk_cached_grade: with self.assertNumQueries(14): @@ -412,7 +411,7 @@ class ZeroGradeTest(GradeTestBase): Creates a zero course grade and ensures that null scores aren't included in the section problem scores. """ with waffle().override(ASSUME_ZERO_GRADE_IF_ABSENT, active=assume_zero_enabled): - with patch('lms.djangoapps.grades.new.subsection_grade.get_score', return_value=None): + with patch('lms.djangoapps.grades.subsection_grade.get_score', return_value=None): course_data = CourseData(self.request.user, structure=self.course_structure) chapter_grades = ZeroCourseGrade(self.request.user, course_data).chapter_grades for chapter in chapter_grades: @@ -744,7 +743,7 @@ class TestCourseGradeLogging(ProblemSubmissionTestMixin, SharedModuleStoreTestCa course_id=self.course.id, enabled_for_course=True ): - with patch('lms.djangoapps.grades.new.course_grade_factory.log') as log_mock: + with patch('lms.djangoapps.grades.course_grade_factory.log') as log_mock: # read, but not persisted self._create_course_grade_and_check_logging(grade_factory.create, log_mock.info, u'Update') diff --git a/lms/djangoapps/grades/tests/test_tasks.py b/lms/djangoapps/grades/tests/test_tasks.py index 005fba01cc..c459d6c7d6 100644 --- a/lms/djangoapps/grades/tests/test_tasks.py +++ b/lms/djangoapps/grades/tests/test_tasks.py @@ -253,7 +253,7 @@ class RecalculateSubsectionGradeTest(HasCourseWithProblemsMixin, ModuleStoreTest self.assertGreater(len(PersistentSubsectionGrade.bulk_read_grades(self.user.id, self.course.id)), 0) @patch('lms.djangoapps.grades.signals.signals.SUBSECTION_SCORE_CHANGED.send') - @patch('lms.djangoapps.grades.new.subsection_grade_factory.SubsectionGradeFactory.update') + @patch('lms.djangoapps.grades.subsection_grade_factory.SubsectionGradeFactory.update') def test_retry_first_time_only(self, mock_update, mock_course_signal): """ Ensures that a task retry completes after a one-time failure. @@ -264,7 +264,7 @@ class RecalculateSubsectionGradeTest(HasCourseWithProblemsMixin, ModuleStoreTest self.assertEquals(mock_course_signal.call_count, 1) @patch('lms.djangoapps.grades.tasks.recalculate_subsection_grade_v3.retry') - @patch('lms.djangoapps.grades.new.subsection_grade_factory.SubsectionGradeFactory.update') + @patch('lms.djangoapps.grades.subsection_grade_factory.SubsectionGradeFactory.update') def test_retry_on_integrity_error(self, mock_update, mock_retry): """ Ensures that tasks will be retried if IntegrityErrors are encountered. @@ -347,7 +347,7 @@ class RecalculateSubsectionGradeTest(HasCourseWithProblemsMixin, ModuleStoreTest @patch('lms.djangoapps.grades.tasks.log') @patch('lms.djangoapps.grades.tasks.recalculate_subsection_grade_v3.retry') - @patch('lms.djangoapps.grades.new.subsection_grade_factory.SubsectionGradeFactory.update') + @patch('lms.djangoapps.grades.subsection_grade_factory.SubsectionGradeFactory.update') def test_log_unknown_error(self, mock_update, mock_retry, mock_log): """ Ensures that unknown errors are logged before a retry. @@ -360,7 +360,7 @@ class RecalculateSubsectionGradeTest(HasCourseWithProblemsMixin, ModuleStoreTest @patch('lms.djangoapps.grades.tasks.log') @patch('lms.djangoapps.grades.tasks.recalculate_subsection_grade_v3.retry') - @patch('lms.djangoapps.grades.new.subsection_grade_factory.SubsectionGradeFactory.update') + @patch('lms.djangoapps.grades.subsection_grade_factory.SubsectionGradeFactory.update') def test_no_log_known_error(self, mock_update, mock_retry, mock_log): """ Ensures that known errors are not logged before a retry. diff --git a/lms/djangoapps/grades/tests/utils.py b/lms/djangoapps/grades/tests/utils.py index e348ce9a22..990f306e27 100644 --- a/lms/djangoapps/grades/tests/utils.py +++ b/lms/djangoapps/grades/tests/utils.py @@ -16,8 +16,8 @@ def mock_passing_grade(grade_pass='Pass', percent=0.75, ): """ Mock the grading function to always return a passing grade. """ - with patch('lms.djangoapps.grades.new.course_grade.CourseGrade._compute_letter_grade') as mock_letter_grade: - with patch('lms.djangoapps.grades.new.course_grade.CourseGrade._compute_percent') as mock_percent_grade: + with patch('lms.djangoapps.grades.course_grade.CourseGrade._compute_letter_grade') as mock_letter_grade: + with patch('lms.djangoapps.grades.course_grade.CourseGrade._compute_percent') as mock_percent_grade: mock_letter_grade.return_value = grade_pass mock_percent_grade.return_value = percent yield @@ -28,7 +28,7 @@ def mock_get_score(earned=0, possible=1, first_attempted=datetime(2000, 1, 1, 0, """ Mocks the get_score function to return a valid grade. """ - with patch('lms.djangoapps.grades.new.subsection_grade.get_score') as mock_score: + with patch('lms.djangoapps.grades.subsection_grade.get_score') as mock_score: mock_score.return_value = ProblemScore( raw_earned=earned, raw_possible=possible, diff --git a/lms/djangoapps/instructor/tests/test_enrollment.py b/lms/djangoapps/instructor/tests/test_enrollment.py index 3593ad5d38..14f63a6027 100644 --- a/lms/djangoapps/instructor/tests/test_enrollment.py +++ b/lms/djangoapps/instructor/tests/test_enrollment.py @@ -17,7 +17,7 @@ from opaque_keys.edx.locator import CourseLocator from capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory from courseware.models import StudentModule -from grades.new.subsection_grade_factory import SubsectionGradeFactory +from grades.subsection_grade_factory import SubsectionGradeFactory from grades.tests.utils import answer_problem from lms.djangoapps.ccx.tests.factories import CcxFactory from lms.djangoapps.course_blocks.api import get_course_blocks diff --git a/lms/djangoapps/instructor/views/gradebook_api.py b/lms/djangoapps/instructor/views/gradebook_api.py index 5bce65dbe2..46de7caded 100644 --- a/lms/djangoapps/instructor/views/gradebook_api.py +++ b/lms/djangoapps/instructor/views/gradebook_api.py @@ -12,7 +12,7 @@ from opaque_keys.edx.keys import CourseKey from courseware.courses import get_course_with_access from edxmako.shortcuts import render_to_response -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.instructor.views.api import require_level from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/instructor_task/tasks_helper/grades.py b/lms/djangoapps/instructor_task/tasks_helper/grades.py index 650d4a99b8..da013c2830 100644 --- a/lms/djangoapps/instructor_task/tasks_helper/grades.py +++ b/lms/djangoapps/instructor_task/tasks_helper/grades.py @@ -17,7 +17,7 @@ from instructor_analytics.basic import list_problem_responses from instructor_analytics.csvs import format_dictlist from lms.djangoapps.grades.context import grading_context, grading_context_for_course from lms.djangoapps.grades.models import PersistentCourseGrade -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.teams.models import CourseTeamMembership from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache diff --git a/lms/djangoapps/instructor_task/tests/test_integration.py b/lms/djangoapps/instructor_task/tests/test_integration.py index a82537c350..419f764eb4 100644 --- a/lms/djangoapps/instructor_task/tests/test_integration.py +++ b/lms/djangoapps/instructor_task/tests/test_integration.py @@ -20,7 +20,7 @@ from nose.plugins.attrib import attr from capa.responsetypes import StudentInputError from capa.tests.response_xml_factory import CodeResponseXMLFactory, CustomResponseXMLFactory from courseware.model_data import StudentModule -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.instructor_task.api import ( submit_delete_problem_state_for_all_students, submit_rescore_problem_for_all_students, diff --git a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py index e467500960..bb64881cc8 100644 --- a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py @@ -135,7 +135,7 @@ class TestInstructorGradeReport(InstructorGradeReportTestCase): self.assertDictContainsSubset({'attempted': num_students, 'succeeded': num_students, 'failed': 0}, result) @patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task') - @patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.iter') + @patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.iter') def test_grading_failure(self, mock_grades_iter, _mock_current_task): """ Test that any grading errors are properly reported in the @@ -312,7 +312,7 @@ class TestInstructorGradeReport(InstructorGradeReportTestCase): ) @patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task') - @patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.iter') + @patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.iter') def test_unicode_in_csv_header(self, mock_grades_iter, _mock_current_task): """ Tests that CSV grade report works if unicode in headers. @@ -762,7 +762,7 @@ class TestProblemGradeReport(TestReportMixin, InstructorTaskModuleTestCase): ]) @patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task') - @patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.iter') + @patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.iter') @ddt.data(u'Cannot grade student', '') def test_grading_failure(self, error_message, mock_grades_iter, _mock_current_task): """ diff --git a/lms/djangoapps/lti_provider/tasks.py b/lms/djangoapps/lti_provider/tasks.py index 4b57dc7fc0..837145d367 100644 --- a/lms/djangoapps/lti_provider/tasks.py +++ b/lms/djangoapps/lti_provider/tasks.py @@ -11,7 +11,7 @@ from opaque_keys.edx.keys import CourseKey import lti_provider.outcomes as outcomes from lms import CELERY_APP -from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory +from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.grades.signals.signals import PROBLEM_WEIGHTED_SCORE_CHANGED from lti_provider.models import GradedAssignment from lti_provider.views import parse_course_and_usage_keys