Skip to content

Commit

Permalink
fix: support force_enrollment in serializers used by bulk enrollment
Browse files Browse the repository at this point in the history
ENT-8788
  • Loading branch information
pwnage101 committed Apr 22, 2024
1 parent 6692c94 commit 509c2fd
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Change Log
Unreleased
----------
[4.15.11]
---------
* fix: support `force_enrollment` in serializers used by bulk enrollment (ENT-8788)

[4.15.10]
---------
* fix: set default langauge for all learners linked with an enteprise customer
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.15.10"
__version__ = "4.15.11"
4 changes: 4 additions & 0 deletions enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,10 @@ class EnrollmentsInfoSerializer(serializers.Serializer):
course_run_key = serializers.CharField(required=True)
license_uuid = serializers.CharField(required=False)
transaction_id = serializers.CharField(required=False)
force_enrollment = serializers.BooleanField(
required=False,
help_text='Enroll even if enrollment deadline is expired.',
)

def create(self, validated_data):
return validated_data
Expand Down
51 changes: 51 additions & 0 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4645,6 +4645,57 @@ def test_bulk_enrollment_in_bulk_courses_existing_users(

assert mock_update_or_create_enrollment.call_count == 2

@mock.patch('enterprise.api.v1.views.enterprise_customer.get_best_mode_from_course_key')
@mock.patch('enterprise.utils.lms_update_or_create_enrollment')
@mock.patch('enterprise.api.v1.views.enterprise_customer.track_enrollment', mock.MagicMock())
def test_bulk_enrollment_force_enrollment(
self,
mock_update_or_create_enrollment,
mock_get_course_mode,
):
"""
Ensure bulk enrollment passes force_enrollment hints into lower level functions.
"""
mock_update_or_create_enrollment.return_value = True

user_one = factories.UserFactory(is_active=True)
user_two = factories.UserFactory(is_active=True)

factories.EnterpriseCustomerFactory(
uuid=FAKE_UUIDS[0],
name="test_enterprise"
)

permission = Permission.objects.get(name='Can add Enterprise Customer')
self.user.user_permissions.add(permission)
mock_get_course_mode.return_value = VERIFIED_SUBSCRIPTION_COURSE_MODE

self.assertEqual(len(PendingEnrollment.objects.all()), 0)
body = {
'enrollments_info': [
{
'user_id': user_one.id,
'course_run_key': 'course-v1:edX+DemoX+Demo_Course',
'license_uuid': '5a88bdcade7c4ecb838f8111b68e18ac',
# For this enrollment, force_enrollment should fallback to False.
},
{
'email': user_two.email,
'course_run_key': 'course-v1:edX+DemoX+Demo_Course',
'license_uuid': '2c58acdade7c4ede838f7111b42e18ac',
'force_enrollment': True,
},
]
}
response = self.client.post(
settings.TEST_SERVER + ENTERPRISE_CUSTOMER_BULK_ENROLL_LEARNERS_IN_COURSES_ENDPOINT,
data=json.dumps(body),
content_type='application/json',
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
assert mock_update_or_create_enrollment.mock_calls[0].kwargs['force_enrollment'] is False
assert mock_update_or_create_enrollment.mock_calls[1].kwargs['force_enrollment'] is True

@mock.patch('enterprise.api.v1.views.enterprise_customer.get_best_mode_from_course_key')
@mock.patch('enterprise.api.v1.views.enterprise_customer.track_enrollment')
@mock.patch('enterprise.models.EnterpriseCustomer.notify_enrolled_learners')
Expand Down

0 comments on commit 509c2fd

Please sign in to comment.