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
f851a954
Kaydet (Commit)
f851a954
authored
May 20, 2014
tarafından
Huu Nguyen
Kaydeden (comit)
Tim Graham
May 23, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22602 -- Improved code coverage of makemigrations command tests.
üst
be88b062
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
326 additions
and
0 deletions
+326
-0
test_commands.py
tests/migrations/test_commands.py
+151
-0
0001_initial.py
tests/migrations/test_migrations_no_ancestor/0001_initial.py
+30
-0
0002_conflicting_second.py
...ns/test_migrations_no_ancestor/0002_conflicting_second.py
+28
-0
0002_second.py
tests/migrations/test_migrations_no_ancestor/0002_second.py
+29
-0
__init__.py
tests/migrations/test_migrations_no_ancestor/__init__.py
+0
-0
0001_initial.py
tests/migrations/test_migrations_no_changes/0001_initial.py
+30
-0
0002_second.py
tests/migrations/test_migrations_no_changes/0002_second.py
+29
-0
0003_third.py
tests/migrations/test_migrations_no_changes/0003_third.py
+29
-0
__init__.py
tests/migrations/test_migrations_no_changes/__init__.py
+0
-0
No files found.
tests/migrations/test_commands.py
Dosyayı görüntüle @
f851a954
...
...
@@ -7,6 +7,7 @@ import shutil
from
django.apps
import
apps
from
django.core.management
import
call_command
,
CommandError
from
django.db.migrations
import
questioner
from
django.test
import
override_settings
,
override_system_checks
from
django.utils
import
six
from
django.utils._os
import
upath
...
...
@@ -211,3 +212,153 @@ class MakeMigrationsTests(MigrationTestBase):
call_command
(
"makemigrations"
,
merge
=
True
,
verbosity
=
0
)
except
CommandError
:
self
.
fail
(
"Makemigrations errored in merge mode with conflicts"
)
@override_system_checks
([])
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations"
})
def
test_makemigrations_merge_no_conflict
(
self
):
"""
Makes sure that makemigrations exits if in merge mode with no conflicts.
"""
stdout
=
six
.
StringIO
()
try
:
call_command
(
"makemigrations"
,
merge
=
True
,
stdout
=
stdout
)
except
CommandError
:
self
.
fail
(
"Makemigrations errored in merge mode with no conflicts"
)
self
.
assertIn
(
"No conflicts detected to merge."
,
stdout
.
getvalue
())
@override_system_checks
([])
def
test_makemigrations_no_app_sys_exit
(
self
):
"""
Makes sure that makemigrations exits if a non-existent app is specified.
"""
stderr
=
six
.
StringIO
()
with
self
.
assertRaises
(
SystemExit
):
call_command
(
"makemigrations"
,
"this_app_does_not_exist"
,
stderr
=
stderr
)
self
.
assertIn
(
"'this_app_does_not_exist' could not be found."
,
stderr
.
getvalue
())
@override_system_checks
([])
def
test_makemigrations_empty_no_app_specified
(
self
):
"""
Makes sure that makemigrations exits if no app is specified with 'empty' mode.
"""
with
override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
self
.
migration_pkg
}):
self
.
assertRaises
(
CommandError
,
call_command
,
"makemigrations"
,
empty
=
True
)
@override_system_checks
([])
def
test_makemigrations_empty_migration
(
self
):
"""
Makes sure that makemigrations properly constructs an empty migration.
"""
with
override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
self
.
migration_pkg
}):
try
:
call_command
(
"makemigrations"
,
"migrations"
,
empty
=
True
,
verbosity
=
0
)
except
CommandError
:
self
.
fail
(
"Makemigrations errored in creating empty migration for a proper app."
)
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
codecs
.
open
(
initial_file
,
'r'
,
encoding
=
'utf-8'
)
as
fp
:
content
=
fp
.
read
()
self
.
assertTrue
(
'# -*- coding: utf-8 -*-'
in
content
)
# Remove all whitespace to check for empty dependencies and operations
content
=
content
.
replace
(
' '
,
''
)
self
.
assertIn
(
'dependencies=[
\n
]'
,
content
)
self
.
assertIn
(
'operations=[
\n
]'
,
content
)
@override_system_checks
([])
def
test_makemigrations_no_changes_no_apps
(
self
):
"""
Makes sure that makemigrations exits when there are no changes and no apps are specified.
"""
stdout
=
six
.
StringIO
()
call_command
(
"makemigrations"
,
stdout
=
stdout
)
self
.
assertIn
(
"No changes detected"
,
stdout
.
getvalue
())
@override_system_checks
([])
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_no_changes"
})
def
test_makemigrations_no_changes
(
self
):
"""
Makes sure that makemigrations exits when there are no changes to an app.
"""
stdout
=
six
.
StringIO
()
call_command
(
"makemigrations"
,
"migrations"
,
stdout
=
stdout
)
self
.
assertIn
(
"No changes detected in app 'migrations'"
,
stdout
.
getvalue
())
@override_system_checks
([])
def
test_makemigrations_migrations_announce
(
self
):
"""
Makes sure that makemigrations announces the migration at the default verbosity level.
"""
stdout
=
six
.
StringIO
()
with
override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
self
.
migration_pkg
}):
call_command
(
"makemigrations"
,
"migrations"
,
stdout
=
stdout
)
self
.
assertIn
(
"Migrations for 'migrations'"
,
stdout
.
getvalue
())
@override_system_checks
([])
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_no_ancestor"
})
def
test_makemigrations_no_common_ancestor
(
self
):
"""
Makes sure that makemigrations fails to merge migrations with no common ancestor.
"""
with
self
.
assertRaises
(
ValueError
)
as
context
:
call_command
(
"makemigrations"
,
"migrations"
,
merge
=
True
)
exception_message
=
str
(
context
.
exception
)
self
.
assertIn
(
"Could not find common ancestor of"
,
exception_message
)
self
.
assertIn
(
"0002_second"
,
exception_message
)
self
.
assertIn
(
"0002_conflicting_second"
,
exception_message
)
@override_system_checks
([])
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_conflict"
})
def
test_makemigrations_interactive_reject
(
self
):
"""
Makes sure that makemigrations enters and exits interactive mode properly.
"""
# Monkeypatch interactive questioner to auto reject
old_input
=
questioner
.
input
questioner
.
input
=
lambda
_
:
"N"
try
:
call_command
(
"makemigrations"
,
"migrations"
,
merge
=
True
,
interactive
=
True
,
verbosity
=
0
)
merge_file
=
os
.
path
.
join
(
self
.
test_dir
,
'test_migrations_conflict'
,
'0003_merge.py'
)
self
.
assertFalse
(
os
.
path
.
exists
(
merge_file
))
except
CommandError
:
self
.
fail
(
"Makemigrations failed while running interactive questioner"
)
finally
:
questioner
.
input
=
old_input
@override_system_checks
([])
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_conflict"
})
def
test_makemigrations_interactive_accept
(
self
):
"""
Makes sure that makemigrations enters interactive mode and merges properly.
"""
# Monkeypatch interactive questioner to auto accept
old_input
=
questioner
.
input
questioner
.
input
=
lambda
_
:
"y"
stdout
=
six
.
StringIO
()
try
:
call_command
(
"makemigrations"
,
"migrations"
,
merge
=
True
,
interactive
=
True
,
stdout
=
stdout
)
merge_file
=
os
.
path
.
join
(
self
.
test_dir
,
'test_migrations_conflict'
,
'0003_merge.py'
)
self
.
assertTrue
(
os
.
path
.
exists
(
merge_file
))
os
.
remove
(
merge_file
)
self
.
assertFalse
(
os
.
path
.
exists
(
merge_file
))
except
CommandError
:
self
.
fail
(
"Makemigrations failed while running interactive questioner"
)
finally
:
questioner
.
input
=
old_input
self
.
assertIn
(
"Created new merge migration"
,
stdout
.
getvalue
())
@override_system_checks
([])
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_conflict"
})
def
test_makemigrations_handle_merge
(
self
):
"""
Makes sure that makemigrations properly merges the conflicting migrations.
"""
stdout
=
six
.
StringIO
()
call_command
(
"makemigrations"
,
"migrations"
,
merge
=
True
,
stdout
=
stdout
)
self
.
assertIn
(
"Merging migrations"
,
stdout
.
getvalue
())
self
.
assertIn
(
"Branch 0002_second"
,
stdout
.
getvalue
())
self
.
assertIn
(
"Branch 0002_conflicting_second"
,
stdout
.
getvalue
())
tests/migrations/test_migrations_no_ancestor/0001_initial.py
0 → 100644
Dosyayı görüntüle @
f851a954
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
operations
=
[
migrations
.
CreateModel
(
"Author"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
255
)),
(
"slug"
,
models
.
SlugField
(
null
=
True
)),
(
"age"
,
models
.
IntegerField
(
default
=
0
)),
(
"silly_field"
,
models
.
BooleanField
(
default
=
False
)),
],
),
migrations
.
CreateModel
(
"Tribble"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"fluffy"
,
models
.
BooleanField
(
default
=
True
)),
],
)
]
tests/migrations/test_migrations_no_ancestor/0002_conflicting_second.py
0 → 100644
Dosyayı görüntüle @
f851a954
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
]
operations
=
[
migrations
.
DeleteModel
(
"Tribble"
),
migrations
.
RemoveField
(
"Author"
,
"silly_field"
),
migrations
.
AddField
(
"Author"
,
"rating"
,
models
.
IntegerField
(
default
=
0
)),
migrations
.
CreateModel
(
"Book"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"author"
,
models
.
ForeignKey
(
"migrations.Author"
,
null
=
True
)),
],
)
]
tests/migrations/test_migrations_no_ancestor/0002_second.py
0 → 100644
Dosyayı görüntüle @
f851a954
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
"migrations"
,
"0001_initial"
),
]
operations
=
[
migrations
.
DeleteModel
(
"Tribble"
),
migrations
.
RemoveField
(
"Author"
,
"silly_field"
),
migrations
.
AddField
(
"Author"
,
"rating"
,
models
.
IntegerField
(
default
=
0
)),
migrations
.
CreateModel
(
"Book"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"author"
,
models
.
ForeignKey
(
"migrations.Author"
,
null
=
True
)),
],
)
]
tests/migrations/test_migrations_no_ancestor/__init__.py
0 → 100644
Dosyayı görüntüle @
f851a954
tests/migrations/test_migrations_no_changes/0001_initial.py
0 → 100644
Dosyayı görüntüle @
f851a954
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
operations
=
[
migrations
.
CreateModel
(
"Author"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"name"
,
models
.
CharField
(
max_length
=
255
)),
(
"slug"
,
models
.
SlugField
(
null
=
True
)),
(
"age"
,
models
.
IntegerField
(
default
=
0
)),
(
"silly_field"
,
models
.
BooleanField
(
default
=
False
)),
],
),
migrations
.
CreateModel
(
"Tribble"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"fluffy"
,
models
.
BooleanField
(
default
=
True
)),
],
)
]
tests/migrations/test_migrations_no_changes/0002_second.py
0 → 100644
Dosyayı görüntüle @
f851a954
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
"migrations"
,
"0001_initial"
),
]
operations
=
[
migrations
.
DeleteModel
(
"Tribble"
),
migrations
.
RemoveField
(
"Author"
,
"silly_field"
),
migrations
.
AddField
(
"Author"
,
"rating"
,
models
.
IntegerField
(
default
=
0
)),
migrations
.
CreateModel
(
"Book"
,
[
(
"id"
,
models
.
AutoField
(
primary_key
=
True
)),
(
"author"
,
models
.
ForeignKey
(
"migrations.Author"
,
null
=
True
)),
],
)
]
tests/migrations/test_migrations_no_changes/0003_third.py
0 → 100644
Dosyayı görüntüle @
f851a954
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'migrations'
,
'0002_second'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'ModelWithCustomBase'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
migrations
.
DeleteModel
(
name
=
'Author'
,
),
migrations
.
DeleteModel
(
name
=
'Book'
,
),
]
tests/migrations/test_migrations_no_changes/__init__.py
0 → 100644
Dosyayı görüntüle @
f851a954
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