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
874b1f2c
Kaydet (Commit)
874b1f2c
authored
Şub 04, 2017
tarafından
Pavel Rybintsev
Kaydeden (comit)
Tim Graham
Haz 16, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26936 -- Fixed stale ContentType deletion in apps without models.
üst
ceca221b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
remove_stale_contenttypes.py
...enttypes/management/commands/remove_stale_contenttypes.py
+0
-2
test_management.py
tests/contenttypes_tests/test_management.py
+12
-1
No files found.
django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py
Dosyayı görüntüle @
874b1f2c
...
...
@@ -26,8 +26,6 @@ class Command(BaseCommand):
for
app_config
in
apps
.
get_app_configs
():
content_types
,
app_models
=
get_contenttypes_and_models
(
app_config
,
db
,
ContentType
)
if
not
app_models
:
continue
to_remove
=
[
ct
for
(
model_name
,
ct
)
in
content_types
.
items
()
if
model_name
not
in
app_models
...
...
tests/contenttypes_tests/test_management.py
Dosyayı görüntüle @
874b1f2c
...
...
@@ -4,13 +4,17 @@ from django.apps.registry import Apps, apps
from
django.contrib.contenttypes
import
management
as
contenttypes_management
from
django.contrib.contenttypes.models
import
ContentType
from
django.core.management
import
call_command
from
django.test
import
TestCase
from
django.test
import
TestCase
,
modify_settings
from
django.test.utils
import
captured_stdout
from
.models
import
ModelWithNullFKToSite
,
Post
@modify_settings
(
INSTALLED_APPS
=
{
'append'
:
[
'no_models'
]})
class
UpdateContentTypesTests
(
TestCase
):
# Speed up tests by avoiding retrieving ContentTypes for all test apps.
available_apps
=
[
'contenttypes_tests'
,
'no_models'
,
'django.contrib.contenttypes'
]
def
setUp
(
self
):
self
.
before_count
=
ContentType
.
objects
.
count
()
self
.
content_type
=
ContentType
.
objects
.
create
(
app_label
=
'contenttypes_tests'
,
model
=
'Fake'
)
...
...
@@ -63,3 +67,10 @@ class UpdateContentTypesTests(TestCase):
with
self
.
assertNumQueries
(
0
):
contenttypes_management
.
create_contenttypes
(
self
.
app_config
,
interactive
=
False
,
verbosity
=
0
,
apps
=
apps
)
self
.
assertEqual
(
ContentType
.
objects
.
count
(),
self
.
before_count
+
1
)
def
test_contenttypes_removed_in_apps_without_models
(
self
):
ContentType
.
objects
.
create
(
app_label
=
'no_models'
,
model
=
'Fake'
)
with
mock
.
patch
(
'builtins.input'
,
return_value
=
'yes'
),
captured_stdout
()
as
stdout
:
call_command
(
'remove_stale_contenttypes'
,
verbosity
=
2
)
self
.
assertIn
(
"Deleting stale content type 'no_models | Fake'"
,
stdout
.
getvalue
())
self
.
assertEqual
(
ContentType
.
objects
.
count
(),
self
.
before_count
)
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