diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2013-06-07 11:15:34 +0100 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2013-06-07 11:15:34 +0100 |
| commit | 3c296382b8dea5de7f4e1e11b66bd7cecaf2ee51 (patch) | |
| tree | 0ca12593be82971691ffca01a836d00d3fcb3bd4 /tests/commands_sql | |
| parent | 7609e0b42e0014a6ad0adf9dafc7018cb268070e (diff) | |
| parent | 357d62d9f2972bf1bc21e5835c12c849143e06af (diff) | |
Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
django/db/models/fields/related.py
Diffstat (limited to 'tests/commands_sql')
| -rw-r--r-- | tests/commands_sql/models.py | 6 | ||||
| -rw-r--r-- | tests/commands_sql/tests.py | 36 |
2 files changed, 25 insertions, 17 deletions
diff --git a/tests/commands_sql/models.py b/tests/commands_sql/models.py index 089aa96f30..d8f372b403 100644 --- a/tests/commands_sql/models.py +++ b/tests/commands_sql/models.py @@ -3,5 +3,11 @@ from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible +class Comment(models.Model): + pass + + +@python_2_unicode_compatible class Book(models.Model): title = models.CharField(max_length=100, db_index=True) + comments = models.ManyToManyField(Comment) diff --git a/tests/commands_sql/tests.py b/tests/commands_sql/tests.py index 831e9a27c4..e083d3977a 100644 --- a/tests/commands_sql/tests.py +++ b/tests/commands_sql/tests.py @@ -12,41 +12,43 @@ from django.utils import six class SQLCommandsTestCase(TestCase): """Tests for several functions in django/core/management/sql.py""" + def count_ddl(self, output, cmd): + return len([o for o in output if o.startswith(cmd)]) + def test_sql_create(self): app = models.get_app('commands_sql') output = sql_create(app, no_style(), connections[DEFAULT_DB_ALIAS]) + create_tables = [o for o in output if o.startswith('CREATE TABLE')] + self.assertEqual(len(create_tables), 3) # Lower so that Oracle's upper case tbl names wont break - sql = output[0].lower() + sql = create_tables[-1].lower() six.assertRegex(self, sql, r'^create table .commands_sql_book.*') def test_sql_delete(self): app = models.get_app('commands_sql') output = sql_delete(app, no_style(), connections[DEFAULT_DB_ALIAS]) - # Oracle produces DROP SEQUENCE and DROP TABLE for this command. - if connections[DEFAULT_DB_ALIAS].vendor == 'oracle': - sql = output[1].lower() - else: - sql = output[0].lower() - six.assertRegex(self, sql, r'^drop table .commands_sql_book.*') + drop_tables = [o for o in output if o.startswith('DROP TABLE')] + self.assertEqual(len(drop_tables), 3) + # Lower so that Oracle's upper case tbl names wont break + sql = drop_tables[-1].lower() + six.assertRegex(self, sql, r'^drop table .commands_sql_comment.*') def test_sql_indexes(self): app = models.get_app('commands_sql') output = sql_indexes(app, no_style(), connections[DEFAULT_DB_ALIAS]) - # PostgreSQL creates two indexes - self.assertIn(len(output), [1, 2]) - self.assertTrue(output[0].startswith("CREATE INDEX")) + # PostgreSQL creates one additional index for CharField + self.assertIn(self.count_ddl(output, 'CREATE INDEX'), [3, 4]) def test_sql_destroy_indexes(self): app = models.get_app('commands_sql') output = sql_destroy_indexes(app, no_style(), connections[DEFAULT_DB_ALIAS]) - # PostgreSQL creates two indexes - self.assertIn(len(output), [1, 2]) - self.assertTrue(output[0].startswith("DROP INDEX")) + # PostgreSQL creates one additional index for CharField + self.assertIn(self.count_ddl(output, 'DROP INDEX'), [3, 4]) def test_sql_all(self): app = models.get_app('commands_sql') output = sql_all(app, no_style(), connections[DEFAULT_DB_ALIAS]) - # PostgreSQL creates two indexes - self.assertIn(len(output), [2, 3]) - self.assertTrue(output[0].startswith('CREATE TABLE')) - self.assertTrue(output[1].startswith('CREATE INDEX')) + + self.assertEqual(self.count_ddl(output, 'CREATE TABLE'), 3) + # PostgreSQL creates one additional index for CharField + self.assertIn(self.count_ddl(output, 'CREATE INDEX'), [3, 4]) |
