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
02c27662
Kaydet (Commit)
02c27662
authored
Agu 16, 2016
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Moved model_validation tests to invalid_models_tests.
üst
8fb53c50
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
147 deletions
+111
-147
test_models.py
tests/invalid_models_tests/test_models.py
+75
-0
test_ordinary_fields.py
tests/invalid_models_tests/test_ordinary_fields.py
+21
-0
test_relative_fields.py
tests/invalid_models_tests/test_relative_fields.py
+15
-0
__init__.py
tests/model_validation/__init__.py
+0
-0
models.py
tests/model_validation/models.py
+0
-49
tests.py
tests/model_validation/tests.py
+0
-98
No files found.
tests/invalid_models_tests/test_models.py
Dosyayı görüntüle @
02c27662
...
...
@@ -6,7 +6,9 @@ import warnings
from
django.conf
import
settings
from
django.core.checks
import
Error
from
django.core.checks.model_checks
import
_check_lazy_references
from
django.db
import
connections
,
models
from
django.db.models.signals
import
post_init
from
django.test
import
SimpleTestCase
from
django.test.utils
import
isolate_apps
,
override_settings
...
...
@@ -827,3 +829,76 @@ class OtherModelTests(SimpleTestCase):
id
=
'fields.E340'
,
)
])
@isolate_apps
(
'django.contrib.auth'
,
kwarg_name
=
'apps'
)
def
test_lazy_reference_checks
(
self
,
apps
):
class
DummyModel
(
models
.
Model
):
author
=
models
.
ForeignKey
(
'Author'
,
models
.
CASCADE
)
class
Meta
:
app_label
=
'invalid_models_tests'
class
DummyClass
(
object
):
def
__call__
(
self
,
**
kwargs
):
pass
def
dummy_method
(
self
):
pass
def
dummy_function
(
*
args
,
**
kwargs
):
pass
apps
.
lazy_model_operation
(
dummy_function
,
(
'auth'
,
'imaginarymodel'
))
apps
.
lazy_model_operation
(
dummy_function
,
(
'fanciful_app'
,
'imaginarymodel'
))
post_init
.
connect
(
dummy_function
,
sender
=
'missing-app.Model'
,
apps
=
apps
)
post_init
.
connect
(
DummyClass
(),
sender
=
'missing-app.Model'
,
apps
=
apps
)
post_init
.
connect
(
DummyClass
()
.
dummy_method
,
sender
=
'missing-app.Model'
,
apps
=
apps
)
expected
=
[
Error
(
"
%
r contains a lazy reference to auth.imaginarymodel, "
"but app 'auth' doesn't provide model 'imaginarymodel'."
%
dummy_function
,
obj
=
dummy_function
,
id
=
'models.E022'
,
),
Error
(
"
%
r contains a lazy reference to fanciful_app.imaginarymodel, "
"but app 'fanciful_app' isn't installed."
%
dummy_function
,
obj
=
dummy_function
,
id
=
'models.E022'
,
),
Error
(
"An instance of class 'DummyClass' was connected to "
"the 'post_init' signal with a lazy reference to the sender "
"'missing-app.model', but app 'missing-app' isn't installed."
,
hint
=
None
,
obj
=
'invalid_models_tests.test_models'
,
id
=
'signals.E001'
,
),
Error
(
"Bound method 'DummyClass.dummy_method' was connected to the "
"'post_init' signal with a lazy reference to the sender "
"'missing-app.model', but app 'missing-app' isn't installed."
,
hint
=
None
,
obj
=
'invalid_models_tests.test_models'
,
id
=
'signals.E001'
,
),
Error
(
"The field invalid_models_tests.DummyModel.author was declared "
"with a lazy reference to 'invalid_models_tests.author', but app "
"'invalid_models_tests' isn't installed."
,
hint
=
None
,
obj
=
DummyModel
.
author
.
field
,
id
=
'fields.E307'
,
),
Error
(
"The function 'dummy_function' was connected to the 'post_init' "
"signal with a lazy reference to the sender "
"'missing-app.model', but app 'missing-app' isn't installed."
,
hint
=
None
,
obj
=
'invalid_models_tests.test_models'
,
id
=
'signals.E001'
,
),
]
self
.
assertEqual
(
_check_lazy_references
(
apps
),
expected
)
tests/invalid_models_tests/test_ordinary_fields.py
Dosyayı görüntüle @
02c27662
...
...
@@ -157,6 +157,27 @@ class CharFieldTests(TestCase):
]
self
.
assertEqual
(
errors
,
expected
)
def
test_iterable_of_iterable_choices
(
self
):
class
ThingItem
(
object
):
def
__init__
(
self
,
value
,
display
):
self
.
value
=
value
self
.
display
=
display
def
__iter__
(
self
):
return
(
x
for
x
in
[
self
.
value
,
self
.
display
])
def
__len__
(
self
):
return
2
class
Things
(
object
):
def
__iter__
(
self
):
return
(
x
for
x
in
[
ThingItem
(
1
,
2
),
ThingItem
(
3
,
4
)])
class
ThingWithIterableChoices
(
models
.
Model
):
thing
=
models
.
CharField
(
max_length
=
100
,
blank
=
True
,
choices
=
Things
())
self
.
assertEqual
(
ThingWithIterableChoices
.
_meta
.
get_field
(
'thing'
)
.
check
(),
[])
def
test_choices_containing_non_pairs
(
self
):
class
Model
(
models
.
Model
):
field
=
models
.
CharField
(
max_length
=
10
,
choices
=
[(
1
,
2
,
3
),
(
1
,
2
,
3
)])
...
...
tests/invalid_models_tests/test_relative_fields.py
Dosyayı görüntüle @
02c27662
...
...
@@ -995,6 +995,21 @@ class AccessorClashTests(SimpleTestCase):
]
self
.
assertEqual
(
errors
,
expected
)
def
test_no_clash_for_hidden_related_name
(
self
):
class
Stub
(
models
.
Model
):
pass
class
ManyToManyRel
(
models
.
Model
):
thing1
=
models
.
ManyToManyField
(
Stub
,
related_name
=
'+'
)
thing2
=
models
.
ManyToManyField
(
Stub
,
related_name
=
'+'
)
class
FKRel
(
models
.
Model
):
thing1
=
models
.
ForeignKey
(
Stub
,
models
.
CASCADE
,
related_name
=
'+'
)
thing2
=
models
.
ForeignKey
(
Stub
,
models
.
CASCADE
,
related_name
=
'+'
)
self
.
assertEqual
(
ManyToManyRel
.
check
(),
[])
self
.
assertEqual
(
FKRel
.
check
(),
[])
@isolate_apps
(
'invalid_models_tests'
)
class
ReverseQueryNameClashTests
(
SimpleTestCase
):
...
...
tests/model_validation/__init__.py
deleted
100644 → 0
Dosyayı görüntüle @
8fb53c50
tests/model_validation/models.py
deleted
100644 → 0
Dosyayı görüntüle @
8fb53c50
from
django.db
import
models
class
ThingItem
(
object
):
def
__init__
(
self
,
value
,
display
):
self
.
value
=
value
self
.
display
=
display
def
__iter__
(
self
):
return
(
x
for
x
in
[
self
.
value
,
self
.
display
])
def
__len__
(
self
):
return
2
class
Things
(
object
):
def
__iter__
(
self
):
return
(
x
for
x
in
[
ThingItem
(
1
,
2
),
ThingItem
(
3
,
4
)])
class
ThingWithIterableChoices
(
models
.
Model
):
# Testing choices= Iterable of Iterables
# See: https://code.djangoproject.com/ticket/20430
thing
=
models
.
CharField
(
max_length
=
100
,
blank
=
True
,
choices
=
Things
())
class
Meta
:
# Models created as unmanaged as these aren't ever queried
managed
=
False
class
ManyToManyRel
(
models
.
Model
):
thing1
=
models
.
ManyToManyField
(
ThingWithIterableChoices
,
related_name
=
'+'
)
thing2
=
models
.
ManyToManyField
(
ThingWithIterableChoices
,
related_name
=
'+'
)
class
Meta
:
# Models created as unmanaged as these aren't ever queried
managed
=
False
class
FKRel
(
models
.
Model
):
thing1
=
models
.
ForeignKey
(
ThingWithIterableChoices
,
models
.
CASCADE
,
related_name
=
'+'
)
thing2
=
models
.
ForeignKey
(
ThingWithIterableChoices
,
models
.
CASCADE
,
related_name
=
'+'
)
class
Meta
:
# Models created as unmanaged as these aren't ever queried
managed
=
False
tests/model_validation/tests.py
deleted
100644 → 0
Dosyayı görüntüle @
8fb53c50
from
django.core
import
management
from
django.core.checks
import
Error
from
django.core.checks.model_checks
import
_check_lazy_references
from
django.db
import
models
from
django.db.models.signals
import
post_init
from
django.test
import
SimpleTestCase
from
django.test.utils
import
isolate_apps
,
override_settings
from
django.utils
import
six
@override_settings
(
INSTALLED_APPS
=
[
'django.contrib.auth'
,
'django.contrib.contenttypes'
],
SILENCED_SYSTEM_CHECKS
=
[
'fields.W342'
],
# ForeignKey(unique=True)
)
class
ModelValidationTest
(
SimpleTestCase
):
def
test_models_validate
(
self
):
# All our models should validate properly
# Validation Tests:
# * choices= Iterable of Iterables
# See: https://code.djangoproject.com/ticket/20430
# * related_name='+' doesn't clash with another '+'
# See: https://code.djangoproject.com/ticket/21375
management
.
call_command
(
"check"
,
stdout
=
six
.
StringIO
())
@isolate_apps
(
'django.contrib.auth'
,
kwarg_name
=
'apps'
)
def
test_lazy_reference_checks
(
self
,
apps
):
class
DummyModel
(
models
.
Model
):
author
=
models
.
ForeignKey
(
'Author'
,
models
.
CASCADE
)
class
Meta
:
app_label
=
"model_validation"
class
DummyClass
(
object
):
def
__call__
(
self
,
**
kwargs
):
pass
def
dummy_method
(
self
):
pass
def
dummy_function
(
*
args
,
**
kwargs
):
pass
apps
.
lazy_model_operation
(
dummy_function
,
(
'auth'
,
'imaginarymodel'
))
apps
.
lazy_model_operation
(
dummy_function
,
(
'fanciful_app'
,
'imaginarymodel'
))
post_init
.
connect
(
dummy_function
,
sender
=
'missing-app.Model'
,
apps
=
apps
)
post_init
.
connect
(
DummyClass
(),
sender
=
'missing-app.Model'
,
apps
=
apps
)
post_init
.
connect
(
DummyClass
()
.
dummy_method
,
sender
=
'missing-app.Model'
,
apps
=
apps
)
errors
=
_check_lazy_references
(
apps
)
expected
=
[
Error
(
"
%
r contains a lazy reference to auth.imaginarymodel, "
"but app 'auth' doesn't provide model 'imaginarymodel'."
%
dummy_function
,
obj
=
dummy_function
,
id
=
'models.E022'
,
),
Error
(
"
%
r contains a lazy reference to fanciful_app.imaginarymodel, "
"but app 'fanciful_app' isn't installed."
%
dummy_function
,
obj
=
dummy_function
,
id
=
'models.E022'
,
),
Error
(
"An instance of class 'DummyClass' was connected to "
"the 'post_init' signal with a lazy reference to the sender "
"'missing-app.model', but app 'missing-app' isn't installed."
,
hint
=
None
,
obj
=
'model_validation.tests'
,
id
=
'signals.E001'
,
),
Error
(
"Bound method 'DummyClass.dummy_method' was connected to the "
"'post_init' signal with a lazy reference to the sender "
"'missing-app.model', but app 'missing-app' isn't installed."
,
hint
=
None
,
obj
=
'model_validation.tests'
,
id
=
'signals.E001'
,
),
Error
(
"The field model_validation.DummyModel.author was declared "
"with a lazy reference to 'model_validation.author', but app "
"'model_validation' isn't installed."
,
hint
=
None
,
obj
=
DummyModel
.
author
.
field
,
id
=
'fields.E307'
,
),
Error
(
"The function 'dummy_function' was connected to the 'post_init' "
"signal with a lazy reference to the sender "
"'missing-app.model', but app 'missing-app' isn't installed."
,
hint
=
None
,
obj
=
'model_validation.tests'
,
id
=
'signals.E001'
,
),
]
self
.
assertEqual
(
errors
,
expected
)
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