fix: revert Add Learner pathway progress update signal (#30598)

This commit is contained in:
Zaman Afzal
2022-06-16 01:59:40 +05:00
committed by GitHub
parent b50f3ec6cc
commit ec36d3a949
23 changed files with 87 additions and 336 deletions

View File

@@ -56,24 +56,9 @@ class AllowlistGeneratedCertificatesTest(ModuleStoreTestCase):
"""
Tests for allowlisted student auto-certificate generation
"""
def setup_patch(self, function_name, return_value):
"""
Patch a function with a given return value, and return the mock
"""
magic_mock = mock.MagicMock(return_value=return_value)
new_patch = mock.patch(function_name, new=magic_mock)
new_patch.start()
self.addCleanup(new_patch.stop)
return magic_mock
def setUp(self):
super().setUp()
self.user = UserFactory.create()
self.mock_pathways_with_course = self.setup_patch(
'learner_pathway_progress.signals.get_learner_pathways_associated_with_course',
None,
)
# Instructor paced course
self.ip_course = CourseFactory.create(self_paced=False)
CourseEnrollmentFactory(
@@ -118,30 +103,11 @@ class PassingGradeCertsTest(ModuleStoreTestCase):
"""
Tests for certificate generation task firing on passing grade receipt
"""
def setup_patch(self, function_name, return_value):
"""
Patch a function with a given return value, and return the mock
"""
magic_mock = mock.MagicMock(return_value=return_value)
new_patch = mock.patch(function_name, new=magic_mock)
new_patch.start()
self.addCleanup(new_patch.stop)
return magic_mock
def setUp(self):
super().setUp()
self.course = CourseFactory.create(
self_paced=True,
)
self.mock_pathways_with_course = self.setup_patch(
'learner_pathway_progress.signals.get_learner_pathways_associated_with_course',
None,
)
self.signal_mock_course_passed_pathway_progress = self.setup_patch(
'learner_pathway_progress.signals.update_learner_pathway_progress',
None,
)
self.course_key = self.course.id
self.user = UserFactory.create()
self.enrollment = CourseEnrollmentFactory(
@@ -253,27 +219,12 @@ class FailingGradeCertsTest(ModuleStoreTestCase):
and that the signal has no effect on the cert status if the cert has a non-passing
status
"""
def setup_patch(self, function_name, return_value):
"""
Patch a function with a given return value, and return the mock
"""
magic_mock = mock.MagicMock(return_value=return_value)
new_patch = mock.patch(function_name, new=magic_mock)
new_patch.start()
self.addCleanup(new_patch.stop)
return magic_mock
def setUp(self):
super().setUp()
self.course = CourseFactory.create(
self_paced=True,
)
self.user = UserFactory.create()
self.mock_pathways_with_course = self.setup_patch(
'learner_pathway_progress.signals.get_learner_pathways_associated_with_course',
None,
)
self.enrollment = CourseEnrollmentFactory(
user=self.user,
course_id=self.course.id,
@@ -349,29 +300,10 @@ class LearnerIdVerificationTest(ModuleStoreTestCase):
"""
Tests for certificate generation task firing on learner id verification
"""
def setup_patch(self, function_name, return_value):
"""
Patch a function with a given return value, and return the mock
"""
magic_mock = mock.MagicMock(return_value=return_value)
new_patch = mock.patch(function_name, new=magic_mock)
new_patch.start()
self.addCleanup(new_patch.stop)
return magic_mock
def setUp(self):
super().setUp()
self.course_one = CourseFactory.create(self_paced=True)
self.user_one = UserFactory.create()
self.mock_pathways_with_course = self.setup_patch(
'learner_pathway_progress.signals.get_learner_pathways_associated_with_course',
None,
)
self.signal_mock_course_passed_pathway_progress = self.setup_patch(
'learner_pathway_progress.signals.update_learner_pathway_progress',
None,
)
self.enrollment_one = CourseEnrollmentFactory(
user=self.user_one,
course_id=self.course_one.id,
@@ -450,31 +382,12 @@ class EnrollmentModeChangeCertsTest(ModuleStoreTestCase):
"""
Tests for certificate generation task firing when the user's enrollment mode changes
"""
def setup_patch(self, function_name, return_value):
"""
Patch a function with a given return value, and return the mock
"""
magic_mock = mock.MagicMock(return_value=return_value)
new_patch = mock.patch(function_name, new=magic_mock)
new_patch.start()
self.addCleanup(new_patch.stop)
return magic_mock
def setUp(self):
super().setUp()
self.user = UserFactory.create()
self.verified_course = CourseFactory.create(
self_paced=True,
)
self.mock_update_pathway_progress = self.setup_patch(
'learner_pathway_progress.signals.update_learner_pathway_progress',
None,
)
self.signal_mock_course_passed_pathway_progress = self.setup_patch(
'learner_pathway_progress.signals.listen_for_course_grade_upgrade_in_learner_pathway',
None,
)
self.verified_course_key = self.verified_course.id # pylint: disable=no-member
self.verified_enrollment = CourseEnrollmentFactory(
user=self.user,

View File

@@ -37,31 +37,24 @@ class TestEnterpriseCourseEnrollmentCreateOldOrder(TestCase):
"""
Creates `count` test enrollments plus 1 invalid and 1 Audit enrollment
"""
with patch(
'learner_pathway_progress.signals.get_learner_pathways_associated_with_course',
return_value=None
):
for _ in range(count):
user = UserFactory()
course_enrollment = CourseEnrollmentFactory(mode=CourseMode.VERIFIED, user=user)
course = course_enrollment.course
enterprise_customer_user = EnterpriseCustomerUserFactory(user_id=user.id)
EnterpriseCourseEnrollmentFactory(
enterprise_customer_user=enterprise_customer_user,
course_id=course.id
)
# creating audit enrollment
for _ in range(count):
user = UserFactory()
course_enrollment = CourseEnrollmentFactory(mode=CourseMode.AUDIT, user=user)
course_enrollment = CourseEnrollmentFactory(mode=CourseMode.VERIFIED, user=user)
course = course_enrollment.course
enterprise_customer_user = EnterpriseCustomerUserFactory(user_id=user.id)
EnterpriseCourseEnrollmentFactory(enterprise_customer_user=enterprise_customer_user, course_id=course.id)
# creating invalid enrollment (with no CourseEnrollment)
user = UserFactory()
enterprise_customer_user = EnterpriseCustomerUserFactory(user_id=user.id)
EnterpriseCourseEnrollmentFactory(enterprise_customer_user=enterprise_customer_user, course_id=course.id)
# creating audit enrollment
user = UserFactory()
course_enrollment = CourseEnrollmentFactory(mode=CourseMode.AUDIT, user=user)
course = course_enrollment.course
enterprise_customer_user = EnterpriseCustomerUserFactory(user_id=user.id)
EnterpriseCourseEnrollmentFactory(enterprise_customer_user=enterprise_customer_user, course_id=course.id)
# creating invalid enrollment (with no CourseEnrollment)
user = UserFactory()
enterprise_customer_user = EnterpriseCustomerUserFactory(user_id=user.id)
EnterpriseCourseEnrollmentFactory(enterprise_customer_user=enterprise_customer_user, course_id=course.id)
@patch('lms.djangoapps.commerce.management.commands.create_orders_for_old_enterprise_course_enrollment'
'.Command._create_manual_enrollment_orders')

View File

@@ -9,7 +9,7 @@ import json
import os
from datetime import datetime
from textwrap import dedent
from unittest.mock import patch, MagicMock
from unittest.mock import patch
import ddt
import pytz
@@ -345,27 +345,6 @@ class TestCourseGrader(TestSubmittingProblems):
"""
Suite of tests for the course grader.
"""
def setup_patch(self, function_name, return_value):
"""
Patch a function with a given return value, and return the mock
"""
magic_mock = MagicMock(return_value=return_value)
new_patch = patch(function_name, new=magic_mock)
new_patch.start()
self.addCleanup(new_patch.stop)
return magic_mock
def setUp(self):
super().setUp()
self.mock_pathways_with_course = self.setup_patch(
'learner_pathway_progress.signals.get_learner_pathways_associated_with_course',
None,
)
self.signal_mock_course_passed_pathway_progress = self.setup_patch(
'learner_pathway_progress.signals.update_learner_pathway_progress',
None,
)
# Tell Django to clean out all databases, not just default
databases = set(connections)

View File

@@ -9,11 +9,6 @@ from openedx.core.djangoapps.signals.signals import (
COURSE_GRADE_NOW_FAILED,
COURSE_GRADE_NOW_PASSED
)
from lms.djangoapps.grades.signals.signals import (
COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY,
)
from .config import assume_zero_if_absent, should_persist_grades
from .course_data import CourseData
from .course_grade import CourseGrade, ZeroCourseGrade
@@ -175,7 +170,6 @@ class CourseGradeFactory:
COURSE_GRADE_CHANGED signal to listeners and
COURSE_GRADE_NOW_PASSED if learner has passed course or
COURSE_GRADE_NOW_FAILED if learner is now failing course
COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY if learner has passed course
"""
should_persist = should_persist_grades(course_data.course_key)
if should_persist and force_update_subsections:
@@ -216,11 +210,6 @@ class CourseGradeFactory:
user=user,
course_id=course_data.course_key,
)
COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send(
sender=CourseGradeFactory,
user_id=user.id,
course_id=course_data.course_key,
)
else:
COURSE_GRADE_NOW_FAILED.send(
sender=CourseGradeFactory,

View File

@@ -27,11 +27,7 @@ from simple_history.models import HistoricalRecords
from lms.djangoapps.courseware.fields import UnsignedBigIntAutoField
from lms.djangoapps.grades import events # lint-amnesty, pylint: disable=unused-import
from openedx.core.lib.cache_utils import get_cache
from lms.djangoapps.grades.signals.signals import (
COURSE_GRADE_PASSED_FIRST_TIME,
COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY
)
from lms.djangoapps.grades.signals.signals import COURSE_GRADE_PASSED_FIRST_TIME
log = logging.getLogger(__name__)
@@ -654,11 +650,6 @@ class PersistentCourseGrade(TimeStampedModel):
course_id=course_id,
user_id=user_id
)
COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send(
sender=None,
user_id=user_id,
course_id=course_id,
)
grade.passed_timestamp = now()
grade.save()

View File

@@ -111,4 +111,3 @@ SUBSECTION_OVERRIDE_CHANGED = Signal()
# 'user_id', # User object id
# ]
COURSE_GRADE_PASSED_FIRST_TIME = Signal()
COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY = Signal()

View File

@@ -13,7 +13,6 @@ from common.djangoapps.student.tests.factories import UserFactory
from lms.djangoapps.certificates.config import AUTO_CERTIFICATE_GENERATION
from lms.djangoapps.courseware.access import has_access
from lms.djangoapps.grades.config.tests.utils import persistent_grades_feature_flags
from lms.djangoapps.grades.signals.signals import COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY
from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory
from openedx.core.djangoapps.signals.signals import COURSE_GRADE_NOW_PASSED
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
@@ -96,25 +95,16 @@ class TestCourseGradeFactory(GradeTestBase):
course_id=self.course.id,
enabled_for_course=False
):
with patch(
'lms.djangoapps.grades.signals.signals.COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send',
return_value=None
) as mock_course_passed_pathway:
with override_waffle_switch(AUTO_CERTIFICATE_GENERATION, active=True), mock_get_score(2, 2):
COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.connect(handler)
COURSE_GRADE_NOW_PASSED.connect(handler)
try:
CourseGradeFactory().update(self.request.user, self.course)
except RecursionError:
pytest.fail("The COURSE_GRADE_NOW_PASSED signal fired recursively.")
with override_waffle_switch(AUTO_CERTIFICATE_GENERATION, active=True), mock_get_score(2, 2):
COURSE_GRADE_NOW_PASSED.connect(handler)
try:
CourseGradeFactory().update(self.request.user, self.course)
except RecursionError:
pytest.fail("The COURSE_GRADE_NOW_PASSED signal fired recursively.")
mock_course_passed_pathway.assert_called_once()
self.mock_process_signal.assert_called_once()
COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.disconnect(handler)
COURSE_GRADE_NOW_PASSED.disconnect(handler)
@patch('lms.djangoapps.grades.signals.signals.COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send',
Mock(return_value=None))
def test_read_and_update(self):
grade_factory = CourseGradeFactory()
@@ -180,8 +170,6 @@ class TestCourseGradeFactory(GradeTestBase):
else:
assert course_grade is None
@patch('lms.djangoapps.grades.signals.signals.COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send',
Mock(return_value=None))
def test_read_optimization(self):
grade_factory = CourseGradeFactory()
with patch('lms.djangoapps.grades.course_data.get_course_blocks') as mocked_course_blocks:
@@ -200,8 +188,6 @@ class TestCourseGradeFactory(GradeTestBase):
assert not mocked_course_blocks.called
# no user-specific transformer calculation
@patch('lms.djangoapps.grades.signals.signals.COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send',
Mock(return_value=None))
def test_subsection_grade(self):
grade_factory = CourseGradeFactory()
with mock_get_score(1, 2):

View File

@@ -8,7 +8,7 @@ from base64 import b64encode
from collections import OrderedDict
from datetime import datetime
from hashlib import sha1
from unittest.mock import patch, MagicMock
from unittest.mock import patch
import ddt
import pytest
@@ -373,20 +373,6 @@ class PersistentCourseGradesTest(GradesModelTestCase):
"letter_grade": "Great job",
"passed": True,
}
self.signal_mock_pathway_progress = self.setup_patch(
'lms.djangoapps.grades.signals.signals.COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send',
None,
)
def setup_patch(self, function_name, return_value):
"""
Patch a function with a given return value, and return the mock
"""
mock = MagicMock(return_value=return_value)
new_patch = patch(function_name, new=mock)
new_patch.start()
self.addCleanup(new_patch.stop)
return mock
def test_update(self):
created_grade = PersistentCourseGrade.update_or_create(**self.params)
@@ -439,14 +425,12 @@ class PersistentCourseGradesTest(GradesModelTestCase):
assert grade.letter_grade == ''
assert grade.passed_timestamp == passed_timestamp
@patch('lms.djangoapps.grades.signals.signals.COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send')
@patch('lms.djangoapps.grades.signals.signals.COURSE_GRADE_PASSED_FIRST_TIME.send')
def test_passed_timestamp_is_now(self, mock, mock_grade_update_in_learner_pathway):
def test_passed_timestamp_is_now(self, mock):
with freeze_time(now()):
grade = PersistentCourseGrade.update_or_create(**self.params)
assert now() == grade.passed_timestamp
self.assertEqual(mock.call_count, 1)
self.assertEqual(mock_grade_update_in_learner_pathway.call_count, 1)
def test_create_and_read_grade(self):
created_grade = PersistentCourseGrade.update_or_create(**self.params)

View File

@@ -285,10 +285,6 @@ class CourseEventsSignalsTest(ModuleStoreTestCase):
Configure mocks for all the dependencies of the render method
"""
super().setUp()
self.signal_mock_pathway_progress = self.setup_patch(
'lms.djangoapps.grades.signals.signals.COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send',
None,
)
self.user_mock = MagicMock()
self.user_mock.id = 42
self.get_user_mock = self.setup_patch(

View File

@@ -1,8 +1,6 @@
"""
Tests of the instructor dashboard spoc gradebook
"""
from unittest.mock import patch, MagicMock
from django.urls import reverse
from capa.tests.response_xml_factory import StringResponseXMLFactory
@@ -23,16 +21,6 @@ class TestGradebook(SharedModuleStoreTestCase):
"""
grading_policy = None
def setup_patch(self, function_name, return_value):
"""
Patch a function with a given return value, and return the mock
"""
mock = MagicMock(return_value=return_value)
new_patch = patch(function_name, new=mock)
new_patch.start()
self.addCleanup(new_patch.stop)
return mock
@classmethod
def setUpClass(cls):
super().setUpClass()
@@ -70,10 +58,6 @@ class TestGradebook(SharedModuleStoreTestCase):
instructor = AdminFactory.create()
self.client.login(username=instructor.username, password='test')
self.users = [UserFactory.create() for _ in range(USER_COUNT)]
self.signal_mock_pathway_progress = self.setup_patch(
'lms.djangoapps.grades.signals.signals.COURSE_GRADE_PASSED_UPDATE_IN_LEARNER_PATHWAY.send',
None,
)
for user in self.users:
CourseEnrollmentFactory.create(user=user, course_id=self.course.id)

View File

@@ -338,40 +338,36 @@ class TestInstructorGradeReport(InstructorGradeReportTestCase):
audit_user = CourseEnrollment.enroll(UserFactory.create(), course.id)
self._verify_cell_data_for_user(audit_user.username, course.id, 'Certificate Eligible', 'N', num_rows=1)
grading_policy_hash = GradesTransformer.grading_policy_hash(course)
with patch(
'learner_pathway_progress.signals.update_learner_pathway_progress',
return_value=None
):
PersistentCourseGrade.update_or_create(
user_id=audit_user.user_id,
course_id=course.id,
passed=False,
percent_grade=0.0,
grading_policy_hash=grading_policy_hash,
)
self._verify_cell_data_for_user(audit_user.username, course.id, 'Certificate Eligible', 'N', num_rows=1)
PersistentCourseGrade.update_or_create(
user_id=audit_user.user_id,
course_id=course.id,
passed=True,
percent_grade=0.8,
letter_grade="pass",
grading_policy_hash=grading_policy_hash,
)
# verifies that audit passing learner is not eligible for certificate
self._verify_cell_data_for_user(audit_user.username, course.id, 'Certificate Eligible', 'N', num_rows=1)
PersistentCourseGrade.update_or_create(
user_id=audit_user.user_id,
course_id=course.id,
passed=False,
percent_grade=0.0,
grading_policy_hash=grading_policy_hash,
)
self._verify_cell_data_for_user(audit_user.username, course.id, 'Certificate Eligible', 'N', num_rows=1)
PersistentCourseGrade.update_or_create(
user_id=audit_user.user_id,
course_id=course.id,
passed=True,
percent_grade=0.8,
letter_grade="pass",
grading_policy_hash=grading_policy_hash,
)
# verifies that audit passing learner is not eligible for certificate
self._verify_cell_data_for_user(audit_user.username, course.id, 'Certificate Eligible', 'N', num_rows=1)
verified_user = CourseEnrollment.enroll(UserFactory.create(), course.id, 'verified')
PersistentCourseGrade.update_or_create(
user_id=verified_user.user_id,
course_id=course.id,
passed=True,
percent_grade=0.8,
letter_grade="pass",
grading_policy_hash=grading_policy_hash,
)
# verifies that verified passing learner is eligible for certificate
self._verify_cell_data_for_user(verified_user.username, course.id, 'Certificate Eligible', 'Y', num_rows=2)
verified_user = CourseEnrollment.enroll(UserFactory.create(), course.id, 'verified')
PersistentCourseGrade.update_or_create(
user_id=verified_user.user_id,
course_id=course.id,
passed=True,
percent_grade=0.8,
letter_grade="pass",
grading_policy_hash=grading_policy_hash,
)
# verifies that verified passing learner is eligible for certificate
self._verify_cell_data_for_user(verified_user.username, course.id, 'Certificate Eligible', 'Y', num_rows=2)
@ddt.data(
(ModuleStoreEnum.Type.mongo, 4, 47),

View File

@@ -155,14 +155,10 @@ class TestProgramsView(SharedModuleStoreTestCase, ProgramCacheMixin):
course_id=modulestore_course.id,
user=cls.user
)
with mock.patch(
'learner_pathway_progress.signals.get_learner_pathways_associated_with_course',
return_value=None
):
EnterpriseCourseEnrollmentFactory(
course_id=modulestore_course.id,
enterprise_customer_user=enterprise_customer_user
)
EnterpriseCourseEnrollmentFactory(
course_id=modulestore_course.id,
enterprise_customer_user=enterprise_customer_user
)
cls.program = ProgramFactory(
uuid=cls.program_uuid,

View File

@@ -343,14 +343,10 @@ class SupportViewEnrollmentsTests(SharedModuleStoreTestCase, SupportViewTestCase
enterprise_customer_user = EnterpriseCustomerUserFactory(
user_id=self.student.id
)
with patch(
'learner_pathway_progress.signals.get_learner_pathways_associated_with_course',
return_value=None
):
enterprise_course_enrollment = EnterpriseCourseEnrollmentFactory(
course_id=self.course.id,
enterprise_customer_user=enterprise_customer_user
)
enterprise_course_enrollment = EnterpriseCourseEnrollmentFactory(
course_id=self.course.id,
enterprise_customer_user=enterprise_customer_user
)
data_sharing_consent = DataSharingConsent(
course_id=self.course.id,
enterprise_customer=enterprise_customer_user.enterprise_customer,