Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SCRUBBER_VALIDATION_WHITELIST and excluded Django core test model #56

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
lociii marked this conversation as resolved.
Show resolved Hide resolved
],
}


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.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string is unnecessary here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The !r notation takes care of the ticks, don't you think that's a plus?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I just meant the second line of the string.
f'not be validated.' could be 'not be validated.'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

continue

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