def test_set_policy_match_site_over_mode(self): """ Verify that, when both a mode-agnostic policy matching the site of a created entitlement and a site-agnostic policy matching the mode of a created entitlement exist but no policy matching both the site and mode of the created entitlement exists, the site-specific (mode-agnostic) policy matching the entitlement is selected over the mode-specific (site-agnostic) policy. """ course_uuid = uuid.uuid4() entitlement_data = self._get_data_set(self.user, str(course_uuid)) self.client.post( self.entitlements_list_url, data=json.dumps(entitlement_data), content_type='application/json', ) course_entitlement = CourseEntitlement.objects.get( user=self.user, course_uuid=course_uuid ) policy_site = SiteFactory.create() policy = CourseEntitlementPolicy.objects.create(mode=None, site=policy_site) CourseEntitlementPolicy.objects.create(mode=entitlement_data['mode'], site=None) set_entitlement_policy(course_entitlement, policy_site) assert course_entitlement.policy == policy
def test_set_policy_site_and_mode_specific(self): """ Verify that, when there exists a policy matching both the mode and site of the a given course entitlement, it is selected over appropriate site- and mode-specific (mode- and site-agnostic) policies and the default policy for assignment to the entitlement. """ course_uuid = uuid.uuid4() entitlement_data = self._get_data_set(self.user, str(course_uuid)) entitlement_data['mode'] = CourseMode.PROFESSIONAL self.client.post( self.entitlements_list_url, data=json.dumps(entitlement_data), content_type='application/json', ) course_entitlement = CourseEntitlement.objects.get( user=self.user, course_uuid=course_uuid ) policy_site = SiteFactory.create() policy = CourseEntitlementPolicy.objects.create(mode=entitlement_data['mode'], site=policy_site) CourseEntitlementPolicy.objects.create(mode=entitlement_data['mode'], site=None) CourseEntitlementPolicy.objects.create(mode=None, site=policy_site) set_entitlement_policy(course_entitlement, policy_site) assert course_entitlement.policy == policy
def test_set_custom_site_policy_on_create(self): """ Verify that, when there does not exist a course entitlement policy with the same mode and site as a created entitlement, but there does exist a policy with the same site and a null mode, that policy is assigned to the entitlement. """ course_uuid = uuid.uuid4() entitlement_data = self._get_data_set(self.user, str(course_uuid)) self.client.post( self.entitlements_list_url, data=json.dumps(entitlement_data), content_type='application/json', ) course_entitlement = CourseEntitlement.objects.get( user=self.user, course_uuid=course_uuid) policy_site = SiteFactory.create() policy = CourseEntitlementPolicy.objects.create(mode=None, site=policy_site) set_entitlement_policy(course_entitlement, policy_site) assert course_entitlement.policy == policy