Skip to content

Commit

Permalink
Merge pull request #56 from GitRon/feature/scrubber-validation-whitel…
Browse files Browse the repository at this point in the history
…ist-added

Added SCRUBBER_VALIDATION_WHITELIST and excluded Django core test model
  • Loading branch information
lociii authored Aug 20, 2024
2 parents b6452f5 + 45139fe commit ef1538e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
- Added support for `Django` version `5.1`
- 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 '
'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 ef1538e

Please sign in to comment.