From 81f3d051354cd232d41b149b7e657203a461e908 Mon Sep 17 00:00:00 2001 From: Arunmozhi Date: Fri, 16 Aug 2024 20:43:15 +1000 Subject: [PATCH] test: adds cea tests for enroll_subsidy_users util --- tests/test_enterprise/test_utils.py | 65 +++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/test_enterprise/test_utils.py b/tests/test_enterprise/test_utils.py index 4dc3a8709..f598b3f8c 100644 --- a/tests/test_enterprise/test_utils.py +++ b/tests/test_enterprise/test_utils.py @@ -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