Skip to content

Commit

Permalink
Resolve merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
radiac committed Jul 1, 2020
1 parent 67850f5 commit 9626539
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
17 changes: 10 additions & 7 deletions gdpr_assist/models.py
@@ -1,21 +1,22 @@
"""
Model-related functionality
"""
from copy import copy
import six
import sys
from copy import copy

from django.apps import apps
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _

import six

from . import app_settings
from . import handlers # noqa
from . import app_settings
from .anonymiser import anonymise_field, anonymise_related_objects
from .signals import pre_anonymise, post_anonymise
from .signals import post_anonymise, pre_anonymise


class PrivacyQuerySet(models.query.QuerySet):
Expand All @@ -32,7 +33,9 @@ def anonymise(self, for_bulk=True):

bulk_objects = []
for obj in self:
bulk_objects.append(obj.anonymise(for_bulk=for_bulk))
privacy_obj = obj.anonymise(for_bulk=for_bulk)
if privacy_obj:
bulk_objects.append(privacy_obj)

if bulk_objects and for_bulk:
PrivacyAnonymised.objects.bulk_create(bulk_objects)
Expand Down Expand Up @@ -209,7 +212,7 @@ def get_privacy_meta(cls):
def check_can_anonymise(cls):
return cls.get_privacy_meta().can_anonymise

def anonymise(self, force=False):
def anonymise(self, force=False, for_bulk=False):
privacy_meta = self.get_privacy_meta()

# Only anonymise if allowed
Expand Down
25 changes: 12 additions & 13 deletions tests/test_admin.py
@@ -1,9 +1,9 @@
"""
Test admin tools
"""
from io import BytesIO, TextIOWrapper
import csv
import zipfile
from io import BytesIO, TextIOWrapper

import django
from django.contrib.auth.models import User
Expand All @@ -15,10 +15,12 @@
import gdpr_assist

from .gdpr_assist_tests_app.models import (
ModelWithPrivacyMeta,
FirstSearchModel,
ForthSearchModel,
ModelWithPrivacyMeta,
ModelWithPrivacyMetaCanNotAnonymise,
SecondSearchModel,
ModelWithPrivacyMetaCanNotAnonymise, ForthSearchModel)
)


model_root_url = '/admin/gdpr_assist_tests_app/modelwithprivacymeta/'
Expand Down Expand Up @@ -141,8 +143,8 @@ def test_anonymise_action_submit__can_anonymise_disabled__404(self):
self.assertEqual(response.status_code, 404)

def test_anonymise_view_submit__can_anonymise_disabled__404(self):
obj_1 = mommy.make(ModelWithPrivacyMetaCanNotAnonymise, anonymised=False)
obj_2 = mommy.make(ModelWithPrivacyMetaCanNotAnonymise, anonymised=False)
obj_1 = mommy.make(ModelWithPrivacyMetaCanNotAnonymise)
obj_2 = mommy.make(ModelWithPrivacyMetaCanNotAnonymise)

response = self.client.post(
'/admin/gdpr_assist_tests_app/modelwithprivacymetacannotanonymise/anonymise/',
Expand All @@ -156,8 +158,8 @@ def test_anonymise_view_submit__can_anonymise_disabled__404(self):

obj_1.refresh_from_db()
obj_2.refresh_from_db()
self.assertFalse(obj_1.anonymised)
self.assertFalse(obj_2.anonymised)
self.assertFalse(obj_1.is_anonymised())
self.assertFalse(obj_2.is_anonymised())


class TestAdminTool(AdminTestCase):
Expand Down Expand Up @@ -231,12 +233,11 @@ def test_anonymise____can_anonymise_disabled__not_all_records_anonymised(self):
obj_1 = mommy.make(
FirstSearchModel,
email='an@example.com',
anonymised=False,
)
obj_1.anonymise()
obj_4 = mommy.make(
ForthSearchModel,
email='an@example.com',
anonymised=False,
)
content_type_1 = ContentType.objects.get_for_model(FirstSearchModel).pk
content_type_4 = ContentType.objects.get_for_model(ForthSearchModel).pk
Expand All @@ -256,8 +257,8 @@ def test_anonymise____can_anonymise_disabled__not_all_records_anonymised(self):

obj_1.refresh_from_db()
obj_4.refresh_from_db()
self.assertTrue(obj_1.anonymised)
self.assertFalse(obj_4.anonymised)
self.assertTrue(obj_1.is_anonymised())
self.assertFalse(obj_4.is_anonymised())

if django.VERSION <= (1, 9):
# Django 1.8 support - redirects include host
Expand All @@ -275,7 +276,6 @@ def test_warn_will_not_anonymise__present(self):
mommy.make(
ForthSearchModel,
email='an@example.com',
anonymised=False,
)

response = self.client.post(tool_root_url, {'term': 'an@example.com'})
Expand All @@ -291,7 +291,6 @@ def test_warn_will_not_anonymise__not_present(self):
mommy.make(
FirstSearchModel,
email='an@example.com',
anonymised=False,
)

response = self.client.post(tool_root_url, {'term': 'an@example.com'})
Expand Down
2 changes: 1 addition & 1 deletion tests/test_anonymisation.py
Expand Up @@ -841,7 +841,7 @@ def test_foreignkey_delete__can_anonymise_disabled__anonymise_not_propagated(sel

target.delete()
obj.refresh_from_db()
self.assertFalse(obj.anonymised)
self.assertFalse(obj.is_anonymised())
self.assertEqual(obj.chars, 'Test')


Expand Down
14 changes: 9 additions & 5 deletions tests/test_commands.py
@@ -1,14 +1,19 @@
"""
Test management commands
"""
import six
import sys
from io import StringIO

from django.core.management import call_command
from django.test import TestCase

from .gdpr_assist_tests_app.models import ModelWithPrivacyMeta, ModelWithPrivacyMetaCanNotAnonymise
import six

from .gdpr_assist_tests_app.models import (
ModelWithPrivacyMeta,
ModelWithPrivacyMetaCanNotAnonymise,
)


# If True, display output from call_command - use for debugging tests
DISPLAY_CALL_COMMAND = False
Expand Down Expand Up @@ -89,13 +94,12 @@ def test_anonymise_command__does_notanonymises_data(self):
obj_1 = ModelWithPrivacyMetaCanNotAnonymise.objects.create(
chars='test',
email='test@example.com',
anonymised=False,
)
self.assertFalse(obj_1.anonymised)
self.assertFalse(obj_1.is_anonymised())
self.run_command('anonymise_db', interactive=False)

obj_1.refresh_from_db()
self.assertFalse(obj_1.anonymised)
self.assertFalse(obj_1.is_anonymised())


class TestRerunCommand(CommandTestCase):
Expand Down

0 comments on commit 9626539

Please sign in to comment.