Skip to content

Commit

Permalink
align default settings and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
lociii committed Sep 10, 2024
1 parent 47529d4 commit d9a7c4d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,58 +251,68 @@ SCRUBBER_GLOBAL_SCRUBBERS = {
The seed used when generating random content by the Faker scrubber. Setting this to `None` means each scrubbing will
generate different data.

(default: 42)
(default: `42`)

### `SCRUBBER_ENTRIES_PER_PROVIDER`:

Number of entries to use as source for Faker scrubber. Increasing this value will increase the randomness of generated
data, but decrease performance.

(default: 1000)
(default: `1000`)

### `SCRUBBER_SKIP_UNMANAGED`:

Do not attempt to scrub models which are not managed by the ORM.

(default: True)
(default: `True`)

### `SCRUBBER_APPS_LIST`:

Only scrub models belonging to these specific django apps. If unset, will scrub all installed apps.

(default: None)
(default: `None`)

### `SCRUBBER_ADDITIONAL_FAKER_PROVIDERS`:

Add additional fake providers to be used by Faker. Must be noted as full dotted path to the provider class.

(default: empty list)
(default: `{*()}`, empty set)

### `SCRUBBER_FAKER_LOCALE`:

Set an alternative locale for Faker used during the scrubbing process.

(default: None, falls back to Django's default locale)
(default: `None`, falls back to Django's default locale)

### `SCRUBBER_MAPPING`:

Define a class and a mapper which does not have to live inside the given model. Useful, if you have no control over the
models code you'd like to scrub.

````python
SCRUBBER_MAPPING = {
"auth.User": "my_app.scrubbers.UserScrubbers",
}
````

(default: `{}`)

### `SCRUBBER_STRICT_MODE`:

When strict mode is activated, you have to define a scrubbing policy for every field of every type defined in
`SCRUBBER_REQUIRED_FIELD_TYPES`. If you have unscrubbed fields and this flag is active, you can't run
`python manage.py scrub_data`.

(default: `False`)

### `SCRUBBER_REQUIRED_FIELD_TYPES`:

Defaults to all text-based Django model fields. Usually, privacy-relevant data is only stored in text-fields, numbers
and booleans (usually) can't contain sensitive personal data. These fields will be checked when running
`python manage.py scrub_validation`.

(default: (models.CharField, models.TextField, models.URLField, models.JSONField, models.GenericIPAddressField,
models.EmailField,))
(default: `(models.CharField, models.TextField, models.URLField, models.JSONField, models.GenericIPAddressField,
models.EmailField,)`)

### `SCRUBBER_REQUIRED_FIELD_MODEL_WHITELIST`:

Expand All @@ -314,15 +324,8 @@ against the full model name (e.g. `re.compile(auth.*)` to whitelist all auth mod
(default: `('auth.Group', 'auth.Permission', 'contenttypes.ContentType', 'sessions.Session', 'sites.Site',
'django_scrubber.FakeData', 'db.TestModel',)`)

````python
SCRUBBER_MAPPING = {
"auth.User": "my_app.scrubbers.UserScrubbers",
}
````

(default: {})


## Logging

Scrubber uses the default django logger. The logger name is ``django_scrubber.scrubbers``.
Expand Down
9 changes: 4 additions & 5 deletions django_scrubber/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
'SCRUBBER_GLOBAL_SCRUBBERS': {},
'SCRUBBER_SKIP_UNMANAGED': True,
'SCRUBBER_APPS_LIST': None,
'SCRUBBER_ADDITIONAL_FAKER_PROVIDERS': [],
'SCRUBBER_ADDITIONAL_FAKER_PROVIDERS': {*()},
'SCRUBBER_FAKER_LOCALE': None,
'SCRUBBER_MAPPING': dict(),
'SCRUBBER_MAPPING': {},
'SCRUBBER_STRICT_MODE': False,
'SCRUBBER_REQUIRED_FIELD_TYPES': (
models.CharField,
Expand All @@ -21,19 +21,18 @@
models.GenericIPAddressField,
models.EmailField,
),
'SCRUBBER_REQUIRED_FIELD_MODEL_WHITELIST': [
'SCRUBBER_REQUIRED_FIELD_MODEL_WHITELIST': (
'auth.Group',
'auth.Permission',
'contenttypes.ContentType',
'db.TestModel',
'sessions.Session',
'sites.Site',
'django_scrubber.FakeData',
],
),
}


# TODO: replace with ChainMap now that we only support py3
def settings_with_fallback(key):
return getattr(settings, key, defaults[key])

Expand Down
18 changes: 18 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.test import TestCase, override_settings

from django_scrubber import settings_with_fallback, defaults


class TestScrubbers(TestCase):
def test_default(self):
self.assertEqual(
defaults["SCRUBBER_RANDOM_SEED"],
settings_with_fallback("SCRUBBER_RANDOM_SEED"),
)

@override_settings(SCRUBBER_RANDOM_SEED=9001)
def test_override(self):
self.assertEqual(
9001,
settings_with_fallback("SCRUBBER_RANDOM_SEED"),
)

0 comments on commit d9a7c4d

Please sign in to comment.