Skip to content

Commit

Permalink
fix: serialize best_mode_for_course_run field in DefaultEnterpriseEnr…
Browse files Browse the repository at this point in the history
…ollmentIntentionSerializer
  • Loading branch information
adamstankiewicz committed Oct 30, 2024
1 parent b9025f8 commit 75a69ff
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 26 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Unreleased
----------
* nothing unreleased

[4.31.1]
--------
* fix: serialize best_mode_for_course_run field in DefaultEnterpriseEnrollmentIntentionSerializer.

[4.31.0]
--------
* feat: create DefaultEnterpriseEnrollmentRealization objects in bulk enrollment API, when applicable.
* fix: Alter the realized_enrollment field in DefaultEnterpriseEnrollmentRealization to be a OneToOneField.
* fix: rename metadata field in DefaultEnterpriseEnrollmentIntentionLearnerStatusSerializer.

[4.30.0]
--------
* feat: REST APIs for default-enterprise-enrollment-intentions
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.30.0"
__version__ = "4.31.1"
7 changes: 7 additions & 0 deletions enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,7 @@ class Meta:
'course_key',
'course_run_key',
'is_course_run_enrollable',
'best_mode_for_course_run',
'applicable_enterprise_catalog_uuids',
'course_run_normalized_metadata',
'created',
Expand Down Expand Up @@ -1942,6 +1943,12 @@ def get_course_run_normalized_metadata(self, obj):
def get_applicable_enterprise_catalog_uuids(self, obj):
return obj.applicable_enterprise_catalog_uuids

def get_best_mode_for_course_run(self, obj):
"""
Get the best course mode for the course run.
"""
return obj.best_mode_for_course_run


class DefaultEnterpriseEnrollmentIntentionWithEnrollmentStateSerializer(DefaultEnterpriseEnrollmentIntentionSerializer):
"""
Expand Down
40 changes: 22 additions & 18 deletions test_utils/fake_catalog_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from unittest import mock

from test_utils import FAKE_UUIDS
from tests.test_enterprise.api.constants import (
AUDIT_COURSE_MODE,
VERIFIED_COURSE_MODE,
)

FAKE_URL = 'https://fake.url'

Expand All @@ -26,7 +30,7 @@
'marketing_url': 'course/demo-course?utm_=test_enterprise&utm_medium=enterprise',
'seats': [
{
'type': 'audit',
'type': AUDIT_COURSE_MODE,
'price': '0.00',
'currency': 'USD',
'upgrade_deadline': None,
Expand All @@ -35,7 +39,7 @@
'sku': '68EFFFF'
},
{
'type': 'verified',
'type': VERIFIED_COURSE_MODE,
'price': '149.00',
'currency': 'USD',
'upgrade_deadline': '2018-08-03T16:44:26.595896Z',
Expand All @@ -50,7 +54,7 @@
'enrollment_end': None,
'enrollment_url': FAKE_URL,
'pacing_type': 'instructor_paced',
'type': 'verified',
'type': VERIFIED_COURSE_MODE,
'status': 'published',
'course': 'edX+DemoX',
'full_description': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand Down Expand Up @@ -110,7 +114,7 @@
'marketing_url': 'course/demo-course?utm_=test_enterprise&utm_medium=enterprise',
'seats': [
{
'type': 'audit',
'type': AUDIT_COURSE_MODE,
'price': 0,
'currency': 'USD',
'upgrade_deadline': None,
Expand All @@ -119,7 +123,7 @@
'sku': '68EFFFF'
},
{
'type': 'verified',
'type': VERIFIED_COURSE_MODE,
'price': 149,
'currency': 'USD',
'upgrade_deadline': '2018-08-03T16:44:26.595896Z',
Expand All @@ -135,7 +139,7 @@
'enrollment_end': None,
'enrollment_url': FAKE_URL,
'pacing_type': 'instructor_paced',
'type': 'verified',
'type': VERIFIED_COURSE_MODE,
'status': 'published',
"is_enrollable": True,
"is_marketable": True,
Expand Down Expand Up @@ -403,7 +407,7 @@
"staff": [],
"credit_redemption_overview": "This is a test Program.",
"applicable_seat_types": [
"audit"
AUDIT_COURSE_MODE
],
}

Expand Down Expand Up @@ -567,7 +571,7 @@
"min_hours_effort_per_week": 5,
"max_hours_effort_per_week": 10,
"applicable_seat_types": [
"verified",
VERIFIED_COURSE_MODE,
"professional",
"credit",
],
Expand Down Expand Up @@ -598,7 +602,7 @@
}
},
"applicable_seat_types": [
"verified",
VERIFIED_COURSE_MODE,
"professional",
"credit"
],
Expand All @@ -623,7 +627,7 @@
"credit_hours": None
},
{
"type": "audit",
"type": AUDIT_COURSE_MODE,
"price": "0.00",
"currency": "USD",
"upgrade_deadline": None,
Expand Down Expand Up @@ -669,7 +673,7 @@
"credit_hours": None
},
{
"type": "audit",
"type": AUDIT_COURSE_MODE,
"price": "0.00",
"currency": "AED",
"upgrade_deadline": None,
Expand Down Expand Up @@ -847,14 +851,14 @@
"enrollment_start": None,
"enrollment_end": None,
"pacing_type": "instructor_paced",
"type": "audit",
"type": AUDIT_COURSE_MODE,
"course": "edX+DemoX",
"full_description": None,
"announcement": None,
"video": None,
"seats": [
{
"type": "audit",
"type": AUDIT_COURSE_MODE,
"price": "0.00",
"currency": "USD",
"upgrade_deadline": None,
Expand Down Expand Up @@ -1103,8 +1107,8 @@
"course_runs": [],
"full_description": None,
"seat_types": [
"audit",
"verified"
AUDIT_COURSE_MODE,
VERIFIED_COURSE_MODE,
],
"mobile_available": False,
"end": None,
Expand All @@ -1122,7 +1126,7 @@
"staff_uuids": [],
"language": None,
"number": "DemoX",
"type": "verified",
"type": VERIFIED_COURSE_MODE,
"key": "course-v1:edX+DemoX+Demo_Course",
"org": "edX",
"level_type": None,
Expand Down Expand Up @@ -1375,7 +1379,7 @@
"course_runs": [
{
"enrollment_end": None,
"enrollment_mode": "verified",
"enrollment_mode": VERIFIED_COURSE_MODE,
"key": "course-v1:edX+DemoX+Demo_Course",
"enrollment_start": None,
"pacing_type": "instructor_paced",
Expand Down Expand Up @@ -1542,7 +1546,7 @@ def create_course_run_dict(start="2014-10-14T13:11:03Z", end="3000-10-13T13:11:0
"status": status,
"enrollment_start": enrollment_start,
"enrollment_end": enrollment_end,
"seats": [{"type": "verified", "upgrade_deadline": upgrade_deadline}],
"seats": [{"type": VERIFIED_COURSE_MODE, "upgrade_deadline": upgrade_deadline}],
"availability": availability,
"weeks_to_complete": weeks_to_complete,
"uuid": uuid,
Expand Down
4 changes: 4 additions & 0 deletions tests/test_enterprise/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
('<md:EntitiesDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"> <md:EntityDescriptor entityID="https://idp1.example.com"> <md:IDPSSODescriptor></md:IDPSSODescriptor> </md:EntityDescriptor> <md:EntityDescriptor entityID="https://idp2.example.com"> <md:IDPSSODescriptor></md:IDPSSODescriptor> </md:EntityDescriptor> </md:EntitiesDescriptor>', "https://idp1.example.com"), # pylint: disable=line-too-long
('<EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata"><EntityDescriptor entityID="https://example.com"></EntityDescriptor></EntitiesDescriptor>', "https://example.com") # pylint: disable=line-too-long
]

# Course Modes
VERIFIED_COURSE_MODE = 'verified'
AUDIT_COURSE_MODE = 'audit'
17 changes: 10 additions & 7 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@
)
from test_utils.fake_enterprise_api import get_default_branding_object

from .constants import FAKE_SSO_METADATA_XML_WITH_ENTITY_ID
from .constants import (
AUDIT_COURSE_MODE,
FAKE_SSO_METADATA_XML_WITH_ENTITY_ID,
VERIFIED_COURSE_MODE,
)

Application = get_application_model()
fake = Faker()
Expand Down Expand Up @@ -173,8 +177,6 @@
DEFAULT_ENTERPRISE_ENROLLMENT_INTENTION_LEARNER_STATUS_ENDPOINT = reverse(
'default-enterprise-enrollment-intentions-learner-status'
)
VERIFIED_COURSE_MODE = 'verified'
AUDIT_COURSE_MODE = 'audit'


def get_default_enterprise_enrollment_intention_detail_endpoint(enrollment_intention_uuid=None):
Expand Down Expand Up @@ -9776,6 +9778,7 @@ def get_default_enrollment_intention_with_learner_enrollment_state(self, enrollm
**kwargs: Additional parameters to customize the response.
- applicable_enterprise_catalog_uuids: List of applicable enterprise catalog UUIDs.
- is_course_run_enrollable: Boolean indicating if the course run is enrollable.
- best_mode_for_course_run: The best mode for the course run (e.g., "verified", "audit").
- has_existing_enrollment: Boolean indicating if there is an existing enrollment.
- is_existing_enrollment_active: Boolean indicating if the existing enrollment is
active, or None if no existing enrollment.
Expand All @@ -9789,6 +9792,7 @@ def get_default_enrollment_intention_with_learner_enrollment_state(self, enrollm
'course_key': enrollment_intention.course_key,
'course_run_key': enrollment_intention.course_run_key,
'is_course_run_enrollable': kwargs.get('is_course_run_enrollable', True),
'best_mode_for_course_run': kwargs.get('best_mode_for_course_run', VERIFIED_COURSE_MODE),
'applicable_enterprise_catalog_uuids': kwargs.get(
'applicable_enterprise_catalog_uuids',
[fake_catalog_api.FAKE_CATALOG_RESULT.get('uuid')],
Expand Down Expand Up @@ -10258,10 +10262,8 @@ def test_default_enrollment_intentions_learner_status_already_enrolled_active_au
self.set_jwt_cookie(ENTERPRISE_LEARNER_ROLE, str(self.enterprise_customer.uuid))
enrollment_intention = self.create_mock_default_enterprise_enrollment_intention(mock_catalog_api_client)

if has_audit_mode_only:
mock_get_best_mode_from_course_key.return_value = AUDIT_COURSE_MODE
else:
mock_get_best_mode_from_course_key.return_value = VERIFIED_COURSE_MODE
best_mode_for_course_run = AUDIT_COURSE_MODE if has_audit_mode_only else VERIFIED_COURSE_MODE
mock_get_best_mode_from_course_key.return_value = best_mode_for_course_run

enterprise_customer_user = factories.EnterpriseCustomerUserFactory(
user_id=self.user.id,
Expand Down Expand Up @@ -10293,6 +10295,7 @@ def test_default_enrollment_intentions_learner_status_already_enrolled_active_au
has_existing_enrollment=True,
is_existing_enrollment_active=True,
is_existing_enrollment_audit=True,
best_mode_for_course_run=best_mode_for_course_run,
)

if has_audit_mode_only:
Expand Down

0 comments on commit 75a69ff

Please sign in to comment.