mirror of
https://github.com/django/django.git
synced 2025-11-25 05:04:26 +00:00
Add tests for the migrate command and fix a bug they exposed
This commit is contained in:
parent
162f7b938f
commit
00276e0414
6 changed files with 84 additions and 37 deletions
37
tests/migrations/test_commands.py
Normal file
37
tests/migrations/test_commands.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from django.core.management import call_command
|
||||
from django.test.utils import override_settings
|
||||
from .test_base import MigrationTestBase
|
||||
|
||||
|
||||
class CommandTests(MigrationTestBase):
|
||||
"""
|
||||
Tests running the commands (migrate, makemigrations).
|
||||
"""
|
||||
|
||||
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
|
||||
def test_migrate(self):
|
||||
"""
|
||||
Tests basic usage of the migrate command.
|
||||
"""
|
||||
# Make sure no tables are created
|
||||
self.assertTableNotExists("migrations_author")
|
||||
self.assertTableNotExists("migrations_tribble")
|
||||
self.assertTableNotExists("migrations_book")
|
||||
# Run the migrations to 0001 only
|
||||
call_command("migrate", "migrations", "0001", verbosity=0)
|
||||
# Make sure the right tables exist
|
||||
self.assertTableExists("migrations_author")
|
||||
self.assertTableExists("migrations_tribble")
|
||||
self.assertTableNotExists("migrations_book")
|
||||
# Run migrations all the way
|
||||
call_command("migrate", verbosity=0)
|
||||
# Make sure the right tables exist
|
||||
self.assertTableExists("migrations_author")
|
||||
self.assertTableNotExists("migrations_tribble")
|
||||
self.assertTableExists("migrations_book")
|
||||
# Unmigrate everything
|
||||
call_command("migrate", "migrations", "zero", verbosity=0)
|
||||
# Make sure it's all gone
|
||||
self.assertTableNotExists("migrations_author")
|
||||
self.assertTableNotExists("migrations_tribble")
|
||||
self.assertTableNotExists("migrations_book")
|
||||
Loading…
Add table
Add a link
Reference in a new issue