def update_dsc_cache_on_course_enrollment(sender, instance, **kwargs): # pylint: disable=unused-argument """ clears data_sharing_consent_needed cache after Enterprise Course Enrollment """ clear_data_consent_share_cache( instance.enterprise_customer_user.user_id, instance.course_id, str(instance.enterprise_customer_user.enterprise_customer.uuid))
def test_consent_needed_for_course(self): user = UserFactory(username='******') request = mock.MagicMock(session={}, user=user, site=SiteFactory(domain="example.com")) ec_uuid = 'cf246b88-d5f6-4908-a522-fc307e0b0c59' course_id = 'fake-course' self.mock_enterprise_learner_api() # test not required consent for example non enterprise customer self.mock_consent_not_required(user.username, course_id, ec_uuid) self.assertFalse(consent_needed_for_course(request, user, course_id)) # test required and missing consent for example now he becomes a enterprise customer self.mock_consent_missing(user.username, course_id, ec_uuid) # still result should be False as it has been stored in cache "Not to show consent", so it will confirm that # cache is working fine self.assertFalse(consent_needed_for_course(request, user, course_id)) # Removing cache clear_data_consent_share_cache(user.id, course_id) # Now test again self.assertTrue(consent_needed_for_course(request, user, course_id)) # test after consent permission is granted self.mock_consent_get(user.username, course_id, ec_uuid) self.assertFalse(consent_needed_for_course(request, user, course_id))
def update_data_consent_share_cache(sender, instance, **kwargs): # pylint: disable=unused-argument """ clears data_sharing_consent_needed cache after Enterprise Course Enrollment """ clear_data_consent_share_cache( instance.enterprise_customer_user.user_id, instance.course_id )
def test_clear_data_consent_share_cache(self, mock_tiered_cache, mock_get_cache_key): user_id = 'some-user-id' course_id = 'some-course-id' clear_data_consent_share_cache(user_id, course_id) mock_get_cache_key.assert_called_once_with( type='data_sharing_consent_needed', user_id='some-user-id', course_id='some-course-id', ) mock_tiered_cache.delete_all_tiers.assert_called_once_with(mock_get_cache_key.return_value)
def test_clear_data_consent_share_cache(self, mock_tiered_cache, mock_get_cache_key): user_id = 'some-user-id' course_id = 'some-course-id' enterprise_customer_uuid = '1a9cae8f-abb7-4336-b075-6ff32ecf73de' clear_data_consent_share_cache(user_id, course_id, enterprise_customer_uuid) mock_get_cache_key.assert_called_once_with( type='data_sharing_consent_needed', user_id='some-user-id', course_id='some-course-id', enterprise_customer_uuid=enterprise_customer_uuid ) mock_tiered_cache.delete_all_tiers.assert_called_once_with(mock_get_cache_key.return_value)
def clear_enterprise_customer_data_consent_share_cache( enterprise_customer_uuid): """ clears data_sharing_consent_needed cache for whole enterprise """ enterprise_course_enrollments = EnterpriseCourseEnrollment.objects.filter( enterprise_customer_user__enterprise_customer__uuid= enterprise_customer_uuid) count = enterprise_course_enrollments.count() log.info( u'Stated Clearing {count} data_sharing_consent_needed cache for enterprise customer {uuid}' .format( count=count, uuid=enterprise_customer_uuid, )) for enrollment in enterprise_course_enrollments: clear_data_consent_share_cache( enrollment.enterprise_customer_user.user_id, enrollment.course_id) log.info( u'Ended Clearing data_sharing_consent_needed cache for enterprise customer {uuid}' .format(uuid=enterprise_customer_uuid, ))
def clear_enterprise_customer_data_consent_share_cache(enterprise_customer_uuid): """ clears data_sharing_consent_needed cache for whole enterprise """ enterprise_course_enrollments = EnterpriseCourseEnrollment.objects.filter( enterprise_customer_user__enterprise_customer__uuid=enterprise_customer_uuid ) count = enterprise_course_enrollments.count() log.info( u'Stated Clearing {count} data_sharing_consent_needed cache for enterprise customer {uuid}'.format( count=count, uuid=enterprise_customer_uuid, ) ) for enrollment in enterprise_course_enrollments: clear_data_consent_share_cache( enrollment.enterprise_customer_user.user_id, enrollment.course_id ) log.info(u'Ended Clearing data_sharing_consent_needed cache for enterprise customer {uuid}'.format( uuid=enterprise_customer_uuid, ))
def test_consent_needed_for_course(self): user = UserFactory(username='******') request = mock.MagicMock(session={}, user=user) ec_uuid = 'cf246b88-d5f6-4908-a522-fc307e0b0c59' course_id = 'fake-course' self.mock_enterprise_learner_api() # test not required consent for example non enterprise customer self.mock_consent_not_required(user.username, course_id, ec_uuid) self.assertFalse(consent_needed_for_course(request, user, course_id)) # test required and missing consent for example now he becomes a enterprise customer self.mock_consent_missing(user.username, course_id, ec_uuid) # still result should be False as it has been stored in cache "Not to show consent", so it will confirm that # cache is working fine self.assertFalse(consent_needed_for_course(request, user, course_id)) # Removing cache clear_data_consent_share_cache(user.id, course_id) # Now test again self.assertTrue(consent_needed_for_course(request, user, course_id)) # test after consent permission is granted self.mock_consent_get(user.username, course_id, ec_uuid) self.assertFalse(consent_needed_for_course(request, user, course_id))
def test_consent_needed_for_course(self, mock_get_enterprise_learner_data): user = UserFactory(username='******') request = mock.MagicMock( user=user, site=SiteFactory(domain="example.com"), session={}, COOKIES={}, GET={}, ) ec_uuid = 'cf246b88-d5f6-4908-a522-fc307e0b0c59' course_id = 'fake-course' mock_get_enterprise_learner_data.return_value = self.get_mock_enterprise_learner_results() self.mock_enterprise_learner_api() # test that consent is not required for a non-enterprise customer self.mock_consent_not_required(user.username, course_id, ec_uuid) assert not consent_needed_for_course(request, user, course_id) # test required and missing consent for example now he becomes a enterprise customer self.mock_consent_missing(user.username, course_id, ec_uuid) # still result should be False as it has been stored in cache "Not to show consent", so it will confirm that # cache is working fine assert not consent_needed_for_course(request, user, course_id) # Removing cache clear_data_consent_share_cache(user.id, course_id, ec_uuid) # Now test again assert consent_needed_for_course(request, user, course_id) # test after consent permission is granted self.mock_consent_get(user.username, course_id, ec_uuid) assert not consent_needed_for_course(request, user, course_id) # test when the enrollment already exists without a consent record existing. clear_data_consent_share_cache(user.id, course_id, ec_uuid) self.mock_consent_missing(user.username, course_id, ec_uuid) assert not consent_needed_for_course(request, user, course_id, enrollment_exists=True)