mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Add tests for the migrate command and fix a bug they exposed
This commit is contained in:
@@ -1,48 +1,17 @@
|
||||
from django.test import TestCase
|
||||
from django.db import connection, models, migrations
|
||||
from django.db.transaction import atomic
|
||||
from django.db.utils import IntegrityError
|
||||
from django.db.migrations.state import ProjectState
|
||||
from .test_base import MigrationTestBase
|
||||
|
||||
|
||||
class OperationTests(TestCase):
|
||||
class OperationTests(MigrationTestBase):
|
||||
"""
|
||||
Tests running the operations and making sure they do what they say they do.
|
||||
Each test looks at their state changing, and then their database operation -
|
||||
both forwards and backwards.
|
||||
"""
|
||||
|
||||
def assertTableExists(self, table):
|
||||
self.assertIn(table, connection.introspection.get_table_list(connection.cursor()))
|
||||
|
||||
def assertTableNotExists(self, table):
|
||||
self.assertNotIn(table, connection.introspection.get_table_list(connection.cursor()))
|
||||
|
||||
def assertColumnExists(self, table, column):
|
||||
self.assertIn(column, [c.name for c in connection.introspection.get_table_description(connection.cursor(), table)])
|
||||
|
||||
def assertColumnNotExists(self, table, column):
|
||||
self.assertNotIn(column, [c.name for c in connection.introspection.get_table_description(connection.cursor(), table)])
|
||||
|
||||
def assertColumnNull(self, table, column):
|
||||
self.assertEqual([c.null_ok for c in connection.introspection.get_table_description(connection.cursor(), table) if c.name == column][0], True)
|
||||
|
||||
def assertColumnNotNull(self, table, column):
|
||||
self.assertEqual([c.null_ok for c in connection.introspection.get_table_description(connection.cursor(), table) if c.name == column][0], False)
|
||||
|
||||
def assertIndexExists(self, table, columns, value=True):
|
||||
self.assertEqual(
|
||||
value,
|
||||
any(
|
||||
c["index"]
|
||||
for c in connection.introspection.get_constraints(connection.cursor(), table).values()
|
||||
if c['columns'] == list(columns)
|
||||
),
|
||||
)
|
||||
|
||||
def assertIndexNotExists(self, table, columns):
|
||||
return self.assertIndexExists(table, columns, False)
|
||||
|
||||
def set_up_test_model(self, app_label):
|
||||
"""
|
||||
Creates a test model state and database table.
|
||||
|
||||
Reference in New Issue
Block a user