1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #16905 -- Added extensible checks (nee validation) framework

This is the result of Christopher Medrela's 2013 Summer of Code project.

Thanks also to Preston Holmes, Tim Graham, Anssi Kääriäinen, Florian
Apolloner, and Alex Gaynor for review notes along the way.

Also: Fixes #8579, fixes #3055, fixes #19844.
This commit is contained in:
Russell Keith-Magee
2014-01-20 10:45:21 +08:00
parent 6e7bd0b63b
commit d818e0c9b2
101 changed files with 7058 additions and 1958 deletions

View File

@@ -7,7 +7,7 @@ import shutil
from django.apps import apps
from django.core.management import call_command, CommandError
from django.test import override_settings
from django.test import override_settings, override_system_checks
from django.utils import six
from django.utils._os import upath
from django.utils.encoding import force_text
@@ -21,6 +21,10 @@ class MigrateTests(MigrationTestBase):
Tests running the migrate command.
"""
# `auth` app is imported, but not installed in these tests (thanks to
# MigrationTestBase), so we need to exclude checks registered by this app.
@override_system_checks([])
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_migrate(self):
"""
@@ -49,6 +53,7 @@ class MigrateTests(MigrationTestBase):
self.assertTableNotExists("migrations_tribble")
self.assertTableNotExists("migrations_book")
@override_system_checks([])
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_migrate_list(self):
"""
@@ -71,6 +76,7 @@ class MigrateTests(MigrationTestBase):
# Cleanup by unmigrating everything
call_command("migrate", "migrations", "zero", verbosity=0)
@override_system_checks([])
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
def test_migrate_conflict_exit(self):
"""
@@ -79,6 +85,7 @@ class MigrateTests(MigrationTestBase):
with self.assertRaises(CommandError):
call_command("migrate", "migrations")
@override_system_checks([])
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
def test_makemigrations_conflict_exit(self):
"""
@@ -87,6 +94,7 @@ class MigrateTests(MigrationTestBase):
with self.assertRaises(CommandError):
call_command("makemigrations")
@override_system_checks([])
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
def test_makemigrations_merge_basic(self):
"""
@@ -99,6 +107,7 @@ class MigrateTests(MigrationTestBase):
except CommandError:
self.fail("Makemigrations errored in merge mode with conflicts")
@override_system_checks([])
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_sqlmigrate(self):
"""
@@ -150,6 +159,9 @@ class MakeMigrationsTests(MigrationTestBase):
return
shutil.rmtree(dname)
# `auth` app is imported, but not installed in this test (thanks to
# MigrationTestBase), so we need to exclude checks registered by this app.
@override_system_checks([])
def test_files_content(self):
self.assertTableNotExists("migrations_unicodemodel")
apps.register_model('migrations', UnicodeModel)
@@ -186,6 +198,9 @@ class MakeMigrationsTests(MigrationTestBase):
self.assertTrue('\\xda\\xd1\\xcd\\xa2\\xd3\\xd0\\xc9' in content) # title.verbose_name
self.assertTrue('\\u201c\\xd0j\\xe1\\xf1g\\xf3\\u201d' in content) # title.default
# `auth` app is imported, but not installed in this test (thanks to
# MigrationTestBase), so we need to exclude checks registered by this app.
@override_system_checks([])
def test_failing_migration(self):
#21280 - If a migration fails to serialize, it shouldn't generate an empty file.
apps.register_model('migrations', UnserializableModel)