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
bd8e1a35
Kaydet (Commit)
bd8e1a35
authored
Eyl 01, 2013
tarafından
Markus Holtermann
Kaydeden (comit)
Tim Graham
Eyl 06, 2013
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #20977 -- Fixed writing migrations to disk on Python 3
üst
8625c7aa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
8 deletions
+101
-8
makemigrations.py
django/core/management/commands/makemigrations.py
+8
-6
models.py
tests/migrations/models.py
+20
-0
test_commands.py
tests/migrations/test_commands.py
+73
-2
No files found.
django/core/management/commands/makemigrations.py
Dosyayı görüntüle @
bd8e1a35
...
...
@@ -52,7 +52,7 @@ class Command(BaseCommand):
changes
=
autodetector
.
changes
(
graph
=
loader
.
graph
,
trim_to_apps
=
app_labels
or
None
)
# No changes? Tell them.
if
not
changes
:
if
not
changes
and
self
.
verbosity
>=
1
:
if
len
(
app_labels
)
==
1
:
self
.
stdout
.
write
(
"No changes detected in app '
%
s'"
%
app_labels
.
pop
())
elif
len
(
app_labels
)
>
1
:
...
...
@@ -63,13 +63,15 @@ class Command(BaseCommand):
directory_created
=
{}
for
app_label
,
migrations
in
changes
.
items
():
self
.
stdout
.
write
(
self
.
style
.
MIGRATE_HEADING
(
"Migrations for '
%
s':"
%
app_label
)
+
"
\n
"
)
if
self
.
verbosity
>=
1
:
self
.
stdout
.
write
(
self
.
style
.
MIGRATE_HEADING
(
"Migrations for '
%
s':"
%
app_label
)
+
"
\n
"
)
for
migration
in
migrations
:
# Describe the migration
writer
=
MigrationWriter
(
migration
)
self
.
stdout
.
write
(
"
%
s:
\n
"
%
(
self
.
style
.
MIGRATE_LABEL
(
writer
.
filename
),))
for
operation
in
migration
.
operations
:
self
.
stdout
.
write
(
" -
%
s
\n
"
%
operation
.
describe
())
if
self
.
verbosity
>=
1
:
self
.
stdout
.
write
(
"
%
s:
\n
"
%
(
self
.
style
.
MIGRATE_LABEL
(
writer
.
filename
),))
for
operation
in
migration
.
operations
:
self
.
stdout
.
write
(
" -
%
s
\n
"
%
operation
.
describe
())
# Write it
migrations_directory
=
os
.
path
.
dirname
(
writer
.
path
)
if
not
directory_created
.
get
(
app_label
,
False
):
...
...
@@ -80,5 +82,5 @@ class Command(BaseCommand):
open
(
init_path
,
"w"
)
.
close
()
# We just do this once per app
directory_created
[
app_label
]
=
True
with
open
(
writer
.
path
,
"w"
)
as
fh
:
with
open
(
writer
.
path
,
"w
b
"
)
as
fh
:
fh
.
write
(
writer
.
as_string
())
tests/migrations/models.py
Dosyayı görüntüle @
bd8e1a35
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
from
django.db.models.loading
import
BaseAppCache
from
django.utils.encoding
import
python_2_unicode_compatible
@python_2_unicode_compatible
class
UnicodeModel
(
models
.
Model
):
title
=
models
.
CharField
(
'ÚÑÍ¢ÓÐÉ'
,
max_length
=
20
,
default
=
'“Ðjáñgó”'
)
class
Meta
:
# Disable auto loading of this model as we load it on our own
app_cache
=
BaseAppCache
()
verbose_name
=
'úñí©óðé µóðéø'
verbose_name_plural
=
'úñí©óðé µóðéøß'
def
__str__
(
self
):
return
self
.
title
tests/migrations/test_commands.py
Dosyayı görüntüle @
bd8e1a35
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
import
os
import
shutil
from
django.core.management
import
call_command
from
django.db.models.loading
import
cache
from
django.test.utils
import
override_settings
from
django.utils
import
six
from
django.utils._os
import
upath
from
django.utils.encoding
import
force_text
from
.models
import
UnicodeModel
from
.test_base
import
MigrationTestBase
class
Command
Tests
(
MigrationTestBase
):
class
Migrate
Tests
(
MigrationTestBase
):
"""
Tests running the
commands (migrate, makemigrations)
.
Tests running the
migrate command
.
"""
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations"
})
...
...
@@ -35,3 +47,62 @@ class CommandTests(MigrationTestBase):
self
.
assertTableNotExists
(
"migrations_author"
)
self
.
assertTableNotExists
(
"migrations_tribble"
)
self
.
assertTableNotExists
(
"migrations_book"
)
class
MakeMigrationsTests
(
MigrationTestBase
):
"""
Tests running the makemigrations command.
"""
def
setUp
(
self
):
self
.
_cwd
=
os
.
getcwd
()
self
.
test_dir
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
upath
(
__file__
)))
self
.
migration_dir
=
os
.
path
.
join
(
self
.
test_dir
,
'migrations'
)
def
tearDown
(
self
):
os
.
chdir
(
self
.
test_dir
)
try
:
self
.
_rmrf
(
self
.
migration_dir
)
except
OSError
:
pass
os
.
chdir
(
self
.
_cwd
)
def
_rmrf
(
self
,
dname
):
if
os
.
path
.
commonprefix
([
self
.
test_dir
,
os
.
path
.
abspath
(
dname
)])
!=
self
.
test_dir
:
return
shutil
.
rmtree
(
dname
)
def
test_files_content
(
self
):
self
.
assertTableNotExists
(
"migrations_unicodemodel"
)
cache
.
register_models
(
'migrations'
,
UnicodeModel
)
call_command
(
"makemigrations"
,
"migrations"
,
verbosity
=
0
)
init_file
=
os
.
path
.
join
(
self
.
migration_dir
,
"__init__.py"
)
# Check for existing __init__.py file in migrations folder
self
.
assertTrue
(
os
.
path
.
exists
(
init_file
))
with
open
(
init_file
,
'r'
)
as
fp
:
content
=
force_text
(
fp
.
read
())
self
.
assertEqual
(
content
,
''
)
initial_file
=
os
.
path
.
join
(
self
.
migration_dir
,
"0001_initial.py"
)
# Check for existing 0001_initial.py file in migration folder
self
.
assertTrue
(
os
.
path
.
exists
(
initial_file
))
with
open
(
initial_file
,
'r'
)
as
fp
:
content
=
force_text
(
fp
.
read
())
self
.
assertTrue
(
'# encoding: utf8'
in
content
)
self
.
assertTrue
(
'migrations.CreateModel'
in
content
)
if
six
.
PY3
:
self
.
assertTrue
(
'úñí©óðé µóðéø'
in
content
)
# Meta.verbose_name
self
.
assertTrue
(
'úñí©óðé µóðéøß'
in
content
)
# Meta.verbose_name_plural
self
.
assertTrue
(
'ÚÑÍ¢ÓÐÉ'
in
content
)
# title.verbose_name
self
.
assertTrue
(
'“Ðjáñgó”'
in
content
)
# title.default
else
:
self
.
assertTrue
(
'
\\
xfa
\\
xf1
\\
xed
\\
xa9
\\
xf3
\\
xf0
\\
xe9
\\
xb5
\\
xf3
\\
xf0
\\
xe9
\\
xf8'
in
content
)
# Meta.verbose_name
self
.
assertTrue
(
'
\\
xfa
\\
xf1
\\
xed
\\
xa9
\\
xf3
\\
xf0
\\
xe9
\\
xb5
\\
xf3
\\
xf0
\\
xe9
\\
xf8
\\
xdf'
in
content
)
# Meta.verbose_name_plural
self
.
assertTrue
(
'
\\
xda
\\
xd1
\\
xcd
\\
xa2
\\
xd3
\\
xd0
\\
xc9'
in
content
)
# title.verbose_name
self
.
assertTrue
(
'
\\
u201c
\\
xd0j
\\
xe1
\\
xf1g
\\
xf3
\\
u201d'
in
content
)
# title.default
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