Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed get_validation_errors to use an app config.

  • Loading branch information...
commit e5bcd1d455cd11d3892adf6717a51ae04169f705 1 parent 856aaaf
@aaugustin aaugustin authored
View
6 django/contrib/auth/tests/test_management.py
@@ -196,21 +196,21 @@ class CustomUserModelValidationTestCase(TestCase):
def test_required_fields_is_list(self):
"REQUIRED_FIELDS should be a list."
new_io = StringIO()
- get_validation_errors(new_io, apps.get_app_config('auth').models_module)
+ get_validation_errors(new_io, apps.get_app_config('auth'))
self.assertIn("The REQUIRED_FIELDS must be a list or tuple.", new_io.getvalue())
@override_settings(AUTH_USER_MODEL='auth.CustomUserBadRequiredFields')
def test_username_not_in_required_fields(self):
"USERNAME_FIELD should not appear in REQUIRED_FIELDS."
new_io = StringIO()
- get_validation_errors(new_io, apps.get_app_config('auth').models_module)
+ get_validation_errors(new_io, apps.get_app_config('auth'))
self.assertIn("The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.", new_io.getvalue())
@override_settings(AUTH_USER_MODEL='auth.CustomUserNonUniqueUsername')
def test_username_non_unique(self):
"A non-unique USERNAME_FIELD should raise a model validation error."
new_io = StringIO()
- get_validation_errors(new_io, apps.get_app_config('auth').models_module)
+ get_validation_errors(new_io, apps.get_app_config('auth'))
self.assertIn("The USERNAME_FIELD must be unique. Add unique=True to the field parameters.", new_io.getvalue())
View
10 django/core/management/base.py
@@ -141,8 +141,8 @@ class BaseCommand(object):
performed prior to executing the command. Default value is
``True``. To validate an individual application's models
rather than all applications' models, call
- ``self.validate(app)`` from ``handle()``, where ``app`` is the
- application's Python module.
+ ``self.validate(app_config)`` from ``handle()``, where ``app_config``
+ is the application's configuration provided by the app registry.
``leave_locale_alone``
A boolean indicating whether the locale set in settings should be
@@ -304,16 +304,16 @@ def execute(self, *args, **options):
if saved_locale is not None:
translation.activate(saved_locale)
- def validate(self, app=None, display_num_errors=False):
+ def validate(self, app_config=None, display_num_errors=False):
"""
Validates the given app, raising CommandError for any errors.
- If app is None, then this will validate all installed apps.
+ If app_config is None, then this will validate all installed apps.
"""
from django.core.management.validation import get_validation_errors
s = StringIO()
- num_errors = get_validation_errors(s, app)
+ num_errors = get_validation_errors(s, app_config)
if num_errors:
s.seek(0)
error_text = s.read()
View
4 django/core/management/validation.py
@@ -20,7 +20,7 @@ def add(self, context, error):
self.outfile.write(self.style.ERROR(force_str("%s: %s\n" % (context, error))))
-def get_validation_errors(outfile, app=None):
+def get_validation_errors(outfile, app_config=None):
"""
Validates all models that are part of the specified app. If no app name is provided,
validates all models of all installed apps. Writes errors, if any, to outfile.
@@ -32,7 +32,7 @@ def get_validation_errors(outfile, app=None):
e = ModelErrorCollection(outfile)
- for cls in apps.get_models(app, include_swapped=True):
+ for cls in (app_config or apps).get_models(include_swapped=True):
opts = cls._meta
# Check swappable attribute.
View
6 tests/invalid_models_tests/tests.py
@@ -32,13 +32,13 @@ def tearDown(self):
TEST_SWAPPED_MODEL_BAD_MODEL='not_an_app.Target',
)
def test_invalid_models(self):
- module = apps.get_app_config("invalid_models").models_module
- get_validation_errors(self.stdout, module)
+ app_config = apps.get_app_config("invalid_models")
+ get_validation_errors(self.stdout, app_config)
self.stdout.seek(0)
error_log = self.stdout.read()
actual = error_log.split('\n')
- expected = module.model_errors.split('\n')
+ expected = app_config.models_module.model_errors.split('\n')
unexpected = [err for err in actual if err not in expected]
missing = [err for err in expected if err not in actual]
Please sign in to comment.
Something went wrong with that request. Please try again.