Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] feat: compare Aci.main with Olive #2554

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cms/djangoapps/contentstore/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from lms.djangoapps.grades.api import task_compute_all_grades_for_course
from openedx.core.djangoapps.content.learning_sequences.api import key_supports_outlines
from openedx.core.djangoapps.discussions.tasks import update_discussions_settings_from_course_task
from openedx.core.djangoapps.models.course_details import CourseDetails
from openedx.core.lib.gating import api as gating_api
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import SignalHandler, modulestore
Expand Down Expand Up @@ -95,7 +94,6 @@ def create_catalog_data_for_signal(course_key: CourseKey) -> Optional[CourseCata
enrollment_start=course.enrollment_start,
enrollment_end=course.enrollment_end,
),
effort=CourseDetails.fetch_about_attribute(course_key, 'effort'),
hidden=course.catalog_visibility in ['about', 'none'] or course_key.deprecated,
invitation_only=course.invitation_only,
)
Expand Down
2 changes: 0 additions & 2 deletions cms/djangoapps/contentstore/signals/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def setUp(self):
end=None,
enrollment_start=None,
enrollment_end=None),
short_description=None,
effort=None,
hidden=False,
invitation_only=False
)
Expand Down
72 changes: 72 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,14 @@
# in the LMS and CMS.
# .. toggle_tickets: 'https://github.com/open-craft/edx-platform/pull/429'
'DISABLE_UNENROLLMENT': False,

# .. toggle_name: FEATURES['BADGES_ENABLED']
# .. toggle_implementation: DjangoSetting
# .. toggle_default: False
# .. toggle_description: Set to True to enable the Badges feature.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2024-04-10
'BADGES_ENABLED': False,
}

# .. toggle_name: ENABLE_COPPA_COMPLIANCE
Expand Down Expand Up @@ -2692,3 +2700,67 @@

# Redirect URL for inactive user. If not set, user will be redirected to /login after the login itself (loop)
INACTIVE_USER_URL = f'http://{CMS_BASE}'

#### Event bus ####
EVENT_BUS_PRODUCER = "edx_event_bus_redis.create_producer"
EVENT_BUS_CONSUMER = "edx_event_bus_redis.RedisEventConsumer"
EVENT_BUS_REDIS_CONNECTION_URL = "redis://:password@edx.devstack.redis:6379/"
EVENT_BUS_TOPIC_PREFIX = "dev"


def _should_send_learning_badge_events(settings):
return settings.FEATURES['BADGES_ENABLED']


# .. setting_name: EVENT_BUS_PRODUCER_CONFIG
# .. setting_default: all events disabled
# .. setting_description: Dictionary of event_types mapped to dictionaries of topic to topic-related configuration.
# Each topic configuration dictionary contains
# * `enabled`: a toggle denoting whether the event will be published to the topic. These should be annotated
# according to
# https://edx.readthedocs.io/projects/edx-toggles/en/latest/how_to/documenting_new_feature_toggles.html
# * `event_key_field` which is a period-delimited string path to event data field to use as event key.
# Note: The topic names should not include environment prefix as it will be dynamically added based on
# EVENT_BUS_TOPIC_PREFIX setting.
EVENT_BUS_PRODUCER_CONFIG = {
"org.openedx.learning.course.passing.status.updated.v1": {
"learning-badges-lifecycle": {
"event_key_field": "course_passing_status.course.course_key",
"enabled": _should_send_learning_badge_events,
},
},
"org.openedx.learning.ccx.course.passing.status.updated.v1": {
"learning-badges-lifecycle": {
"event_key_field": "course_passing_status.course.ccx_course_key",
"enabled": _should_send_learning_badge_events,
},
},
}

derived_collection_entry(
"EVENT_BUS_PRODUCER_CONFIG",
"org.openedx.learning.course.passing.status.updated.v1",
"learning-badges-lifecycle",
"enabled",
)
derived_collection_entry(
"EVENT_BUS_PRODUCER_CONFIG",
"org.openedx.learning.ccx.course.passing.status.updated.v1",
"learning-badges-lifecycle",
"enabled",
)

# If the consumer encounters this many consecutive errors, exit with an error.
# This is intended to be used in a context where a management system (such as Kubernetes)
# will relaunch the consumer automatically.

#EVENT_BUS_REDIS_CONSUMER_CONSECUTIVE_ERRORS_LIMIT (defaults to None)

# How long the consumer should wait for new entries in a stream.
# As we are running the consumer in a while True loop, changing this setting doesn't make much difference
# expect for changing number of monitoring messages while waiting for new events.
# https://redis.io/commands/xread/#blocking-for-data
#EVENT_BUS_REDIS_CONSUMER_POLL_TIMEOUT (defaults to 60 seconds)

# Limits stream size to approximately this number
#EVENT_BUS_REDIS_STREAM_MAX_LEN (defaults to 10_000)
65 changes: 61 additions & 4 deletions lms/djangoapps/grades/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
from crum import get_current_user
from django.conf import settings
from eventtracking import tracker
from openedx_events.learning.data import (
CcxCourseData,
CcxCoursePassingStatusData,
CourseData,
CoursePassingStatusData,
UserData,
UserPersonalData
)
from openedx_events.learning.signals import CCX_COURSE_PASSING_STATUS_UPDATED, COURSE_PASSING_STATUS_UPDATED

from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.student.models import CourseEnrollment
Expand Down Expand Up @@ -174,8 +183,8 @@ def course_grade_passed_first_time(user_id, course_id):

def course_grade_now_passed(user, course_id):
"""
Emits an edx.course.grade.now_passed event
with data from the course and user passed now .
Emits an edx.course.grade.now_passed and passing status updated events
with data from the course and user passed now.
"""
event_name = COURSE_GRADE_NOW_PASSED_EVENT_TYPE
context = contexts.course_context_from_course_id(course_id)
Expand All @@ -190,11 +199,13 @@ def course_grade_now_passed(user, course_id):
}
)

_emit_course_passing_status_update(user, course_id, is_passing=True)


def course_grade_now_failed(user, course_id):
"""
Emits an edx.course.grade.now_failed event
with data from the course and user failed now .
Emits an edx.course.grade.now_failed and passing status updated events
with data from the course and user failed now.
"""
event_name = COURSE_GRADE_NOW_FAILED_EVENT_TYPE
context = contexts.course_context_from_course_id(course_id)
Expand All @@ -209,6 +220,8 @@ def course_grade_now_failed(user, course_id):
}
)

_emit_course_passing_status_update(user, course_id, is_passing=False)


def fire_segment_event_on_course_grade_passed_first_time(user_id, course_locator):
"""
Expand Down Expand Up @@ -258,3 +271,47 @@ def fire_segment_event_on_course_grade_passed_first_time(user_id, course_locator
)

log.info("Segment event fired for passed learners. Event: [{}], Data: [{}]".format(event_name, event_properties))


def _emit_course_passing_status_update(user, course_id, is_passing):
"""
Emit course passing status event according to the course type.
The status of event is determined by is_passing parameter.
"""
if hasattr(course_id, 'ccx'):
CCX_COURSE_PASSING_STATUS_UPDATED.send_event(
course_passing_status=CcxCoursePassingStatusData(
is_passing=is_passing,
user=UserData(
pii=UserPersonalData(
username=user.username,
email=user.email,
name=user.get_full_name(),
),
id=user.id,
is_active=user.is_active,
),
course=CcxCourseData(
ccx_course_key=course_id,
master_course_key=course_id.to_course_locator(),
),
)
)
else:
COURSE_PASSING_STATUS_UPDATED.send_event(
course_passing_status=CoursePassingStatusData(
is_passing=is_passing,
user=UserData(
pii=UserPersonalData(
username=user.username,
email=user.email,
name=user.get_full_name(),
),
id=user.id,
is_active=user.is_active,
),
course=CourseData(
course_key=course_id,
),
)
)
164 changes: 160 additions & 4 deletions lms/djangoapps/grades/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@

from unittest import mock

from ccx_keys.locator import CCXLocator
from django.utils.timezone import now
from openedx_events.learning.data import (
CcxCourseData,
CcxCoursePassingStatusData,
CourseData,
PersistentCourseGradeData
CoursePassingStatusData,
PersistentCourseGradeData,
UserData,
UserPersonalData
)
from openedx_events.learning.signals import (
CCX_COURSE_PASSING_STATUS_UPDATED,
COURSE_PASSING_STATUS_UPDATED,
PERSISTENT_GRADE_SUMMARY_CHANGED
)
from openedx_events.learning.signals import PERSISTENT_GRADE_SUMMARY_CHANGED
from openedx_events.tests.utils import OpenEdxEventsTestMixin

from common.djangoapps.student.tests.factories import UserFactory
from common.djangoapps.student.tests.factories import AdminFactory, UserFactory
from lms.djangoapps.ccx.models import CustomCourseForEdX
from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory
from lms.djangoapps.grades.models import PersistentCourseGrade
from lms.djangoapps.grades.tests.utils import mock_passing_grade
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory

Expand Down Expand Up @@ -94,5 +107,148 @@ def test_persistent_grade_event_emitted(self):
passed_timestamp=grade.passed_timestamp
)
},
event_receiver.call_args.kwargs
event_receiver.call_args.kwargs,
)


class CoursePassingStatusEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin):
"""
Tests for Open edX passing status update event.
"""
ENABLED_OPENEDX_EVENTS = [
"org.openedx.learning.course.passing.status.updated.v1",
]

@classmethod
def setUpClass(cls):
"""
Set up class method for the Test class.
"""
super().setUpClass()
cls.start_events_isolation()

def setUp(self):
super().setUp()
self.course = CourseFactory.create()
self.user = UserFactory.create()
self.receiver_called = False

def _event_receiver_side_effect(self, **kwargs):
"""
Used show that the Open edX Event was called by the Django signal handler.
"""
self.receiver_called = True

def test_course_passing_status_updated_emitted(self):
"""
Test whether passing status updated event is sent after the grade is being updated for a user.
"""
event_receiver = mock.Mock(side_effect=self._event_receiver_side_effect)
COURSE_PASSING_STATUS_UPDATED.connect(event_receiver)
grade_factory = CourseGradeFactory()

with mock_passing_grade():
grade_factory.update(self.user, self.course)

self.assertTrue(self.receiver_called)
self.assertDictContainsSubset(
{
"signal": COURSE_PASSING_STATUS_UPDATED,
"sender": None,
"course_passing_status": CoursePassingStatusData(
is_passing=True,
user=UserData(
pii=UserPersonalData(
username=self.user.username,
email=self.user.email,
name=self.user.get_full_name(),
),
id=self.user.id,
is_active=self.user.is_active,
),
course=CourseData(
course_key=self.course.id,
),
),
},
event_receiver.call_args.kwargs,
)


class CCXCoursePassingStatusEventsTest(
SharedModuleStoreTestCase, OpenEdxEventsTestMixin
):
"""
Tests for Open edX passing status update event in a CCX course.
"""
ENABLED_OPENEDX_EVENTS = [
"org.openedx.learning.ccx.course.passing.status.updated.v1",
]

@classmethod
def setUpClass(cls):
"""
Set up class method for the Test class.
"""
super().setUpClass()
cls.start_events_isolation()

def setUp(self):
super().setUp()
self.course = CourseFactory.create()
self.user = UserFactory.create()
self.coach = AdminFactory.create()
self.ccx = ccx = CustomCourseForEdX(
course_id=self.course.id, display_name="Test CCX", coach=self.coach
)
ccx.save()
self.ccx_locator = CCXLocator.from_course_locator(self.course.id, ccx.id)

self.receiver_called = False

def _event_receiver_side_effect(self, **kwargs):
"""
Used show that the Open edX Event was called by the Django signal handler.
"""
self.receiver_called = True

def test_ccx_course_passing_status_updated_emitted(self):
"""
Test whether passing status updated event is sent after the grade is being updated in CCX course.
"""
event_receiver = mock.Mock(side_effect=self._event_receiver_side_effect)
CCX_COURSE_PASSING_STATUS_UPDATED.connect(event_receiver)
grade_factory = CourseGradeFactory()

with mock_passing_grade():
grade_factory.update(self.user, self.store.get_course(self.ccx_locator))

self.assertTrue(self.receiver_called)
self.assertDictContainsSubset(
{
"signal": CCX_COURSE_PASSING_STATUS_UPDATED,
"sender": None,
"course_passing_status": CcxCoursePassingStatusData(
is_passing=True,
user=UserData(
pii=UserPersonalData(
username=self.user.username,
email=self.user.email,
name=self.user.get_full_name(),
),
id=self.user.id,
is_active=self.user.is_active,
),
course=CcxCourseData(
ccx_course_key=self.ccx_locator,
master_course_key=self.course.id,
display_name="",
coach_email="",
start=None,
end=None,
max_students_allowed=self.ccx.max_student_enrollments_allowed,
),
),
},
event_receiver.call_args.kwargs,
)
Loading
Loading