Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
e5bcd1d4
Kaydet (Commit)
e5bcd1d4
authored
Ara 29, 2013
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Changed get_validation_errors to use an app config.
üst
856aaaf2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
13 deletions
+13
-13
test_management.py
django/contrib/auth/tests/test_management.py
+3
-3
base.py
django/core/management/base.py
+5
-5
validation.py
django/core/management/validation.py
+2
-2
tests.py
tests/invalid_models_tests/tests.py
+3
-3
No files found.
django/contrib/auth/tests/test_management.py
Dosyayı görüntüle @
e5bcd1d4
...
...
@@ -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
())
...
...
django/core/management/base.py
Dosyayı görüntüle @
e5bcd1d4
...
...
@@ -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 @@ class BaseCommand(object):
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
()
...
...
django/core/management/validation.py
Dosyayı görüntüle @
e5bcd1d4
...
...
@@ -20,7 +20,7 @@ class ModelErrorCollection:
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.
...
...
tests/invalid_models_tests/tests.py
Dosyayı görüntüle @
e5bcd1d4
...
...
@@ -32,13 +32,13 @@ class InvalidModelTestCase(unittest.TestCase):
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
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment