diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0239f9959..82ebe5c74 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,12 @@ Unreleased ---------- * nothing unreleased +[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.1] -------- * fix: serialize best_mode_for_course_run field in DefaultEnterpriseEnrollmentIntentionSerializer. diff --git a/enterprise/__init__.py b/enterprise/__init__.py index c39375715..e1ddcb95b 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,4 +2,4 @@ Your project description goes here. """ -__version__ = "4.30.1" +__version__ = "4.31.0" diff --git a/enterprise/api/v1/serializers.py b/enterprise/api/v1/serializers.py index 0646b3b4f..d767cc398 100644 --- a/enterprise/api/v1/serializers.py +++ b/enterprise/api/v1/serializers.py @@ -2064,7 +2064,7 @@ def get_metadata(self, obj): # pylint: disable=unused-argument enrolled by the learner. """ return { - 'total_default_enterprise_course_enrollments': self.total_default_enrollment_intention_count(), + 'total_default_enterprise_enrollment_intentions': self.total_default_enrollment_intention_count(), 'total_needs_enrollment': self.needs_enrollment_counts(), 'total_already_enrolled': self.already_enrolled_count(), } diff --git a/enterprise/api/v1/views/default_enterprise_enrollments.py b/enterprise/api/v1/views/default_enterprise_enrollments.py index 2409317d7..f1fcb6ab2 100644 --- a/enterprise/api/v1/views/default_enterprise_enrollments.py +++ b/enterprise/api/v1/views/default_enterprise_enrollments.py @@ -66,7 +66,7 @@ def base_queryset(self): For non-list actions, this is what's returned by `get_queryset()`. For list actions, some non-strict subset of this is what's returned by `get_queryset()`. """ - return models.DefaultEnterpriseEnrollmentIntention.objects.filter( + return models.DefaultEnterpriseEnrollmentIntention.available_objects.filter( enterprise_customer=self.requested_enterprise_customer_uuid, ) @@ -129,8 +129,10 @@ def learner_status(self, request): ) # Retrieve configured default enrollment intentions for the enterprise customer - default_enrollment_intentions_for_customer = models.DefaultEnterpriseEnrollmentIntention.objects.filter( - enterprise_customer=enterprise_customer_uuid, + default_enrollment_intentions_for_customer = ( + models.DefaultEnterpriseEnrollmentIntention.available_objects.filter( + enterprise_customer=enterprise_customer_uuid, + ) ) # Retrieve the course enrollments for the learner diff --git a/enterprise/migrations/0228_alter_defaultenterpriseenrollmentrealization_realized_enrollment.py b/enterprise/migrations/0228_alter_defaultenterpriseenrollmentrealization_realized_enrollment.py new file mode 100644 index 000000000..c4f93d4f5 --- /dev/null +++ b/enterprise/migrations/0228_alter_defaultenterpriseenrollmentrealization_realized_enrollment.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.16 on 2024-10-29 21:30 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('enterprise', '0227_alter_defaultenterpriseenrollmentintention_content_type_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='defaultenterpriseenrollmentrealization', + name='realized_enrollment', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='enterprise.enterprisecourseenrollment'), + ), + ] diff --git a/enterprise/models.py b/enterprise/models.py index e65186610..2d477e8fd 100644 --- a/enterprise/models.py +++ b/enterprise/models.py @@ -2124,6 +2124,17 @@ def learner_credit_fulfillment(self): associated_fulfillment = None return associated_fulfillment + @property + def default_enterprise_enrollment_realization(self): + """ + Returns the default realization for the enterprise enrollment. + """ + try: + associated_realization = self.defaultenterpriseenrollmentrealization_realized_enrollment # pylint: disable=no-member + except DefaultEnterpriseEnrollmentRealization.DoesNotExist: + associated_realization = None + return associated_realization + @property def fulfillments(self): """ @@ -2708,7 +2719,7 @@ class DefaultEnterpriseEnrollmentRealization(TimeStampedModel): DefaultEnterpriseEnrollmentIntention, on_delete=models.CASCADE, ) - realized_enrollment = models.ForeignKey( + realized_enrollment = models.OneToOneField( EnterpriseCourseEnrollment, on_delete=models.CASCADE, ) diff --git a/enterprise/utils.py b/enterprise/utils.py index b0e904abf..07370c950 100644 --- a/enterprise/utils.py +++ b/enterprise/utils.py @@ -742,6 +742,20 @@ def pending_enterprise_customer_admin_user_model(): return apps.get_model('enterprise', 'PendingEnterpriseCustomerAdminUser') +def default_enterprise_enrollment_intention_model(): + """ + Returns the ``DefaultEnterpriseEnrollmentIntention`` class. + """ + return apps.get_model('enterprise', 'DefaultEnterpriseEnrollmentIntention') + + +def default_enterprise_enrollment_realization_model(): + """ + Returns the ``DefaultEnterpriseEnrollmentRealization`` class. + """ + return apps.get_model('enterprise', 'DefaultEnterpriseEnrollmentRealization') + + def get_enterprise_customer(uuid): """ Get the ``EnterpriseCustomer`` instance associated with ``uuid``. @@ -1816,14 +1830,15 @@ def enroll_user(enterprise_customer, user, course_mode, *course_ids, **kwargs): def customer_admin_enroll_user_with_status( - enterprise_customer, - user, - course_mode, - course_id, - enrollment_source=None, - license_uuid=None, - transaction_id=None, - force_enrollment=False, + enterprise_customer, + user, + course_mode, + course_id, + enrollment_source=None, + license_uuid=None, + transaction_id=None, + force_enrollment=False, + is_default_auto_enrollment=False, ): """ For use with bulk enrollment, or any use case of admin enrolling a user @@ -1910,6 +1925,12 @@ def customer_admin_enroll_user_with_status( licensed_enrollment_obj.uuid, license_uuid, ) enterprise_fulfillment_source_uuid = licensed_enrollment_obj.uuid + + if is_default_auto_enrollment: + # Check for default enterprise enrollment intentions for enterprise customer associated + # with the enrollment, and create a default enterprise enrollment realization if necessary. + check_default_enterprise_enrollment_intentions_and_create_realization(enterprise_course_enrollment=obj) + if created: # Note: this tracking event only caters to bulk enrollment right now. track_enrollment(PATHWAY_CUSTOMER_ADMIN_ENROLLMENT, user.id, course_id) @@ -1920,6 +1941,50 @@ def customer_admin_enroll_user_with_status( return succeeded, created, enterprise_fulfillment_source_uuid +def check_default_enterprise_enrollment_intentions_and_create_realization(enterprise_course_enrollment): + """ + Check if there are any default enrollment intentions for the given enterprise customer, + and create corresponding realizations if they do not exist. + """ + enterprise_customer_uuid = enterprise_course_enrollment.enterprise_customer_user.enterprise_customer.uuid + default_enrollment_intentions_for_customer = ( + default_enterprise_enrollment_intention_model().available_objects.filter( + enterprise_customer=enterprise_customer_uuid, + ) + ) + default_enterprise_enrollment_intention = next( + ( + intention for intention in default_enrollment_intentions_for_customer + if intention.course_run_key == enterprise_course_enrollment.course_id + ), + None + ) + + if not default_enterprise_enrollment_intention: + LOGGER.info( + "No default enrollment intention found for enterprise course enrollment %s", + enterprise_course_enrollment.id + ) + return None + + default_enterprise_enrollment_realization, created = ( + default_enterprise_enrollment_realization_model().objects.get_or_create( + intended_enrollment=default_enterprise_enrollment_intention, + realized_enrollment=enterprise_course_enrollment, + ) + ) + + if created: + LOGGER.info( + "Created default enterprise enrollment realization for default enrollment " + "intention %s and enterprise course enrollment %s", + default_enterprise_enrollment_intention.uuid, + enterprise_course_enrollment.id + ) + + return default_enterprise_enrollment_intention, default_enterprise_enrollment_realization + + def customer_admin_enroll_user(enterprise_customer, user, course_mode, course_id, enrollment_source=None): """ For use with bulk enrollment, or any use case of admin enrolling a user @@ -2006,10 +2071,12 @@ def enroll_subsidy_users_in_courses(enterprise_customer, subsidy_users_info, dis * 'course_mode': The course mode. * 'license_uuid' OR 'transaction_id': ID of either accepted form of subsidy. * 'force_enrollment' (bool, optional): Enroll user even enrollment deadline is expired (default False). + * 'is_default_auto_enrollment' (bool, optional): If True, a related default enterprise enrollment + realization will be created (default False). Example:: - licensed_users_info: [ + subsidy_users_info: [ { 'email': 'newuser@test.com', 'course_run_key': 'course-v1:edX+DemoX+Demo_Course', @@ -2029,6 +2096,7 @@ def enroll_subsidy_users_in_courses(enterprise_customer, subsidy_users_info, dis 'transaction_id': '3a5312d722564db0a16e3d81f53a3718', }, ] + discount: (int) the discount offered to the learner for their enrollment. Subscription based enrollments default to 100 @@ -2057,6 +2125,7 @@ def enroll_subsidy_users_in_courses(enterprise_customer, subsidy_users_info, dis transaction_id = subsidy_user_info.get('transaction_id') activation_link = subsidy_user_info.get('activation_link') force_enrollment = subsidy_user_info.get('force_enrollment', False) + is_default_auto_enrollment = subsidy_user_info.get('is_default_auto_enrollment', False) if user_id and user_email: user = User.objects.filter(id=subsidy_user_info['user_id']).first() @@ -2088,6 +2157,7 @@ def enroll_subsidy_users_in_courses(enterprise_customer, subsidy_users_info, dis license_uuid, transaction_id, force_enrollment=force_enrollment, + is_default_auto_enrollment=is_default_auto_enrollment, ) if succeeded: success_dict = { diff --git a/tests/test_enterprise/api/test_views.py b/tests/test_enterprise/api/test_views.py index c2e2a126a..5fbbd5bbb 100644 --- a/tests/test_enterprise/api/test_views.py +++ b/tests/test_enterprise/api/test_views.py @@ -51,6 +51,7 @@ ) from enterprise.models import ( ChatGPTResponse, + DefaultEnterpriseEnrollmentRealization, EnterpriseCourseEnrollment, EnterpriseCustomer, EnterpriseCustomerInviteKey, @@ -200,6 +201,42 @@ def side_effect(url, query_parameters): ) +def create_mock_default_enterprise_enrollment_intention( + enterprise_customer, + mock_catalog_api_client, + content_metadata=None, + contains_content_items=False, + catalog_list=None, +): + """ + Create a mock default enterprise enrollment intention. + """ + mock_content_metadata = content_metadata or fake_catalog_api.FAKE_COURSE + mock_contains_content_items = contains_content_items + mock_catalog_list = ( + catalog_list + if catalog_list is not None + else [fake_catalog_api.FAKE_CATALOG_RESULT.get('uuid')] + ) + + mock_catalog_api_client.return_value = mock.Mock( + get_content_metadata_content_identifier=mock.Mock( + return_value=mock_content_metadata, + ), + enterprise_contains_content_items=mock.Mock( + return_value=fake_catalog_api.get_fake_enterprise_contains_content_items_response( + contains_content_items=mock_contains_content_items, + catalog_list=mock_catalog_list, + ), + ), + ) + enrollment_intention = factories.DefaultEnterpriseEnrollmentIntentionFactory( + enterprise_customer=enterprise_customer, + content_key=mock_content_metadata.get('key', 'edX+DemoX'), + ) + return enrollment_intention + + class BaseTestEnterpriseAPIViews(APITest): """ Shared setup and methods for enterprise api views. @@ -4878,7 +4915,7 @@ def tearDown(self): 'expected_num_pending_licenses': 1, 'expected_events': [mock.call(PATHWAY_CUSTOMER_ADMIN_ENROLLMENT, 1, 'course-v1:edX+DemoX+Demo_Course')], }, - # Validation failure cases + # Missing enrollment_info or licenses_info { 'body': {}, 'expected_code': 400, @@ -4886,6 +4923,7 @@ def tearDown(self): 'expected_num_pending_licenses': 0, 'expected_events': None, }, + # Invalid licenses_info format { 'body': { 'licenses_info': {} @@ -4897,6 +4935,7 @@ def tearDown(self): 'expected_num_pending_licenses': 0, 'expected_events': None, }, + # No subsidy identifiers provided { 'body': { 'licenses_info': [{'email': 'abc@test.com', 'course_run_key': 'course-v1:edX+DemoX+Demo_Course'}] @@ -4914,6 +4953,7 @@ def tearDown(self): 'expected_num_pending_licenses': 0, 'expected_events': None, }, + # Conflicting license and transaction identifiers { 'body': { 'licenses_info': [ @@ -4939,6 +4979,7 @@ def tearDown(self): 'expected_num_pending_licenses': 0, 'expected_events': None, }, + # No user identifier provided { 'body': { 'licenses_info': [ @@ -4957,6 +4998,7 @@ def tearDown(self): 'expected_num_pending_licenses': 0, 'expected_events': None, }, + # Invalid email format { 'body': { 'licenses_info': [{ @@ -5098,6 +5140,7 @@ def tearDown(self): mock.call(PATHWAY_CUSTOMER_ADMIN_ENROLLMENT, 1, 'course-v2:edX+DemoX+Second_Demo_Course') ], }, + # Multi-learner, multi-course pending { 'body': { 'enrollments_info': [ @@ -5792,6 +5835,128 @@ def test_enroll_learners_in_courses_partial_failure(self, mock_get_course_mode, self.assertEqual(response.status_code, status.HTTP_409_CONFLICT) self.assertEqual(response.json(), enrollment_response) + @ddt.data( + # Creates DefaultEnterpriseEnrollmentRealization upon successful subscription + # enrollment (is_default_auto_enrollment is True) + { + 'body': { + 'notify': 'true', + 'enrollments_info': [ + { + 'email': 'abc@test.com', + 'course_run_key': fake_catalog_api.FAKE_COURSE_RUN.get('key'), + 'mode': VERIFIED_COURSE_MODE, + 'license_uuid': '2aa06d86-e2bf-40b8-81e7-b0449fa5541f', + 'is_default_auto_enrollment': True, + }, + ] + }, + 'fulfillment_source': LicensedEnterpriseCourseEnrollment, + 'expected_enrollment_realization_count': 0, + }, + # Does NOT create DefaultEnterpriseEnrollmentRealization upon successful + # subscription enrollment (is_default_auto_enrollment is False) + { + 'body': { + 'notify': 'true', + 'enrollments_info': [ + { + 'email': 'abc@test.com', + 'course_run_key': fake_catalog_api.FAKE_COURSE_RUN.get('key'), + 'mode': VERIFIED_COURSE_MODE, + 'license_uuid': '2aa06d86-e2bf-40b8-81e7-b0449fa5541f', + 'is_default_auto_enrollment': False, + }, + ] + }, + 'fulfillment_source': LicensedEnterpriseCourseEnrollment, + 'expected_enrollment_realization_count': 0, + }, + # Does NOT create DefaultEnterpriseEnrollmentRealization upon successful + # subscription enrollment (is_default_auto_enrollment is not provided) + { + 'body': { + 'notify': 'true', + 'enrollments_info': [ + { + 'email': 'abc@test.com', + 'course_run_key': fake_catalog_api.FAKE_COURSE_RUN.get('key'), + 'mode': VERIFIED_COURSE_MODE, + 'license_uuid': '2aa06d86-e2bf-40b8-81e7-b0449fa5541f', + }, + ] + }, + 'fulfillment_source': LicensedEnterpriseCourseEnrollment, + 'expected_enrollment_realization_count': 0, + }, + ) + @ddt.unpack + @mock.patch('enterprise.content_metadata.api.EnterpriseCatalogApiClient') + @mock.patch('enterprise.api.v1.views.enterprise_customer.get_best_mode_from_course_key') + @mock.patch('enterprise.utils.lms_update_or_create_enrollment') + def test_enroll_learners_in_courses_default_enrollment_realizations( + self, + mock_get_course_mode, + mock_update_or_create_enrollment, + mock_catalog_api_client, + body, + fulfillment_source, + expected_enrollment_realization_count, + ): + """ + Test that a successful bulk enrollment call to generate subsidy based enrollment records will return the newly + generated subsidized enrollment uuid value as part of the response payload. + """ + mock_update_or_create_enrollment.return_value = True + + user, ecu, enterprise_customer = self._create_user_and_enterprise_customer( + body.get('enrollments_info')[0].get('email'), TEST_PASSWORD + ) + + permission = Permission.objects.get(name='Can add Enterprise Customer') + user.user_permissions.add(permission) + mock_get_course_mode.return_value = VERIFIED_COURSE_MODE + + # Create a new DefaultEnterpriseEnrollmentIntention + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) + + enrollment_url = reverse( + 'enterprise-customer-enroll-learners-in-courses', + (str(enterprise_customer.uuid),) + ) + with mock.patch('enterprise.api.v1.views.enterprise_customer.track_enrollment'): + with mock.patch("enterprise.models.EnterpriseCustomer.notify_enrolled_learners"): + response = self.client.post( + settings.TEST_SERVER + enrollment_url, + data=json.dumps(body), + content_type='application/json', + ) + + self.assertEqual(response.status_code, 201) + + response_json = response.json() + self.assertEqual(len(response_json.get('successes')), 1) + self.assertEqual( + str(fulfillment_source.objects.first().uuid), + response_json.get('successes')[0].get('enterprise_fulfillment_source_uuid') + ) + + enrollments = EnterpriseCourseEnrollment.objects.filter( + enterprise_customer_user=ecu, + ) + assert len(enrollments) == 1 + enrollment = enrollments.first() + assert enrollment.course_id == body['enrollments_info'][0]['course_run_key'] + + enrollment_realization = DefaultEnterpriseEnrollmentRealization.objects.filter( + intended_enrollment=enrollment_intention, + realized_enrollment=enrollment, + ) + assert len(enrollment_realization) == expected_enrollment_realization_count + @ddt.ddt @mark.django_db @@ -9807,41 +9972,6 @@ def get_default_enrollment_intention_with_learner_enrollment_state(self, enrollm 'is_existing_enrollment_audit': kwargs.get('is_existing_enrollment_audit', None), } - def create_mock_default_enterprise_enrollment_intention( - self, - mock_catalog_api_client, - content_metadata=None, - contains_content_items=False, - catalog_list=None, - ): - """ - Create a mock default enterprise enrollment intention. - """ - mock_content_metadata = content_metadata or fake_catalog_api.FAKE_COURSE - mock_contains_content_items = contains_content_items - mock_catalog_list = ( - catalog_list - if catalog_list is not None - else [fake_catalog_api.FAKE_CATALOG_RESULT.get('uuid')] - ) - - mock_catalog_api_client.return_value = mock.Mock( - get_content_metadata_content_identifier=mock.Mock( - return_value=mock_content_metadata, - ), - enterprise_contains_content_items=mock.Mock( - return_value=fake_catalog_api.get_fake_enterprise_contains_content_items_response( - contains_content_items=mock_contains_content_items, - catalog_list=mock_catalog_list, - ), - ), - ) - enrollment_intention = factories.DefaultEnterpriseEnrollmentIntentionFactory( - enterprise_customer=self.enterprise_customer, - content_key=mock_content_metadata.get('key', 'edX+DemoX'), - ) - return enrollment_intention - def test_default_enterprise_enrollment_intentions_missing_enterprise_uuid(self): """ Test expected response when successfully listing existing default enterprise enrollment intentions. @@ -9869,7 +9999,10 @@ def test_default_enterprise_enrollment_intentions_list(self, mock_catalog_api_cl Test expected response when successfully listing existing default enterprise enrollment intentions. """ 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) + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) query_params = f'enterprise_customer_uuid={str(self.enterprise_customer.uuid)}' response = self.client.get( f"{settings.TEST_SERVER}{DEFAULT_ENTERPRISE_ENROLLMENT_INTENTION_LIST_ENDPOINT}?{query_params}" @@ -9888,7 +10021,10 @@ def test_default_enterprise_enrollment_intentions_detail(self, mock_catalog_api_ enterprise enrollment intentions. """ 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) + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) query_params = f'enterprise_customer_uuid={str(self.enterprise_customer.uuid)}' base_url = get_default_enterprise_enrollment_intention_detail_endpoint(str(enrollment_intention.uuid)) response = self.client.get(f"{settings.TEST_SERVER}{base_url}?{query_params}") @@ -9905,7 +10041,10 @@ def test_default_enterprise_enrollment_intentions_list_unauthorized(self, mock_c enterprise enrollment intentions. """ self.set_jwt_cookie(ENTERPRISE_LEARNER_ROLE, str(self.enterprise_customer.uuid)) - self.create_mock_default_enterprise_enrollment_intention(mock_catalog_api_client) + create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) query_params = f'enterprise_customer_uuid={str(uuid.uuid4())}' response = self.client.get( f"{settings.TEST_SERVER}{DEFAULT_ENTERPRISE_ENROLLMENT_INTENTION_LIST_ENDPOINT}?{query_params}" @@ -9922,7 +10061,10 @@ def test_default_enterprise_enrollment_intentions_detail_403_forbidden(self, moc enterprise enrollment intentions. """ 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) + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) query_params = f'enterprise_customer_uuid={str(uuid.uuid4())}' base_url = get_default_enterprise_enrollment_intention_detail_endpoint(str(enrollment_intention.uuid)) response = self.client.get(f"{settings.TEST_SERVER}{base_url}?{query_params}") @@ -9934,8 +10076,9 @@ def test_default_enterprise_enrollment_intentions_not_in_catalog(self, mock_cata Test expected response when default enterprise enrollment intention is not in catalog. """ 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, + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, contains_content_items=False, catalog_list=[], ) @@ -9975,7 +10118,10 @@ def test_default_enterprise_enrollment_intentions_learner_status_enrollable( the course run associated with the default enrollment intention is enrollable. """ 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) + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) mock_get_best_mode_from_course_key.return_value = VERIFIED_COURSE_MODE factories.EnterpriseCustomerUserFactory( user_id=self.user.id, @@ -9999,7 +10145,7 @@ def test_default_enterprise_enrollment_intentions_learner_status_enrollable( 'already_enrolled': [], } assert response_data['metadata'] == { - 'total_default_enterprise_course_enrollments': 1, + 'total_default_enterprise_enrollment_intentions': 1, 'total_needs_enrollment': { 'enrollable': 1, 'not_enrollable': 0, @@ -10023,8 +10169,9 @@ def test_default_enrollment_intentions_learner_status_content_not_enrollable( mock_course_run.update({'is_enrollable': False}) mock_course = fake_catalog_api.FAKE_COURSE.copy() mock_course.update({'course_runs': [mock_course_run]}) - enrollment_intention = self.create_mock_default_enterprise_enrollment_intention( - mock_catalog_api_client, + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, content_metadata=mock_course, ) mock_get_best_mode_from_course_key.return_value = VERIFIED_COURSE_MODE @@ -10053,7 +10200,7 @@ def test_default_enrollment_intentions_learner_status_content_not_enrollable( 'already_enrolled': [], } assert response_data['metadata'] == { - 'total_default_enterprise_course_enrollments': 1, + 'total_default_enterprise_enrollment_intentions': 1, 'total_needs_enrollment': { 'enrollable': 0, 'not_enrollable': 1, @@ -10073,8 +10220,9 @@ def test_default_enrollment_intentions_learner_status_content_not_in_catalog( catalog) for specific learner linked to enterprise customer. """ 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, + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, contains_content_items=False, catalog_list=[], ) @@ -10108,7 +10256,7 @@ def test_default_enrollment_intentions_learner_status_content_not_in_catalog( 'already_enrolled': [], } assert response_data['metadata'] == { - 'total_default_enterprise_course_enrollments': 1, + 'total_default_enterprise_enrollment_intentions': 1, 'total_needs_enrollment': { 'enrollable': 0, 'not_enrollable': 1, @@ -10130,7 +10278,10 @@ def test_default_enrollment_intentions_learner_status_already_enrolled_active( enrollment) for specific learner linked to enterprise customer. """ 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) + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) mock_get_best_mode_from_course_key.return_value = VERIFIED_COURSE_MODE enterprise_customer_user = factories.EnterpriseCustomerUserFactory( user_id=self.user.id, @@ -10168,7 +10319,7 @@ def test_default_enrollment_intentions_learner_status_already_enrolled_active( ], } assert response_data['metadata'] == { - 'total_default_enterprise_course_enrollments': 1, + 'total_default_enterprise_enrollment_intentions': 1, 'total_needs_enrollment': { 'enrollable': 0, 'not_enrollable': 0, @@ -10190,7 +10341,10 @@ def test_default_enrollment_intentions_learner_status_already_enrolled_inactive( enrollment) for specific learner linked to enterprise customer. """ 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) + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) mock_get_best_mode_from_course_key.return_value = VERIFIED_COURSE_MODE enterprise_customer_user = factories.EnterpriseCustomerUserFactory( user_id=self.user.id, @@ -10228,7 +10382,7 @@ def test_default_enrollment_intentions_learner_status_already_enrolled_inactive( 'already_enrolled': [], } assert response_data['metadata'] == { - 'total_default_enterprise_course_enrollments': 1, + 'total_default_enterprise_enrollment_intentions': 1, 'total_needs_enrollment': { 'enrollable': 1, 'not_enrollable': 0, @@ -10256,7 +10410,10 @@ def test_default_enrollment_intentions_learner_status_already_enrolled_active_au audit enrollment) for specific learner linked to enterprise customer. """ 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) + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) 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 @@ -10307,7 +10464,7 @@ def test_default_enrollment_intentions_learner_status_already_enrolled_active_au 'already_enrolled': expected_already_enrolled, } assert response_data['metadata'] == { - 'total_default_enterprise_course_enrollments': 1, + 'total_default_enterprise_enrollment_intentions': 1, 'total_needs_enrollment': { 'enrollable': len(expected_enrollable), 'not_enrollable': 0, @@ -10332,7 +10489,10 @@ def test_default_enrollment_intentions_learner_status_staff_lms_user_id_override staff_user = self.create_user(username='staff_username', password=TEST_PASSWORD, is_staff=True) self.client.login(username=staff_user.username, password=TEST_PASSWORD) - enrollment_intention = self.create_mock_default_enterprise_enrollment_intention(mock_catalog_api_client) + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) mock_get_best_mode_from_course_key.return_value = VERIFIED_COURSE_MODE factories.EnterpriseCustomerUserFactory( user_id=self.user.id, @@ -10360,7 +10520,7 @@ def test_default_enrollment_intentions_learner_status_staff_lms_user_id_override 'already_enrolled': [], } assert response_data['metadata'] == { - 'total_default_enterprise_course_enrollments': 1, + 'total_default_enterprise_enrollment_intentions': 1, 'total_needs_enrollment': { 'enrollable': 1, 'not_enrollable': 0, @@ -10379,7 +10539,10 @@ def test_default_enrollment_intentions_learner_status_nonstaff_lms_user_id_overr Test default enterprise enrollment intentions for non-staff user linked to enterprise customer. """ 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) + enrollment_intention = create_mock_default_enterprise_enrollment_intention( + enterprise_customer=self.enterprise_customer, + mock_catalog_api_client=mock_catalog_api_client, + ) mock_get_best_mode_from_course_key.return_value = VERIFIED_COURSE_MODE factories.EnterpriseCustomerUserFactory( user_id=self.user.id, @@ -10407,7 +10570,7 @@ def test_default_enrollment_intentions_learner_status_nonstaff_lms_user_id_overr 'already_enrolled': [], } assert response_data['metadata'] == { - 'total_default_enterprise_course_enrollments': 1, + 'total_default_enterprise_enrollment_intentions': 1, 'total_needs_enrollment': { 'enrollable': 1, 'not_enrollable': 0,