1
0
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:
Andrew Godwin
2013-07-25 13:52:35 +01:00
parent 162f7b938f
commit 00276e0414
6 changed files with 84 additions and 37 deletions

View 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")