Skip to content

Commit d9a7c4d

Browse files
committed
align default settings and readme
1 parent 47529d4 commit d9a7c4d

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

README.md

+18-15
Original file line numberDiff line numberDiff line change
@@ -251,58 +251,68 @@ SCRUBBER_GLOBAL_SCRUBBERS = {
251251
The seed used when generating random content by the Faker scrubber. Setting this to `None` means each scrubbing will
252252
generate different data.
253253

254-
(default: 42)
254+
(default: `42`)
255255

256256
### `SCRUBBER_ENTRIES_PER_PROVIDER`:
257257

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

261-
(default: 1000)
261+
(default: `1000`)
262262

263263
### `SCRUBBER_SKIP_UNMANAGED`:
264264

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

267-
(default: True)
267+
(default: `True`)
268268

269269
### `SCRUBBER_APPS_LIST`:
270270

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

273-
(default: None)
273+
(default: `None`)
274274

275275
### `SCRUBBER_ADDITIONAL_FAKER_PROVIDERS`:
276276

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

279-
(default: empty list)
279+
(default: `{*()}`, empty set)
280280

281281
### `SCRUBBER_FAKER_LOCALE`:
282282

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

285-
(default: None, falls back to Django's default locale)
285+
(default: `None`, falls back to Django's default locale)
286286

287287
### `SCRUBBER_MAPPING`:
288288

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

292+
````python
293+
SCRUBBER_MAPPING = {
294+
"auth.User": "my_app.scrubbers.UserScrubbers",
295+
}
296+
````
297+
298+
(default: `{}`)
299+
292300
### `SCRUBBER_STRICT_MODE`:
293301

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

306+
(default: `False`)
307+
298308
### `SCRUBBER_REQUIRED_FIELD_TYPES`:
299309

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

304-
(default: (models.CharField, models.TextField, models.URLField, models.JSONField, models.GenericIPAddressField,
305-
models.EmailField,))
314+
(default: `(models.CharField, models.TextField, models.URLField, models.JSONField, models.GenericIPAddressField,
315+
models.EmailField,)`)
306316

307317
### `SCRUBBER_REQUIRED_FIELD_MODEL_WHITELIST`:
308318

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

317-
````python
318-
SCRUBBER_MAPPING = {
319-
"auth.User": "my_app.scrubbers.UserScrubbers",
320-
}
321-
````
322-
323327
(default: {})
324328

325-
326329
## Logging
327330

328331
Scrubber uses the default django logger. The logger name is ``django_scrubber.scrubbers``.

django_scrubber/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
'SCRUBBER_GLOBAL_SCRUBBERS': {},
1010
'SCRUBBER_SKIP_UNMANAGED': True,
1111
'SCRUBBER_APPS_LIST': None,
12-
'SCRUBBER_ADDITIONAL_FAKER_PROVIDERS': [],
12+
'SCRUBBER_ADDITIONAL_FAKER_PROVIDERS': {*()},
1313
'SCRUBBER_FAKER_LOCALE': None,
14-
'SCRUBBER_MAPPING': dict(),
14+
'SCRUBBER_MAPPING': {},
1515
'SCRUBBER_STRICT_MODE': False,
1616
'SCRUBBER_REQUIRED_FIELD_TYPES': (
1717
models.CharField,
@@ -21,19 +21,18 @@
2121
models.GenericIPAddressField,
2222
models.EmailField,
2323
),
24-
'SCRUBBER_REQUIRED_FIELD_MODEL_WHITELIST': [
24+
'SCRUBBER_REQUIRED_FIELD_MODEL_WHITELIST': (
2525
'auth.Group',
2626
'auth.Permission',
2727
'contenttypes.ContentType',
2828
'db.TestModel',
2929
'sessions.Session',
3030
'sites.Site',
3131
'django_scrubber.FakeData',
32-
],
32+
),
3333
}
3434

3535

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

tests/test_settings.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.test import TestCase, override_settings
2+
3+
from django_scrubber import settings_with_fallback, defaults
4+
5+
6+
class TestScrubbers(TestCase):
7+
def test_default(self):
8+
self.assertEqual(
9+
defaults["SCRUBBER_RANDOM_SEED"],
10+
settings_with_fallback("SCRUBBER_RANDOM_SEED"),
11+
)
12+
13+
@override_settings(SCRUBBER_RANDOM_SEED=9001)
14+
def test_override(self):
15+
self.assertEqual(
16+
9001,
17+
settings_with_fallback("SCRUBBER_RANDOM_SEED"),
18+
)

0 commit comments

Comments
 (0)