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 test_consent_needed_for_course(self): user = UserFactory(username='******') request = mock.MagicMock(session={}, user=user) self.mock_enterprise_learner_api() self.mock_consent_missing(user.username, 'fake-course', 'cf246b88-d5f6-4908-a522-fc307e0b0c59') self.assertTrue(consent_needed_for_course(request, user, 'fake-course')) self.mock_consent_get(user.username, 'fake-course', 'cf246b88-d5f6-4908-a522-fc307e0b0c59') self.assertFalse(consent_needed_for_course(request, user, 'fake-course')) # Test that the result is cached when false (remove the HTTP mock so if the result # isn't cached, we'll fail spectacularly.) httpretty.reset() self.assertFalse(consent_needed_for_course(request, user, 'fake-course'))
def test_consent_needed_for_course(self): user = mock.MagicMock( username='******', is_authenticated=lambda: True, ) request = mock.MagicMock(session={}, user=user) self.mock_enterprise_learner_api() self.mock_consent_missing(user.username, 'fake-course', 'cf246b88-d5f6-4908-a522-fc307e0b0c59') self.assertTrue(consent_needed_for_course(request, user, 'fake-course')) self.mock_consent_get(user.username, 'fake-course', 'cf246b88-d5f6-4908-a522-fc307e0b0c59') self.assertFalse(consent_needed_for_course(request, user, 'fake-course')) # Test that the result is cached when false (remove the HTTP mock so if the result # isn't cached, we'll fail spectacularly.) httpretty.reset() self.assertFalse(consent_needed_for_course(request, user, 'fake-course'))
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)
def test_consent_needed_for_course_no_learner_data(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 = None 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)