From d4b488c4302e1e4976bf221b05c3ebd8d0f768a3 Mon Sep 17 00:00:00 2001 From: Chris Pappas Date: Wed, 2 Oct 2019 16:26:37 -0400 Subject: [PATCH] ENT-1289 | Removing enterprise entitlement logic from codebase (#590) Updating tests and a few other spots I missed Adding back in some things I should not have taken out Bumping version and changelog --- CHANGELOG.rst | 5 + enterprise/__init__.py | 2 +- enterprise/admin/__init__.py | 44 ------- enterprise/api/v1/serializers.py | 33 +---- enterprise/api/v1/urls.py | 5 - enterprise/api/v1/views.py | 35 ------ enterprise/models.py | 90 -------------- test_utils/factories.py | 21 ---- tests/test_enterprise/api/test_views.py | 102 +-------------- tests/test_models.py | 157 ------------------------ tests/test_utilities.py | 1 - 11 files changed, 11 insertions(+), 484 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ccc84d0fd5..ed94a4e6cf 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,11 @@ Change Log Unreleased ---------- +[2.0.0] - 2019-10-02 +--------------------- + +* Removing EnterpriseCustomerEntitlement code + [1.11.0] - 2019-10-02 --------------------- diff --git a/enterprise/__init__.py b/enterprise/__init__.py index b2e8888238..463c0e16c0 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -4,6 +4,6 @@ from __future__ import absolute_import, unicode_literals -__version__ = "1.11.0" +__version__ = "2.0.0" default_app_config = "enterprise.apps.EnterpriseConfig" # pylint: disable=invalid-name diff --git a/enterprise/admin/__init__.py b/enterprise/admin/__init__.py index 9ea350a676..417fef4752 100644 --- a/enterprise/admin/__init__.py +++ b/enterprise/admin/__init__.py @@ -45,7 +45,6 @@ EnterpriseCustomer, EnterpriseCustomerBrandingConfiguration, EnterpriseCustomerCatalog, - EnterpriseCustomerEntitlement, EnterpriseCustomerIdentityProvider, EnterpriseCustomerReportingConfiguration, EnterpriseCustomerType, @@ -87,35 +86,6 @@ class EnterpriseCustomerIdentityProviderInline(admin.StackedInline): form = EnterpriseCustomerIdentityProviderAdminForm -class EnterpriseCustomerEntitlementInline(admin.StackedInline): - """ - Django admin model for EnterpriseCustomerEntitlement. - The admin interface has the ability to edit models on the same page as a parent model. These are called inlines. - https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.StackedInline - """ - - model = EnterpriseCustomerEntitlement - extra = 0 - can_delete = True - fields = ('enterprise_customer', 'entitlement_id', 'ecommerce_coupon_url',) - - def ecommerce_coupon_url(self, instance): - """ - Instance is EnterpriseCustomer. Return e-commerce coupon urls. - """ - if not instance.entitlement_id: - return "N/A" - - return format_html( - 'View coupon "{id}" details', - base_url=settings.ECOMMERCE_PUBLIC_URL_ROOT, id=instance.entitlement_id - ) - - readonly_fields = ('ecommerce_coupon_url',) - ecommerce_coupon_url.allow_tags = True - ecommerce_coupon_url.short_description = 'Seat Entitlement URL' - - class EnterpriseCustomerCatalogInline(admin.TabularInline): """ Django admin model for EnterpriseCustomerCatalog. @@ -165,7 +135,6 @@ class EnterpriseCustomerAdmin(DjangoObjectActions, SimpleHistoryAdmin): 'has_logo', 'enable_dsc', 'has_identity_provider', - 'has_ecommerce_coupons', 'uuid', ) @@ -175,7 +144,6 @@ class EnterpriseCustomerAdmin(DjangoObjectActions, SimpleHistoryAdmin): inlines = [ EnterpriseCustomerBrandingConfigurationInline, EnterpriseCustomerIdentityProviderInline, - EnterpriseCustomerEntitlementInline, EnterpriseCustomerCatalogInline, ] @@ -192,18 +160,6 @@ class EnterpriseCustomerAdmin(DjangoObjectActions, SimpleHistoryAdmin): class Meta(object): model = EnterpriseCustomer - def has_ecommerce_coupons(self, instance): - """ - Return True if provded enterprise customer has ecommerce coupons. - - Arguments: - instance (enterprise.models.EnterpriseCustomer): `EnterpriseCustomer` model instance - """ - return instance.enterprise_customer_entitlements.exists() - - has_ecommerce_coupons.boolean = True - has_ecommerce_coupons.short_description = 'Ecommerce coupons' - def get_form(self, request, obj=None, **kwargs): """ Retrieve the appropriate form to use, saving the request user diff --git a/enterprise/api/v1/serializers.py b/enterprise/api/v1/serializers.py index c0ac24647f..cb384d5529 100644 --- a/enterprise/api/v1/serializers.py +++ b/enterprise/api/v1/serializers.py @@ -96,18 +96,6 @@ def get_enterprise_slug(self, obj): return obj.enterprise_customer.slug -class EnterpriseCustomerEntitlementSerializer(serializers.ModelSerializer): - """ - Serializer for EnterpriseCustomerEntitlement model. - """ - - class Meta: - model = models.EnterpriseCustomerEntitlement - fields = ( - 'enterprise_customer', 'entitlement_id' - ) - - class EnterpriseCustomerSerializer(serializers.ModelSerializer): """ Serializer for EnterpriseCustomer model. @@ -117,7 +105,7 @@ class Meta: model = models.EnterpriseCustomer fields = ( 'uuid', 'name', 'slug', 'active', 'site', 'enable_data_sharing_consent', - 'enforce_data_sharing_consent', 'branding_configuration', 'enterprise_customer_entitlements', + 'enforce_data_sharing_consent', 'branding_configuration', 'identity_provider', 'enable_audit_enrollment', 'replace_sensitive_sso_username', 'enable_portal_code_management_screen', 'sync_learner_profile_data', 'enable_audit_data_reporting', 'enable_learner_portal', 'learner_portal_hostname', 'enable_portal_reporting_config_screen' @@ -125,9 +113,6 @@ class Meta: site = SiteSerializer() branding_configuration = EnterpriseCustomerBrandingConfigurationSerializer() - enterprise_customer_entitlements = EnterpriseCustomerEntitlementSerializer( # pylint: disable=invalid-name - many=True, - ) class EnterpriseCustomerBasicSerializer(serializers.ModelSerializer): @@ -353,22 +338,6 @@ def save(self): # pylint: disable=arguments-differ ecu.save() -class EnterpriseCustomerUserEntitlementSerializer(ImmutableStateSerializer): - """ - Serializer for the entitlements of EnterpriseCustomerUser. - - This Serializer is for read only endpoint of enterprise learner's entitlements - It will ignore any state changing requests like POST, PUT and PATCH. - """ - - entitlements = serializers.ListField( - child=serializers.DictField() - ) - - user = UserSerializer(read_only=True) - enterprise_customer = EnterpriseCustomerSerializer(read_only=True) - - class CourseDetailSerializer(ImmutableStateSerializer): """ Serializer for course data retrieved from the discovery service course detail API endpoint. diff --git a/enterprise/api/v1/urls.py b/enterprise/api/v1/urls.py index e7a4ebd7ae..7952d90909 100644 --- a/enterprise/api/v1/urls.py +++ b/enterprise/api/v1/urls.py @@ -20,11 +20,6 @@ views.EnterpriseCustomerBrandingConfigurationViewSet, 'enterprise-customer-branding', ) -router.register( - "enterprise-customer-entitlement", - views.EnterpriseCustomerEntitlementViewSet, - 'enterprise-customer-entitlement', -) router.register( "enterprise_customer_reporting", views.EnterpriseCustomerReportingConfigurationViewSet, diff --git a/enterprise/api/v1/views.py b/enterprise/api/v1/views.py index 76a2937ac4..6aedaf7135 100644 --- a/enterprise/api/v1/views.py +++ b/enterprise/api/v1/views.py @@ -264,25 +264,6 @@ def get_serializer_class(self): return serializers.EnterpriseCustomerUserReadOnlySerializer return serializers.EnterpriseCustomerUserWriteSerializer - @detail_route() - def entitlements(self, request, pk=None): # pylint: disable=invalid-name,unused-argument - """ - Retrieve the list of entitlements available to this learner. - - Only those entitlements are returned that satisfy enterprise customer's data sharing setting. - - Arguments: - request (HttpRequest): Reference to in-progress request instance. - pk (Int): Primary key value of the selected enterprise learner. - - Returns: - (HttpResponse): Response object containing a list of learner's entitlements. - """ - enterprise_customer_user = self.get_object() - instance = {"entitlements": enterprise_customer_user.entitlements} - serializer = serializers.EnterpriseCustomerUserEntitlementSerializer(instance, context={'request': request}) - return Response(serializer.data) - class EnterpriseCustomerBrandingConfigurationViewSet(EnterpriseReadOnlyModelViewSet): """ @@ -301,22 +282,6 @@ class EnterpriseCustomerBrandingConfigurationViewSet(EnterpriseReadOnlyModelView lookup_field = 'enterprise_customer__slug' -class EnterpriseCustomerEntitlementViewSet(EnterpriseReadOnlyModelViewSet): - """ - API views for the ``enterprise-customer-entitlements`` API endpoint. - """ - - queryset = models.EnterpriseCustomerEntitlement.objects.all() - serializer_class = serializers.EnterpriseCustomerEntitlementSerializer - - USER_ID_FILTER = 'enterprise_customer__enterprise_customer_users__user_id' - FIELDS = ( - 'enterprise_customer', 'entitlement_id', - ) - filter_fields = FIELDS - ordering_fields = FIELDS - - class EnterpriseCustomerCatalogViewSet(EnterpriseReadOnlyModelViewSet): """ API Views for performing search through course discovery at the ``enterprise_catalogs`` API endpoint. diff --git a/enterprise/models.py b/enterprise/models.py index edc12d4f84..370cb7778c 100644 --- a/enterprise/models.py +++ b/enterprise/models.py @@ -664,53 +664,6 @@ def username(self): return self.user.username return None - @property - def entitlements(self): - """ - Return entitlement ids available to the learner along-with consent data. - - Returns an empty list if enterprise customer requires data sharing consent and learner does not agree. - - Returns: - (list): A list of entitlements that learner can avail. Each item in the list is a dict with two - key-value pairs, - { - "requires_consent": True , - "entitlement_id": 1 - } - "requires_consent": True if learner must consent to data - sharing in order to get benefits of entitlement. - "entitlement_id: id of the entitlements available to the learner. - - """ - # Check if Enterprise Learner consents to data sharing and store the boolean result - DataSharingConsent = apps.get_model('consent', 'DataSharingConsent') # pylint: disable=invalid-name - learner_consent_enabled = DataSharingConsent.objects.filter( - enterprise_customer=self.enterprise_customer, - username=self.username, - granted=True, - ).exists() - - entitlements = self.enterprise_customer.enterprise_customer_entitlements - - # If Enterprise Customer requires account course specific consent then we return all entitlements - # including whether or not to acquire learner's consent. - if self.enterprise_customer.enforces_data_sharing_consent(EnterpriseCustomer.AT_ENROLLMENT): - return [ - { - "entitlement_id": entitlement.entitlement_id, - "requires_consent": not learner_consent_enabled, - } for entitlement in entitlements.all() - ] - - # for all other cases learner is eligible to all entitlements. - return [ - { - "entitlement_id": entitlement.entitlement_id, - "requires_consent": False, - } for entitlement in entitlements.all() - ] - @property def data_sharing_consent_records(self): """ @@ -1059,49 +1012,6 @@ def sync_learner_profile_data(self): return identity_provider is not None and identity_provider.sync_learner_profile_data -@python_2_unicode_compatible -class EnterpriseCustomerEntitlement(TimeStampedModel): - """ - Enterprise Customer Entitlement is a relationship between and Enterprise customer and its entitlements. - - Users associated with an Enterprise Customer could be eligible for these entitlements resulting in partial or full - discounts while taking paid courses on the edX platform. - - .. no_pii: - """ - - class Meta(object): - app_label = 'enterprise' - verbose_name = _("Enterprise Customer Entitlement") - verbose_name_plural = _("Enterprise Customer Entitlements") - ordering = ['created'] - - enterprise_customer = models.ForeignKey(EnterpriseCustomer, related_name="enterprise_customer_entitlements") - entitlement_id = models.PositiveIntegerField( - blank=False, - null=False, - unique=True, - help_text=_("Enterprise customer's entitlement id for relationship with e-commerce coupon."), - verbose_name=_('Seat Entitlement') - ) - history = HistoricalRecords() - - def __str__(self): - """ - Return human-readable string representation. - """ - return "".format( - customer=self.enterprise_customer, - id=self.entitlement_id - ) - - def __repr__(self): - """ - Return uniquely identifying string representation. - """ - return self.__str__() - - @python_2_unicode_compatible class EnterpriseCourseEnrollment(TimeStampedModel): """ diff --git a/test_utils/factories.py b/test_utils/factories.py index 40f688f3b3..f4fc3197ec 100644 --- a/test_utils/factories.py +++ b/test_utils/factories.py @@ -20,7 +20,6 @@ EnterpriseCustomer, EnterpriseCustomerBrandingConfiguration, EnterpriseCustomerCatalog, - EnterpriseCustomerEntitlement, EnterpriseCustomerIdentityProvider, EnterpriseCustomerReportingConfiguration, EnterpriseCustomerUser, @@ -211,26 +210,6 @@ class Meta(object): cohort_name = None -class EnterpriseCustomerEntitlementFactory(factory.django.DjangoModelFactory): - """ - EnterpriseCustomerEntitlement factory. - - Creates an instance of EnterpriseCustomerEntitlement with minimal boilerplate - uses this class' attributes as - default parameters for EnterpriseCustomerEntitlementFactory constructor. - """ - - class Meta(object): - """ - Meta for EnterpriseCustomerEntitlementFactory. - """ - - model = EnterpriseCustomerEntitlement - - id = factory.LazyAttribute(lambda x: FAKER.random_int(min=1)) - entitlement_id = factory.LazyAttribute(lambda x: FAKER.random_int(min=1)) - enterprise_customer = factory.SubFactory(EnterpriseCustomerFactory) - - class EnterpriseCustomerBrandingConfigurationFactory(factory.django.DjangoModelFactory): """ EnterpriseCustomerBrandingConfiguration factory. diff --git a/tests/test_enterprise/api/test_views.py b/tests/test_enterprise/api/test_views.py index 50a14f81fc..dfdb6dc324 100644 --- a/tests/test_enterprise/api/test_views.py +++ b/tests/test_enterprise/api/test_views.py @@ -38,7 +38,6 @@ from enterprise.models import ( EnterpriseCatalogQuery, EnterpriseCourseEnrollment, - EnterpriseCustomer, EnterpriseCustomerUser, EnterpriseFeatureRole, EnterpriseFeatureUserRoleAssignment, @@ -86,7 +85,6 @@ kwargs={'pk': FAKE_UUIDS[1], 'program_uuid': FAKE_UUIDS[3]} ) ENTERPRISE_COURSE_ENROLLMENT_LIST_ENDPOINT = reverse('enterprise-course-enrollment-list') -ENTERPRISE_CUSTOMER_ENTITLEMENT_LIST_ENDPOINT = reverse('enterprise-customer-entitlement-list') ENTERPRISE_CUSTOMER_BRANDING_LIST_ENDPOINT = reverse('enterprise-customer-branding-list') ENTERPRISE_CUSTOMER_BRANDING_DETAIL_ENDPOINT = reverse('enterprise-customer-branding-detail', (TEST_SLUG,)) ENTERPRISE_CUSTOMER_LIST_ENDPOINT = reverse('enterprise-customer-list') @@ -97,7 +95,6 @@ ) ENTERPRISE_CUSTOMER_COURSE_ENROLLMENTS_ENDPOINT = reverse('enterprise-customer-course-enrollments', (FAKE_UUIDS[0],)) ENTERPRISE_CUSTOMER_REPORTING_ENDPOINT = reverse('enterprise-customer-reporting-list') -ENTERPRISE_LEARNER_ENTITLEMENTS_ENDPOINT = reverse('enterprise-learner-entitlements', (1,)) ENTERPRISE_LEARNER_LIST_ENDPOINT = reverse('enterprise-learner-list') ENTERPRISE_CUSTOMER_WITH_ACCESS_TO_ENDPOINT = reverse('enterprise-customer-with-access-to') @@ -149,84 +146,6 @@ def create_items(self, factory, items): for item in items: factory.create(**item) - @ddt.data( - ( - True, EnterpriseCustomer.AT_ENROLLMENT, True, - [1, 2, 3], {"entitlements": [ - {"entitlement_id": 1, "requires_consent": False}, - {"entitlement_id": 2, "requires_consent": False}, - {"entitlement_id": 3, "requires_consent": False}, - ]}, - ), - ( - True, EnterpriseCustomer.AT_ENROLLMENT, False, - [1, 2, 3], {"entitlements": [ - {"entitlement_id": 1, "requires_consent": True}, - {"entitlement_id": 2, "requires_consent": True}, - {"entitlement_id": 3, "requires_consent": True}, - ]}, - ), - ( - False, EnterpriseCustomer.AT_ENROLLMENT, True, - [1, 2, 3], {"entitlements": [ - {"entitlement_id": 1, "requires_consent": False}, - {"entitlement_id": 2, "requires_consent": False}, - {"entitlement_id": 3, "requires_consent": False}, - ]}, - ), - ( - True, EnterpriseCustomer.AT_ENROLLMENT, None, - [], {"entitlements": []}, - ), - ( - True, EnterpriseCustomer.EXTERNALLY_MANAGED, True, - [1, 2, 3], - {"entitlements": [ - {"entitlement_id": 1, "requires_consent": False}, - {"entitlement_id": 2, "requires_consent": False}, - {"entitlement_id": 3, "requires_consent": False}, - ]}, - ), - ) - @ddt.unpack - def test_enterprise_learner_entitlements( - self, enable_data_sharing_consent, enforce_data_sharing_consent, - learner_consent_state, entitlements, expected_json - ): - """ - Test that entitlement details route on enterprise learner returns correct data. - This test verifies that entitlements returned by entitlement details route on enterprise learner - has the expected behavior as listed down. - 1. Empty entitlements list if enterprise customer requires data sharing consent - (this includes enforcing data sharing consent at login and at enrollment) and enterprise learner - does not consent to share data. - 2. Full list of entitlements for all other cases. - """ - user_id = self.user.id + 1 - enterprise_customer = factories.EnterpriseCustomerFactory( - enable_data_sharing_consent=enable_data_sharing_consent, - enforce_data_sharing_consent=enforce_data_sharing_consent, - ) - user = factories.UserFactory(id=user_id) - ecu = factories.EnterpriseCustomerUserFactory( - user_id=user.id, - enterprise_customer=enterprise_customer, - ) - factories.DataSharingConsentFactory( - username=user.username, - enterprise_customer=enterprise_customer, - granted=learner_consent_state, - ) - for entitlement in entitlements: - factories.EnterpriseCustomerEntitlementFactory( - enterprise_customer=enterprise_customer, - entitlement_id=entitlement, - ) - url = reverse('enterprise-learner-entitlements', (ecu.id, )) - response = self.client.get(settings.TEST_SERVER + url) - response = self.load_json(response.content) - assert sorted(response) == sorted(expected_json) - @override_settings(ECOMMERCE_SERVICE_WORKER_USERNAME=TEST_USERNAME) @mock.patch("enterprise.api.v1.serializers.track_enrollment") @ddt.data( @@ -507,7 +426,7 @@ def test_post_enterprise_customer_user_logged_out(self): 'uuid': FAKE_UUIDS[0], 'name': 'Test Enterprise Customer', 'slug': TEST_SLUG, 'active': True, 'enable_data_sharing_consent': True, 'enforce_data_sharing_consent': 'at_enrollment', - 'branding_configuration': None, 'enterprise_customer_entitlements': [], + 'branding_configuration': None, 'enable_audit_enrollment': False, 'enable_audit_data_reporting': True, 'identity_provider': None, 'replace_sensitive_sso_username': False, 'enable_portal_code_management_screen': False, 'enable_portal_reporting_config_screen': False, @@ -540,7 +459,7 @@ def test_post_enterprise_customer_user_logged_out(self): 'uuid': FAKE_UUIDS[0], 'name': 'Test Enterprise Customer', 'slug': TEST_SLUG, 'active': True, 'enable_data_sharing_consent': True, 'enforce_data_sharing_consent': 'at_enrollment', - 'branding_configuration': None, 'enterprise_customer_entitlements': [], + 'branding_configuration': None, 'enable_audit_enrollment': False, 'identity_provider': None, 'replace_sensitive_sso_username': False, 'enable_portal_code_management_screen': False, 'enable_portal_reporting_config_screen': False, @@ -554,19 +473,6 @@ def test_post_enterprise_customer_user_logged_out(self): } }], ), - ( - factories.EnterpriseCustomerEntitlementFactory, - ENTERPRISE_CUSTOMER_ENTITLEMENT_LIST_ENDPOINT, - itemgetter('enterprise_customer'), - [{ - 'enterprise_customer__uuid': FAKE_UUIDS[0], - 'entitlement_id': 1 - }], - [{ - 'enterprise_customer': FAKE_UUIDS[0], - 'entitlement_id': 1 - }], - ), ( factories.EnterpriseCourseEnrollmentFactory, ENTERPRISE_COURSE_ENROLLMENT_LIST_ENDPOINT, @@ -599,7 +505,7 @@ def test_post_enterprise_customer_user_logged_out(self): 'uuid': FAKE_UUIDS[1], 'name': 'Test Enterprise Customer', 'slug': TEST_SLUG, 'active': True, 'enable_data_sharing_consent': True, 'enforce_data_sharing_consent': 'at_enrollment', - 'branding_configuration': None, 'enterprise_customer_entitlements': [], + 'branding_configuration': None, 'enable_audit_enrollment': False, 'identity_provider': FAKE_UUIDS[0], 'replace_sensitive_sso_username': False, 'enable_portal_code_management_screen': False, 'enable_portal_reporting_config_screen': False, @@ -753,7 +659,7 @@ def test_enterprise_customer_with_access_to( 'uuid': FAKE_UUIDS[0], 'name': 'Test Enterprise Customer', 'slug': TEST_SLUG, 'active': True, 'enable_data_sharing_consent': True, 'enforce_data_sharing_consent': 'at_enrollment', - 'branding_configuration': None, 'enterprise_customer_entitlements': [], + 'branding_configuration': None, 'enable_audit_enrollment': False, 'enable_audit_data_reporting': False, 'identity_provider': None, 'replace_sensitive_sso_username': False, 'enable_portal_code_management_screen': True, 'enable_portal_reporting_config_screen': False, diff --git a/tests/test_models.py b/tests/test_models.py index afff57d1d6..437f356651 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -6,7 +6,6 @@ from __future__ import absolute_import, unicode_literals, with_statement import unittest -from operator import itemgetter import ddt import mock @@ -31,7 +30,6 @@ EnterpriseCustomer, EnterpriseCustomerBrandingConfiguration, EnterpriseCustomerCatalog, - EnterpriseCustomerEntitlement, EnterpriseCustomerReportingConfiguration, EnterpriseCustomerUser, PendingEnterpriseCustomerUser, @@ -395,136 +393,6 @@ def test_get_remote_id(self, provider_id, expected_value, called, mock_third_par else: assert mock_third_party_api.return_value.get_remote_id.call_count == 0 - @ddt.data( - ( - True, - EnterpriseCustomer.AT_ENROLLMENT, - True, - [1, 2, 3], - [ - {"entitlement_id": 1, "requires_consent": False}, - {"entitlement_id": 2, "requires_consent": False}, - {"entitlement_id": 3, "requires_consent": False}, - ], - ), - ( - True, - EnterpriseCustomer.AT_ENROLLMENT, - False, - [1, 2, 3], - [ - {"entitlement_id": 1, "requires_consent": True}, - {"entitlement_id": 2, "requires_consent": True}, - {"entitlement_id": 3, "requires_consent": True}, - ], - ), - ( - True, - EnterpriseCustomer.AT_ENROLLMENT, - None, - [1, 2, 3], - [ - {"entitlement_id": 1, "requires_consent": True}, - {"entitlement_id": 2, "requires_consent": True}, - {"entitlement_id": 3, "requires_consent": True}, - ], - ), - ( - False, - EnterpriseCustomer.AT_ENROLLMENT, - True, - [1, 2, 3], - [ - {"entitlement_id": 1, "requires_consent": False}, - {"entitlement_id": 2, "requires_consent": False}, - {"entitlement_id": 3, "requires_consent": False}, - ], - ), - ( - False, - EnterpriseCustomer.AT_ENROLLMENT, - False, - [1, 2, 3], - [ - {"entitlement_id": 1, "requires_consent": False}, - {"entitlement_id": 2, "requires_consent": False}, - {"entitlement_id": 3, "requires_consent": False}, - ], - ), - ( - False, - EnterpriseCustomer.AT_ENROLLMENT, - None, - [1, 2, 3], - [ - {"entitlement_id": 1, "requires_consent": False}, - {"entitlement_id": 2, "requires_consent": False}, - {"entitlement_id": 3, "requires_consent": False}, - ], - ), - (True, EnterpriseCustomer.AT_ENROLLMENT, True, [], []), - (True, EnterpriseCustomer.AT_ENROLLMENT, False, [], []), - (True, EnterpriseCustomer.AT_ENROLLMENT, None, [], []), - ( - True, - EnterpriseCustomer.EXTERNALLY_MANAGED, - True, - [1, 2, 3], - [ - {"entitlement_id": 1, "requires_consent": False}, - {"entitlement_id": 2, "requires_consent": False}, - {"entitlement_id": 3, "requires_consent": False}, - ], - ), - ) - @ddt.unpack - def test_entitlements( - self, enable_data_sharing_consent, enforce_data_sharing_consent, - learner_consent_state, entitlements, expected_entitlements, - ): - """ - Test that entitlement property on `EnterpriseCustomerUser` returns correct data. - - This test verifies that entitlements returned by entitlement property on `EnterpriseCustomerUser - has the expected behavior as listed down. - 1. Empty entitlements list if enterprise customer requires data sharing consent - (this includes enforcing data sharing consent at login and at enrollment) and enterprise learner - does not consent to share data. - 2. Full list of entitlements for all other cases. - - Arguments: - enable_data_sharing_consent (bool): True if enterprise customer enables data sharing consent, - False it does not. - enforce_data_sharing_consent (str): string for the location at which enterprise customer enforces - data sharing consent, possible values are 'at_enrollment' and 'externally_managed'. - learner_consent_state (bool): the state of learner consent on data sharing, - entitlements (list): A list of integers pointing to voucher ids generated in E-Commerce CAT tool. - expected_entitlements (list): A list of integers pointing to voucher ids expected to be - returned by the model. - """ - enterprise_customer = factories.EnterpriseCustomerFactory( - enable_data_sharing_consent=enable_data_sharing_consent, - enforce_data_sharing_consent=enforce_data_sharing_consent, - ) - user = factories.UserFactory(id=1) - enterprise_customer_user = factories.EnterpriseCustomerUserFactory( - user_id=user.id, - enterprise_customer=enterprise_customer, - ) - factories.DataSharingConsentFactory( - username=enterprise_customer_user.username, - enterprise_customer=enterprise_customer, - granted=learner_consent_state, - ) - for entitlement in entitlements: - factories.EnterpriseCustomerEntitlementFactory( - enterprise_customer=enterprise_customer, - entitlement_id=entitlement, - ) - - assert sorted(enterprise_customer_user.entitlements, key=itemgetter('entitlement_id')) == \ - sorted(expected_entitlements, key=itemgetter('entitlement_id')) - @mock.patch('enterprise.utils.segment') @mock.patch('enterprise.models.EnrollmentApiClient') def test_enroll_learner(self, enrollment_api_client_mock, analytics_mock, *args): # pylint: disable=unused-argument @@ -797,31 +665,6 @@ def test_provider_name(self, mock_method): assert ec_idp.provider_name == provider_name -@mark.django_db -@ddt.ddt -class TestEnterpriseCustomerEntitlements(unittest.TestCase): - """ - Tests of the TestEnterpriseCustomerEntitlements model. - """ - @ddt.data(str, repr) - def test_string_conversion(self, method): - """ - Test ``TestEnterpriseCustomerEntitlements`` conversion to string. - """ - entitlement_id, enterprise_customer_name = 1234, "TestShib" - enterprise_customer = factories.EnterpriseCustomerFactory(name=enterprise_customer_name) - ec_entitlements = EnterpriseCustomerEntitlement( - enterprise_customer=enterprise_customer, - entitlement_id=entitlement_id, - ) - - expected_to_str = "".format( - customer=enterprise_customer, - id=entitlement_id, - ) - self.assertEqual(method(ec_entitlements), expected_to_str) - - @mark.django_db @ddt.ddt class TestEnterpriseCustomerCatalog(unittest.TestCase): diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 87cd43d4fe..314501d9ca 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -81,7 +81,6 @@ def setUp(self): "pendingenterprisecustomeruser", "branding_configuration", "enterprise_customer_identity_provider", - "enterprise_customer_entitlements", "enterprise_customer_catalogs", "enterprise_enrollment_template", "reporting_configurations",