Add enrollment_course_run to entitlementserializer

The marketing site currently cannot use the entitlement
api to determine whether a user has an unfilled entitlement.
Including the entitlement enrollment_course_run makes this
information accessible to consumers of the entitlement API.

Learner-3731
This commit is contained in:
Michael LoTurco
2017-12-22 10:09:19 -05:00
parent 565e1271cf
commit 2807d9915e
3 changed files with 8 additions and 2 deletions

View File

@@ -6,6 +6,10 @@ from entitlements.models import CourseEntitlement
class CourseEntitlementSerializer(serializers.ModelSerializer):
user = serializers.SlugRelatedField(slug_field='username', queryset=get_user_model().objects.all())
enrollment_course_run = serializers.CharField(
source='enrollment_course_run.course_id',
read_only=True
)
class Meta:
model = CourseEntitlement
@@ -13,6 +17,7 @@ class CourseEntitlementSerializer(serializers.ModelSerializer):
'user',
'uuid',
'course_uuid',
'enrollment_course_run',
'expired_at',
'created',
'modified',

View File

@@ -27,6 +27,7 @@ class EntitlementsSerializerTests(ModuleStoreTestCase):
'expired_at': entitlement.expired_at,
'course_uuid': str(entitlement.course_uuid),
'mode': entitlement.mode,
'enrollment_course_run': None,
'order_number': entitlement.order_number,
'created': entitlement.created.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
'modified': entitlement.modified.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),

View File

@@ -159,8 +159,8 @@ class EntitlementViewSetTest(ModuleStoreTestCase):
@patch("entitlements.api.v1.views.get_course_runs_for_course")
def test_add_entitlement_inactive_audit_enrollment(self, mock_get_course_runs):
"""
Verify that if an entitlement is added for a user, if the user has one upgradeable enrollment
that enrollment is upgraded to the mode of the entitlement and linked to the entitlement.
Verify that if an entitlement is added for a user, if the user has an inactive audit enrollment
that enrollment is NOT upgraded to the mode of the entitlement and linked to the entitlement.
"""
course_uuid = uuid.uuid4()
entitlement_data = self._get_data_set(self.user, str(course_uuid))