コード例 #1
0
    def test_mixin_reject_policy(self):
        """Testing CheckPendingConsentMixin when the user has rejected the
        policy requirement
        """
        policy_requirement = PolicyConsentRequirement(
            'https://example.com/',
            'https://example.com/',
            reject_instructions='Obey.')

        self.registry.register(policy_requirement)

        request = self.request_factory.get('/')
        request.user = User.objects.create_user(username='******',
                                                email='*****@*****.**')

        get_consent_tracker().record_consent_data_list(request.user, [
            ConsentData(BenevolentConsentRequirement.requirement_id,
                        granted=True),
            ConsentData(NefariousConsentRequirement.requirement_id,
                        granted=False),
            policy_requirement.build_consent_data(granted=False),
        ])

        rsp = MixinView.as_view()(request)

        self.assertIsInstance(rsp, HttpResponseRedirect)
        self.assertEqual(rsp.url, '/consent')
コード例 #2
0
    def test_record_consent_data_list(self):
        """Testing DatabaseConsentTracker.record_consent_data_list"""
        consent_data_1 = ConsentData(
            requirement_id='test-requirement-1',
            granted=True,
            source='http://example.com/account/profile/#consent',
            extra_data={
                'test': True,
            })

        consent_data_2 = ConsentData(
            requirement_id='test-requirement-2',
            granted=False,
            source='http://example.com/account/profile/#consent')

        self.tracker.record_consent_data_list(self.user,
                                              [consent_data_1, consent_data_2])

        stored_consents = list(StoredConsentData.objects.all())
        self.assertEqual(len(stored_consents), 1)

        stored_consent = stored_consents[0]
        self.assertEqual(stored_consent.user, self.user)
        self.assertEqual(stored_consent.audit_identifier,
                         '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69'
                         '824a89ea65dba4e813b')
        self.assertEqual(stored_consent.time_added, self.timestamp)
        self.assertEqual(stored_consent.last_updated, self.timestamp)
        self.assertEqual(
            stored_consent.consent_grants,
            {
                'test-requirement-1': True,
                'test-requirement-2': False,
            })
        self.assertEqual(
            stored_consent.audit_trail,
            {
                'test-requirement-1': [{
                    'identifier': '973dfe463ec85785f5f95af5ba3906eedb2d931c2'
                                  '4e69824a89ea65dba4e813b',
                    'granted': True,
                    'timestamp': '2018-01-02T13:14:15+00:00',
                    'source': 'http://example.com/account/profile/#consent',
                    'extra_data': {
                        'test': True,
                    },
                }],
                'test-requirement-2': [{
                    'identifier': '973dfe463ec85785f5f95af5ba3906eedb2d931c2'
                                  '4e69824a89ea65dba4e813b',
                    'granted': False,
                    'timestamp': '2018-01-02T13:14:15+00:00',
                    'source': 'http://example.com/account/profile/#consent',
                }],
            })
コード例 #3
0
    def test_serialize_audit_info_with_minimum_data(self):
        """Testing ConsentData.serialize_audit_info with minimum required data
        """
        consent_data = ConsentData(
            requirement_id='test-requirement',
            granted=False,
            timestamp=datetime(2018, 1, 2, 13, 14, 15, tzinfo=timezone.utc))

        self.assertEqual(
            consent_data.serialize_audit_info('123:[email protected]'),
            {
                'identifier': '123:[email protected]',
                'granted': False,
                'timestamp': '2018-01-02T13:14:15+00:00',
            })
コード例 #4
0
    def test_for_user_with_consent_checks_and_consent_granted(self):
        """Testing AvatarServiceRegistry.for_user with consent checks enabled
        and consent granted
        """
        class DummyAvatarServiceRegistry(AvatarServiceRegistry):
            settings_manager_class = DummySettingsManager(
                GravatarService.avatar_service_id, {})
            default_avatar_service_classes = [
                GravatarService,
                DummyAvatarService,
            ]

        registry = DummyAvatarServiceRegistry()
        registry.enable_service(GravatarService, save=False)
        registry.enable_service(DummyAvatarService, save=False)
        registry.set_default_service(DummyAvatarService, save=False)

        user = User.objects.create(username='******')

        settings = {
            AvatarServiceRegistry.ENABLE_CONSENT_CHECKS: True,
        }

        get_consent_tracker().record_consent_data(
            user,
            ConsentData(requirement_id=GravatarService.consent_requirement_id,
                        granted=True))

        with self.siteconfig_settings(settings):
            self.assertIsInstance(registry.for_user(user), GravatarService)
コード例 #5
0
    def test_record_consent_data_list_clears_cache(self):
        """Testing DatabaseConsentTracker.record_consent_data_list clears cache
        """
        consent_data_1 = ConsentData(requirement_id='test-requirement-1',
                                     granted=True)
        consent_data_2 = ConsentData(requirement_id='test-requirement-2',
                                     granted=False)

        cache_key = make_cache_key('privacy-consent:%s' % self.user.pk)
        cache.add(cache_key, ['test-requirement-1'])

        self.assertEqual(cache.get(cache_key), ['test-requirement-1'])

        self.tracker.record_consent_data_list(self.user,
                                              [consent_data_1, consent_data_2])

        self.assertIsNone(cache.get(cache_key))
コード例 #6
0
    def test_mixin_all_met(self):
        """Testing CheckPendingConsentMixin when a user has no pending consent
        decisions
        """
        request = self.request_factory.get('/')
        request.user = User.objects.create_user(username='******',
                                                email='*****@*****.**')

        get_consent_tracker().record_consent_data_list(request.user, [
            ConsentData(BenevolentConsentRequirement.requirement_id,
                        granted=True),
            ConsentData(NefariousConsentRequirement.requirement_id,
                        granted=False),
        ])

        rsp = MixinView.as_view()(request)

        self.assertNotIsInstance(rsp, HttpResponseRedirect)
        self.assertIsInstance(rsp, HttpResponse)
        self.assertEqual(rsp.content, b'ok')
コード例 #7
0
    def test_serialize_audit_info_with_all_data(self):
        """Testing ConsentData.serialize_audit_info with all data"""
        consent_data = ConsentData(
            requirement_id='test-requirement',
            granted=True,
            timestamp=datetime(2018, 1, 2, 13, 14, 15, tzinfo=timezone.utc),
            source='http://example.com/account/profile/#consent',
            extra_data={
                'test': True,
            })

        self.assertEqual(
            consent_data.serialize_audit_info('123:[email protected]'),
            {
                'identifier': '123:[email protected]',
                'granted': True,
                'timestamp': '2018-01-02T13:14:15+00:00',
                'source': 'http://example.com/account/profile/#consent',
                'extra_data': {
                    'test': True,
                },
            })
コード例 #8
0
    def test_parse_audit_info_with_minimum_data(self):
        """Testing ConsentData.parse_audit_info with minimum required data"""
        consent_data = ConsentData.parse_audit_info('test-requirement', {
            'granted': False,
            'timestamp': '2018-01-02T13:14:15+00:00',
        })

        self.assertEqual(consent_data.requirement_id, 'test-requirement')
        self.assertFalse(consent_data.granted)
        self.assertEqual(consent_data.timestamp,
                         datetime(2018, 1, 2, 13, 14, 15, tzinfo=timezone.utc))
        self.assertIsNone(consent_data.source)
        self.assertIsNone(consent_data.extra_data)
コード例 #9
0
    def test_mixin_some_met(self):
        """Testing CheckPendingConsentMixin when a user has some pending
        consent decisions
        """
        request = self.request_factory.get('/')
        request.user = User.objects.create_user(username='******',
                                                email='*****@*****.**')

        get_consent_tracker().record_consent_data(
            request.user,
            ConsentData(BenevolentConsentRequirement.requirement_id,
                        granted=True))

        rsp = MixinView.as_view()(request)

        self.assertIsInstance(rsp, HttpResponseRedirect)
        self.assertEqual(rsp.url, '/consent')
コード例 #10
0
    def test_get_consent(self):
        """Testing BaseConsentRequirement.get_consent"""
        requirement = MyConsentRequirement()
        timestamp = datetime(2018, 1, 2, 13, 14, 15, tzinfo=timezone.utc)
        user = User.objects.create(username='******')

        consent_data = ConsentData(
            requirement_id='my-requirement',
            granted=True,
            timestamp=timestamp,
            source='http://example.com/account/profile/#consent',
            extra_data={
                'test': True,
            })

        get_consent_tracker().record_consent_data(user, consent_data)

        self.assertEqual(requirement.get_consent(user), Consent.GRANTED)
コード例 #11
0
    def test_parse_audit_info_with_all_data(self):
        """Testing ConsentData.parse_audit_info with all data"""
        consent_data = ConsentData.parse_audit_info('test-requirement', {
            'granted': True,
            'timestamp': '2018-01-02T13:14:15+00:00',
            'source': 'http://example.com/account/profile/#consent',
            'extra_data': {
                'test': True,
            },
        })

        self.assertEqual(consent_data.requirement_id, 'test-requirement')
        self.assertTrue(consent_data.granted)
        self.assertEqual(consent_data.timestamp,
                         datetime(2018, 1, 2, 13, 14, 15, tzinfo=timezone.utc))
        self.assertEqual(consent_data.source,
                         'http://example.com/account/profile/#consent')
        self.assertEqual(
            consent_data.extra_data,
            {
                'test': True,
            })