Skip to content

Commit

Permalink
test: adds cea tests for enroll_subsidy_users util
Browse files Browse the repository at this point in the history
  • Loading branch information
tecoholic committed Aug 16, 2024
1 parent 0c6f7a6 commit 81f3d05
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/test_enterprise/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,71 @@ def test_enroll_subsidy_users_in_courses_user_identifier_failures(
)
self.assertEqual(len(EnterpriseCourseEnrollment.objects.all()), 0)

@ddt.unpack
@ddt.data(
(True, True),
(True, False),
(False, True),
(False, False),
)
@mock.patch('enterprise.utils.lms_update_or_create_enrollment')
@mock.patch('enterprise.utils.ensure_course_enrollment_is_allowed')
def test_enroll_subsidy_users_in_courses_for_invite_only_courses(
self,
invite_only,
enrollment_allowed,
mock_ensure_course_enrollment_is_allowed,
mock_update_or_create_enrollment,
):
"""
Test that the users ensure_course_enrollemnt_is_allowed is called for
invitiation-only courses when the enterprise_customer has the flag enabled.
"""
self.create_user()

ent_customer = factories.EnterpriseCustomerFactory(
uuid=FAKE_UUIDS[0],
name="test_enterprise",
allow_enrollment_in_invite_only_courses=enrollment_allowed,
)
factories.EnterpriseCustomerUserFactory(
user_id=self.user.id,
enterprise_customer=ent_customer,
)
licensed_users_info = [{
'email': self.user.email,
'course_run_key': 'course-key-v1',
'course_mode': 'verified',
'license_uuid': '5b77bdbade7b4fcb838f8111b68e18ae',
'invitation_only': invite_only,
}]

mock_update_or_create_enrollment.return_value = True
result = enroll_subsidy_users_in_courses(ent_customer, licensed_users_info)
self.assertEqual(
{
'pending': [],
'successes': [{
'user_id': self.user.id,
'email': self.user.email,
'course_run_key': 'course-key-v1',
'user': self.user,
'created': True,
'activation_link': None,
'enterprise_fulfillment_source_uuid': LicensedEnterpriseCourseEnrollment.objects.first().uuid,
}],
'failures': []
},
result
)
self.assertEqual(len(EnterpriseCourseEnrollment.objects.all()), 1)
if invite_only and enrollment_allowed:
mock_ensure_course_enrollment_is_allowed.assert_called()
else:
mock_ensure_course_enrollment_is_allowed.assert_not_called()



def test_enroll_pending_licensed_users_in_courses_succeeds(self):
"""
Test that users that do not exist are pre-enrolled by enroll_subsidy_users_in_courses and returned under the
Expand Down

0 comments on commit 81f3d05

Please sign in to comment.