diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-09-14 20:26:16 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-12-23 19:35:01 +0100 |
| commit | 30cbd5d360a2b8becdef7c6a0c939e0633a5468e (patch) | |
| tree | 51501bc75cfac03eaef9676ba7139aabb08fb148 /tests | |
| parent | 15ba0d166ff714b231dcd4bebf0af32af964cae1 (diff) | |
Replaced DatabaseCreation sql methods by schema editor equivalents
Also used schema editor in migrate to sync unmigrated apps (sync_apps).
Refs #22340. Thanks Tim Graham for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/tests.py | 7 | ||||
| -rw-r--r-- | tests/commands_sql/tests.py | 10 | ||||
| -rw-r--r-- | tests/model_options/test_tablespaces.py | 9 |
3 files changed, 16 insertions, 10 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 5e2c447755..d25cde675a 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -111,9 +111,10 @@ class SQLiteTests(TestCase): Check that auto_increment fields are created with the AUTOINCREMENT keyword in order to be monotonically increasing. Refs #10164. """ - statements = connection.creation.sql_create_model(models.Square, - style=no_style()) - match = re.search('"id" ([^,]+),', statements[0][0]) + with connection.schema_editor(collect_sql=True) as editor: + editor.create_model(models.Square) + statements = editor.collected_sql + match = re.search('"id" ([^,]+),', statements[0]) self.assertIsNotNone(match) self.assertEqual('integer NOT NULL PRIMARY KEY AUTOINCREMENT', match.group(1), "Wrong SQL used to create an auto-increment " diff --git a/tests/commands_sql/tests.py b/tests/commands_sql/tests.py index e381c031a5..e1d4272616 100644 --- a/tests/commands_sql/tests.py +++ b/tests/commands_sql/tests.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import re import unittest +import warnings from django.apps import apps from django.core.management.color import no_style @@ -10,6 +11,7 @@ from django.core.management.sql import (sql_create, sql_delete, sql_indexes, from django.db import connections, DEFAULT_DB_ALIAS from django.test import TestCase, override_settings from django.utils import six +from django.utils.deprecation import RemovedInDjango20Warning # See also initial_sql_regress for 'custom_sql_for_model' tests @@ -67,7 +69,9 @@ class SQLCommandsTestCase(TestCase): def test_sql_indexes(self): app_config = apps.get_app_config('commands_sql') - output = sql_indexes(app_config, no_style(), connections[DEFAULT_DB_ALIAS]) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=RemovedInDjango20Warning) + output = sql_indexes(app_config, no_style(), connections[DEFAULT_DB_ALIAS]) # PostgreSQL creates one additional index for CharField self.assertIn(self.count_ddl(output, 'CREATE INDEX'), [3, 4]) @@ -79,7 +83,9 @@ class SQLCommandsTestCase(TestCase): def test_sql_all(self): app_config = apps.get_app_config('commands_sql') - output = sql_all(app_config, no_style(), connections[DEFAULT_DB_ALIAS]) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=RemovedInDjango20Warning) + output = sql_all(app_config, no_style(), connections[DEFAULT_DB_ALIAS]) self.assertEqual(self.count_ddl(output, 'CREATE TABLE'), 3) # PostgreSQL creates one additional index for CharField diff --git a/tests/model_options/test_tablespaces.py b/tests/model_options/test_tablespaces.py index ac331bd36c..515cd8a032 100644 --- a/tests/model_options/test_tablespaces.py +++ b/tests/model_options/test_tablespaces.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals from django.apps import apps from django.conf import settings from django.db import connection -from django.core.management.color import no_style from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from .models.tablespaces import (Article, ArticleRef, Authors, Reviewers, @@ -11,13 +10,13 @@ from .models.tablespaces import (Article, ArticleRef, Authors, Reviewers, def sql_for_table(model): - return '\n'.join(connection.creation.sql_create_model(model, - no_style())[0]) + with connection.schema_editor(collect_sql=True) as editor: + editor.create_model(model) + return editor.collected_sql[0] def sql_for_index(model): - return '\n'.join(connection.creation.sql_indexes_for_model(model, - no_style())) + return '\n'.join(connection.schema_editor()._model_indexes_sql(model)) # We can't test the DEFAULT_TABLESPACE and DEFAULT_INDEX_TABLESPACE settings |
