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
8d4ab0c4
Unverified
Kaydet (Commit)
8d4ab0c4
authored
Tem 21, 2018
tarafından
Tim Graham
Kaydeden (comit)
GitHub
Tem 21, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added tests for migrate logging and error messages.
üst
15641950
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
3 deletions
+47
-3
test_commands.py
tests/migrations/test_commands.py
+37
-3
__init__.py
tests/migrations/test_migrations_clashing_prefix/__init__.py
+0
-0
a.py
tests/migrations/test_migrations_clashing_prefix/a.py
+5
-0
ab.py
tests/migrations/test_migrations_clashing_prefix/ab.py
+5
-0
No files found.
tests/migrations/test_commands.py
Dosyayı görüntüle @
8d4ab0c4
...
@@ -36,7 +36,11 @@ class MigrateTests(MigrationTestBase):
...
@@ -36,7 +36,11 @@ class MigrateTests(MigrationTestBase):
self
.
assertTableNotExists
(
"migrations_tribble"
)
self
.
assertTableNotExists
(
"migrations_tribble"
)
self
.
assertTableNotExists
(
"migrations_book"
)
self
.
assertTableNotExists
(
"migrations_book"
)
# Run the migrations to 0001 only
# Run the migrations to 0001 only
call_command
(
"migrate"
,
"migrations"
,
"0001"
,
verbosity
=
0
)
stdout
=
io
.
StringIO
()
call_command
(
'migrate'
,
'migrations'
,
'0001'
,
verbosity
=
1
,
stdout
=
stdout
,
no_color
=
True
)
stdout
=
stdout
.
getvalue
()
self
.
assertIn
(
'Target specific migration: 0001_initial, from migrations'
,
stdout
)
self
.
assertIn
(
'Applying migrations.0001_initial... OK'
,
stdout
)
# The correct tables exist
# The correct tables exist
self
.
assertTableExists
(
"migrations_author"
)
self
.
assertTableExists
(
"migrations_author"
)
self
.
assertTableExists
(
"migrations_tribble"
)
self
.
assertTableExists
(
"migrations_tribble"
)
...
@@ -48,7 +52,11 @@ class MigrateTests(MigrationTestBase):
...
@@ -48,7 +52,11 @@ class MigrateTests(MigrationTestBase):
self
.
assertTableNotExists
(
"migrations_tribble"
)
self
.
assertTableNotExists
(
"migrations_tribble"
)
self
.
assertTableExists
(
"migrations_book"
)
self
.
assertTableExists
(
"migrations_book"
)
# Unmigrate everything
# Unmigrate everything
call_command
(
"migrate"
,
"migrations"
,
"zero"
,
verbosity
=
0
)
stdout
=
io
.
StringIO
()
call_command
(
'migrate'
,
'migrations'
,
'zero'
,
verbosity
=
1
,
stdout
=
stdout
,
no_color
=
True
)
stdout
=
stdout
.
getvalue
()
self
.
assertIn
(
'Unapply all migrations: migrations'
,
stdout
)
self
.
assertIn
(
'Unapplying migrations.0002_second... OK'
,
stdout
)
# Tables are gone
# Tables are gone
self
.
assertTableNotExists
(
"migrations_author"
)
self
.
assertTableNotExists
(
"migrations_author"
)
self
.
assertTableNotExists
(
"migrations_tribble"
)
self
.
assertTableNotExists
(
"migrations_tribble"
)
...
@@ -64,6 +72,27 @@ class MigrateTests(MigrationTestBase):
...
@@ -64,6 +72,27 @@ class MigrateTests(MigrationTestBase):
call_command
(
'migrate'
,
skip_checks
=
False
,
no_color
=
True
,
stdout
=
out
)
call_command
(
'migrate'
,
skip_checks
=
False
,
no_color
=
True
,
stdout
=
out
)
self
.
assertIn
(
'Apply all migrations: migrated_app'
,
out
.
getvalue
())
self
.
assertIn
(
'Apply all migrations: migrated_app'
,
out
.
getvalue
())
@override_settings
(
INSTALLED_APPS
=
[
'migrations'
,
'migrations.migrations_test_apps.unmigrated_app_syncdb'
])
def
test_app_without_migrations
(
self
):
msg
=
"App 'unmigrated_app_syncdb' does not have migrations."
with
self
.
assertRaisesMessage
(
CommandError
,
msg
):
call_command
(
'migrate'
,
app_label
=
'unmigrated_app_syncdb'
)
@override_settings
(
MIGRATION_MODULES
=
{
'migrations'
:
'migrations.test_migrations_clashing_prefix'
})
def
test_ambigious_prefix
(
self
):
msg
=
(
"More than one migration matches 'a' in app 'migrations'. Please "
"be more specific."
)
with
self
.
assertRaisesMessage
(
CommandError
,
msg
):
call_command
(
'migrate'
,
app_label
=
'migrations'
,
migration_name
=
'a'
)
@override_settings
(
MIGRATION_MODULES
=
{
'migrations'
:
'migrations.test_migrations'
})
def
test_unknown_prefix
(
self
):
msg
=
"Cannot find a migration matching 'nonexistent' from app 'migrations'."
with
self
.
assertRaisesMessage
(
CommandError
,
msg
):
call_command
(
'migrate'
,
app_label
=
'migrations'
,
migration_name
=
'nonexistent'
)
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_initial_false"
})
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_initial_false"
})
def
test_migrate_initial_false
(
self
):
def
test_migrate_initial_false
(
self
):
"""
"""
...
@@ -552,13 +581,18 @@ class MigrateTests(MigrationTestBase):
...
@@ -552,13 +581,18 @@ class MigrateTests(MigrationTestBase):
For an app without migrations, editor.execute() is used for executing
For an app without migrations, editor.execute() is used for executing
the syncdb deferred SQL.
the syncdb deferred SQL.
"""
"""
stdout
=
io
.
StringIO
()
with
mock
.
patch
.
object
(
BaseDatabaseSchemaEditor
,
'execute'
)
as
execute
:
with
mock
.
patch
.
object
(
BaseDatabaseSchemaEditor
,
'execute'
)
as
execute
:
call_command
(
'migrate'
,
run_syncdb
=
True
,
verbosity
=
0
)
call_command
(
'migrate'
,
run_syncdb
=
True
,
verbosity
=
1
,
stdout
=
stdout
,
no_color
=
True
)
create_table_count
=
len
([
call
for
call
in
execute
.
mock_calls
if
'CREATE TABLE'
in
str
(
call
)])
create_table_count
=
len
([
call
for
call
in
execute
.
mock_calls
if
'CREATE TABLE'
in
str
(
call
)])
self
.
assertEqual
(
create_table_count
,
2
)
self
.
assertEqual
(
create_table_count
,
2
)
# There's at least one deferred SQL for creating the foreign key
# There's at least one deferred SQL for creating the foreign key
# index.
# index.
self
.
assertGreater
(
len
(
execute
.
mock_calls
),
2
)
self
.
assertGreater
(
len
(
execute
.
mock_calls
),
2
)
stdout
=
stdout
.
getvalue
()
self
.
assertIn
(
'Synchronize unmigrated apps: unmigrated_app_syncdb'
,
stdout
)
self
.
assertIn
(
'Creating tables...'
,
stdout
)
self
.
assertIn
(
'Creating table unmigrated_app_syncdb_classroom'
,
stdout
)
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_squashed"
})
@override_settings
(
MIGRATION_MODULES
=
{
"migrations"
:
"migrations.test_migrations_squashed"
})
def
test_migrate_record_replaced
(
self
):
def
test_migrate_record_replaced
(
self
):
...
...
tests/migrations/test_migrations_clashing_prefix/__init__.py
0 → 100644
Dosyayı görüntüle @
8d4ab0c4
tests/migrations/test_migrations_clashing_prefix/a.py
0 → 100644
Dosyayı görüntüle @
8d4ab0c4
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
pass
tests/migrations/test_migrations_clashing_prefix/ab.py
0 → 100644
Dosyayı görüntüle @
8d4ab0c4
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[(
'migrations'
,
'a'
)]
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