Skip to content

Commit

Permalink
Added SCRUBBER_VALIDATION_WHITELIST and excluded Django core test model
Browse files Browse the repository at this point in the history
  • Loading branch information
GitRon committed Aug 19, 2024
1 parent 28ef2bb commit ea04d5b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

<!--
## [Unreleased]
- Added `SCRUBBER_VALIDATION_WHITELIST` and excluded Django core test model
-->

## [2.0.0] - 2024-06-27
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ SCRUBBER_MAPPING = {

(default: {})

### `SCRUBBER_VALIDATION_WHITELIST`:

Whitelist models you want to exclude from the `scrub_validation` checker command for scrubber-wise undeclared models.
By default, it contains only a test model from Django core which doesn't have to be anonymised.

(default: ['db.TestModel',])

## Logging

Scrubber uses the default django logger. The logger name is ``django_scrubber.scrubbers``.
Expand Down
3 changes: 3 additions & 0 deletions django_scrubber/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
'sites.Site',
'django_scrubber.FakeData',
],
'SCRUBBER_VALIDATION_WHITELIST': [
'db.TestModel', # Test model from Django core
],
}


Expand Down
10 changes: 10 additions & 0 deletions django_scrubber/management/commands/scrub_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.core.management.base import BaseCommand

from django_scrubber import settings_with_fallback
from django_scrubber.services.validator import ScrubberValidatorService


Expand All @@ -13,8 +14,17 @@ def handle(self, *args, **options):

found_models = 0
found_fields = 0

whitelisted_models = settings_with_fallback('SCRUBBER_VALIDATION_WHITELIST')

if len(non_scrubbed_field_list):
for model_path, affected_field_list in non_scrubbed_field_list.items():

if model_path in whitelisted_models:
print(f'Model {model_path!r} was excluded via \'SCRUBBER_VALIDATION_WHITELIST\' and will '
f'not be validated.')
continue

print(f'Model {model_path!r}:')
found_models += 1
for field in affected_field_list:
Expand Down

0 comments on commit ea04d5b

Please sign in to comment.