mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Add tests for the migrate command and fix a bug they exposed
This commit is contained in:
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")
|
||||
Reference in New Issue
Block a user