Exemplo n.º 1
0
def test_register_clean():
    register_models.register_clean([
        (User, register_models.AnonymBase),
        (Permission, register_models.AnonymBase(truncate=True)),
        (Group, register_models.AnonymBase())
    ])

    assert len(Anonymizer.clean_models) == 3
    assert len(Anonymizer.skip_models) == 0
    assert len(Anonymizer.anonym_models) == 0

    assert 'django.contrib.auth.models.User' in \
        Anonymizer.clean_models.keys()
    assert 'django.contrib.auth.models.Permission' in \
        Anonymizer.clean_models.keys()
    assert 'django.contrib.auth.models.Group' in \
        Anonymizer.clean_models.keys()

    assert isinstance(
        Anonymizer.clean_models['django.contrib.auth.models.User'], QuerySet)
    assert isinstance(
        Anonymizer.clean_models['django.contrib.auth.models.Permission'],
        QuerySet)
    assert isinstance(
        Anonymizer.clean_models['django.contrib.auth.models.Group'], QuerySet)

    assert Anonymizer.clean_models[
        "django.contrib.auth.models.User"].model is User
    assert Anonymizer.clean_models[
        "django.contrib.auth.models.Permission"].model is Permission
    assert Anonymizer.clean_models[
        "django.contrib.auth.models.Group"].model is Group
Exemplo n.º 2
0
def test_register_clean_duplicate():
    with pytest.raises(ValueError):
        register_models.register_clean([
            (User, register_models.AnonymBase),
            (User, register_models.AnonymBase),
            (Permission, register_models.AnonymBase(truncate=True)),
            (Group, register_models.AnonymBase())
        ])
Exemplo n.º 3
0
def test_register_clean_only():
    register_models.register_clean([
        (User, register_models.AnonymBase),
        (Permission, register_models.AnonymBase(truncate=True)),
        (Group, register_models.AnonymBase())
    ])
    Anonymizer(only='django.contrib.auth.models.Group')

    with pytest.raises(LookupError):
        Anonymizer(only='django.contrib.auth.models.WrongGroup')
def test_register_clean(mocker):
    clean_mock = mock.MagicMock()
    mocker.patch('dj_anonymizer.anonymizer.Anonymizer.clean_models',
                 clean_mock)
    register_models.register_clean([
        (User, register_models.AnonymBase),
        (Permission, register_models.AnonymBase(truncate=True)),
        (Group, register_models.AnonymBase())
    ])

    assert clean_mock._mock_mock_calls[0][1][0] == \
        'django.contrib.auth.models.User'
    assert isinstance(clean_mock._mock_mock_calls[0][1][1], QuerySet)
    assert clean_mock._mock_mock_calls[0][1][1].truncate is False
    assert clean_mock._mock_mock_calls[1][1][0] == \
        'django.contrib.auth.models.Permission'
    assert isinstance(clean_mock._mock_mock_calls[1][1][1], QuerySet)
    assert clean_mock._mock_mock_calls[1][1][1].truncate is True
    assert clean_mock._mock_mock_calls[2][1][1].truncate is False
    assert clean_mock._mock_mock_calls[2][1][0] == \
        'django.contrib.auth.models.Group'
    assert isinstance(clean_mock._mock_mock_calls[2][1][1], QuerySet)
Exemplo n.º 5
0
from dj_anonymizer.register_models import register_clean

from notes.models import UserNote, ChapterNote

register_clean([UserNote, ChapterNote])
Exemplo n.º 6
0
    is_staff = fields.function(lambda: False)

    class Meta:
        exclude_fields = ['is_active', 'is_superuser',
                          'last_login', 'date_joined']


class GroupAnonym(AnonymBase):
    name = fields.string('group_{seq}')

    class Meta:
        pass


register_anonym([
    (User, UserAnonym),
    (Group, GroupAnonym),
])


register_clean([
    (Session, AnonymBase),
    (LogEntry, AnonymBase(truncate=True)),
])

register_skip([
    ContentType,
    Permission,
    Session,
])
Exemplo n.º 7
0
from dj_anonymizer.register_models import register_skip, register_clean

from herald.models import SentNotification, UserNotification, Notification

register_skip([UserNotification, Notification])

# This stores a complete message sent to users
register_clean([SentNotification])
Exemplo n.º 8
0
    InitiationProcess,
    OSM,
    Pledge,
    PledgeProcess,
    PledgeProgram,
    PrematureAlumnus,
    ResignationProcess,
    ReturnStudent,
    RiskManagement,
    StatusChange,
    PledgeProgramProcess,
)

fake = Factory.create()

register_clean([DisciplinaryAttachment])

register_skip([
    Audit,
    Badge,
    ChapterReport,
    Depledge,
    Guard,
    InitiationProcess,
    OSM,
    PledgeProcess,
    PledgeProgram,
    ReturnStudent,
    PledgeProgramProcess,
])
Exemplo n.º 9
0
from dj_anonymizer.register_models import register_clean

from watson.models import SearchEntry

register_clean([SearchEntry])
Exemplo n.º 10
0
def test_register_clean_none():
    with pytest.raises(TypeError):
        register_models.register_clean([(User, register_models.AnonymBase),
                                        (Permission, None)])
Exemplo n.º 11
0
def test_register_clean_mixed_args():
    with pytest.raises(TypeError):
        register_models.register_clean([(User, register_models.AnonymBase),
                                        (register_models.AnonymBase,
                                         Permission)])
Exemplo n.º 12
0
from dj_anonymizer.register_models import register_clean

from ballots.models import Ballot, BallotComplete

# Just clean for now, not really using ballots
register_clean([Ballot, BallotComplete])
Exemplo n.º 13
0
    UserSemesterGPA,
)

fake = Factory.create()

register_skip(
    [
        UserAlter,
        UserStatusChange,
        UserSemesterServiceHours,
        UserDemographic,
        UserSemesterGPA,
    ]
)

register_clean([UserRoleChange, UserOrgParticipate])


class UserAnonym(AnonymBase):
    password = anonym_field.password("test")
    user_id = anonym_field.string("FAKE{seq}")
    email_school = anonym_field.string("{seq}[email protected]")
    email = anonym_field.string("{seq}@thetatau.org")
    username = anonym_field.string("{seq}@thetatau.org")
    middle_name = anonym_field.function(fake.first_name)
    preferred_name = anonym_field.function(fake.first_name)
    first_name = anonym_field.function(fake.first_name)
    last_name = anonym_field.function(fake.last_name)
    maiden_name = anonym_field.function(fake.last_name)
    nickname = anonym_field.function(fake.first_name)
    suffix = anonym_field.function(fake.suffix)
Exemplo n.º 14
0
from dj_anonymizer.register_models import register_clean

from finances.models import Invoice

register_clean([Invoice])
Exemplo n.º 15
0
from dj_anonymizer.register_models import (
    register_skip,
    AnonymBase,
    register_anonym,
    register_clean,
)
from dj_anonymizer import anonym_field
from faker import Factory

from allauth.socialaccount.models import SocialToken, SocialAccount, SocialApp
from allauth.account.models import EmailConfirmation, EmailAddress

register_skip([EmailConfirmation, SocialToken, SocialApp])
register_clean([SocialAccount])

fake = Factory.create()


class EmailAddressAnonym(AnonymBase):
    email = anonym_field.string("{seq}@thetatau.org")
    verified = anonym_field.function(lambda: True)

    class Meta:
        exclude_fields = ["primary"]


register_anonym([
    (EmailAddress, EmailAddressAnonym),
])