-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: emit learner credit unenrollment event
event type: org.openedx.enterprise.learner_credit_course_enrollment.revoked.v1 event_name: LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED The motivation for emitting this event is to support event-driven creation of openedx_ledger.Reversal objects. ENT-9213
- Loading branch information
Showing
7 changed files
with
145 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
Your project description goes here. | ||
""" | ||
|
||
__version__ = "4.24.0" | ||
__version__ = "4.25.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Functions for serializing and emiting Open edX event bus signals. | ||
""" | ||
from openedx_events.enterprise.data import ( | ||
EnterpriseCourseEnrollment, | ||
EnterpriseCustomerUser, | ||
LearnerCreditEnterpriseCourseEnrollment, | ||
) | ||
from openedx_events.enterprise.signals import LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED | ||
|
||
|
||
def serialize_learner_credit_course_enrollment(learner_credit_course_enrollment): | ||
""" | ||
Serializes the ``LearnerCreditEnterpriseCourseEnrollment`` into a defined set of attributes | ||
for use in the event-bus signal. | ||
""" | ||
enterprise_course_enrollment = learner_credit_course_enrollment.enterprise_course_enrollment | ||
enterprise_customer_user = enterprise_course_enrollment.enterprise_customer_user | ||
|
||
enterprise_customer_user_data = EnterpriseCustomerUser( | ||
id=enterprise_customer_user.id, | ||
created=enterprise_customer_user.created, | ||
modified=enterprise_customer_user.modified, | ||
enterprise_customer_uuid=enterprise_customer_user.enterprise_customer.uuid, | ||
user_id=enterprise_customer_user.user_id, | ||
active=enterprise_customer_user.active, | ||
linked=enterprise_customer_user.linked, | ||
is_relinkable=enterprise_customer_user.is_relinkable, | ||
invite_key=enterprise_customer_user.invite_key.uuid if enterprise_customer_user.invite_key else None, | ||
should_inactivate_other_customers=enterprise_customer_user.should_inactivate_other_customers, | ||
) | ||
enterprise_course_enrollment_data = EnterpriseCourseEnrollment( | ||
id=enterprise_course_enrollment.id, | ||
created=enterprise_course_enrollment.created, | ||
modified=enterprise_course_enrollment.modified, | ||
enterprise_customer_user=enterprise_customer_user_data, | ||
course_id=enterprise_course_enrollment.course_id, | ||
saved_for_later=enterprise_course_enrollment.saved_for_later, | ||
source_slug=enterprise_course_enrollment.source.slug if enterprise_course_enrollment.source else None, | ||
unenrolled=enterprise_course_enrollment.unenrolled, | ||
unenrolled_at=enterprise_course_enrollment.unenrolled_at, | ||
) | ||
data = LearnerCreditEnterpriseCourseEnrollment( | ||
uuid=learner_credit_course_enrollment.uuid, | ||
created=learner_credit_course_enrollment.created, | ||
modified=learner_credit_course_enrollment.modified, | ||
fulfillment_type=learner_credit_course_enrollment.fulfillment_type, | ||
enterprise_course_entitlement_uuid=( | ||
learner_credit_course_enrollment.enterprise_course_entitlement.uuid | ||
if learner_credit_course_enrollment.enterprise_course_entitlement | ||
else None | ||
), | ||
enterprise_course_enrollment=enterprise_course_enrollment_data, | ||
is_revoked=learner_credit_course_enrollment.is_revoked, | ||
transaction_id=learner_credit_course_enrollment.transaction_id, | ||
) | ||
return data | ||
|
||
|
||
def send_learner_credit_course_enrollment_revoked_event(learner_credit_course_enrollment): | ||
""" | ||
Sends the LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED openedx event. | ||
Args: | ||
learner_credit_course_enrollment (enterprise.models.LearnerCreditEnterpriseCourseEnrollment): | ||
An enterprise learner credit fulfillment record that was revoked. | ||
""" | ||
LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED.send_event( | ||
learner_credit_course_enrollment=serialize_learner_credit_course_enrollment(learner_credit_course_enrollment), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
Tests for enterprise/event_bus.py | ||
""" | ||
import unittest | ||
|
||
import ddt | ||
from pytest import mark | ||
|
||
from enterprise.event_bus import serialize_learner_credit_course_enrollment | ||
from enterprise.models import EnterpriseEnrollmentSource | ||
from test_utils import factories | ||
|
||
|
||
@ddt.ddt | ||
@mark.django_db | ||
class TestEventBusSerializers(unittest.TestCase): | ||
""" | ||
Test serializers for use with openedx-events events ("event bus"). | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
|
||
self.user = factories.UserFactory(is_active=True) | ||
self.enterprise_customer = factories.EnterpriseCustomerFactory() | ||
self.enterprise_user = factories.EnterpriseCustomerUserFactory( | ||
user_id=self.user.id, | ||
enterprise_customer=self.enterprise_customer, | ||
) | ||
self.enterprise_course_enrollment = factories.EnterpriseCourseEnrollmentFactory( | ||
enterprise_customer_user=self.enterprise_user, | ||
source=EnterpriseEnrollmentSource.get_source(EnterpriseEnrollmentSource.API), | ||
) | ||
self.learner_credit_course_enrollment = factories.LearnerCreditEnterpriseCourseEnrollmentFactory( | ||
enterprise_course_enrollment=self.enterprise_course_enrollment, | ||
) | ||
|
||
def test_serialize_learner_credit_course_enrollment(self): | ||
""" | ||
Perform a basic test that the serializer drills down two levels into the enterprise user correctly. | ||
""" | ||
data = serialize_learner_credit_course_enrollment(self.learner_credit_course_enrollment) | ||
assert data.uuid == self.learner_credit_course_enrollment.uuid | ||
assert data.enterprise_course_enrollment.id == self.enterprise_course_enrollment.id | ||
assert data.enterprise_course_enrollment.source_slug == self.enterprise_course_enrollment.source.slug | ||
assert data.enterprise_course_enrollment.enterprise_customer_user.id == self.enterprise_user.id | ||
assert data.enterprise_course_enrollment.enterprise_customer_user.enterprise_customer_uuid == \ | ||
self.enterprise_customer.uuid |