From 5a3ae7e260f68602b25dbe3fc6ed13249a5c6515 Mon Sep 17 00:00:00 2001 From: Moayad Mardini Date: Tue, 10 Jun 2014 22:35:48 +0300 Subject: [PATCH] Created a new tests folder (`model_options`). And moved `tablespaces` option tests to it. The new folder can be used to test models/options, like the new option added in refs #22778. --- .../__init__.py | 0 tests/model_options/models/__init__.py | 0 .../models/tablespaces.py} | 8 ++--- .../test_tablespaces.py} | 30 ++++++++++--------- 4 files changed, 20 insertions(+), 18 deletions(-) rename tests/{tablespaces => model_options}/__init__.py (100%) create mode 100644 tests/model_options/models/__init__.py rename tests/{tablespaces/models.py => model_options/models/tablespaces.py} (88%) rename tests/{tablespaces/tests.py => model_options/test_tablespaces.py} (91%) diff --git a/tests/tablespaces/__init__.py b/tests/model_options/__init__.py similarity index 100% rename from tests/tablespaces/__init__.py rename to tests/model_options/__init__.py diff --git a/tests/model_options/models/__init__.py b/tests/model_options/models/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/tablespaces/models.py b/tests/model_options/models/tablespaces.py similarity index 88% rename from tests/tablespaces/models.py rename to tests/model_options/models/tablespaces.py index ecd1944294..56e22e973a 100644 --- a/tests/tablespaces/models.py +++ b/tests/model_options/models/tablespaces.py @@ -23,7 +23,7 @@ class Scientist(models.Model): name = models.CharField(max_length=50) class Meta: - db_table = 'tablespaces_scientistref' + db_table = 'model_options_scientistref' db_tablespace = 'tbl_tbsp' managed = False @@ -35,14 +35,14 @@ class Article(models.Model): reviewers = models.ManyToManyField(Scientist, related_name='articles_reviewed_set', db_tablespace='idx_tbsp') class Meta: - db_table = 'tablespaces_articleref' + db_table = 'model_options_articleref' db_tablespace = 'tbl_tbsp' managed = False # Also set the tables for automatically created models Authors = Article._meta.get_field('authors').rel.through -Authors._meta.db_table = 'tablespaces_articleref_authors' +Authors._meta.db_table = 'model_options_articleref_authors' Reviewers = Article._meta.get_field('reviewers').rel.through -Reviewers._meta.db_table = 'tablespaces_articleref_reviewers' +Reviewers._meta.db_table = 'model_options_articleref_reviewers' diff --git a/tests/tablespaces/tests.py b/tests/model_options/test_tablespaces.py similarity index 91% rename from tests/tablespaces/tests.py rename to tests/model_options/test_tablespaces.py index 8c69e70a19..ac331bd36c 100644 --- a/tests/tablespaces/tests.py +++ b/tests/model_options/test_tablespaces.py @@ -6,27 +6,29 @@ from django.db import connection from django.core.management.color import no_style from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature -from .models import Article, ArticleRef, Authors, Reviewers, Scientist, ScientistRef +from .models.tablespaces import (Article, ArticleRef, Authors, Reviewers, + Scientist, ScientistRef) + + +def sql_for_table(model): + return '\n'.join(connection.creation.sql_create_model(model, + no_style())[0]) + + +def sql_for_index(model): + return '\n'.join(connection.creation.sql_indexes_for_model(model, + no_style())) + # We can't test the DEFAULT_TABLESPACE and DEFAULT_INDEX_TABLESPACE settings # because they're evaluated when the model class is defined. As a consequence, # @override_settings doesn't work, and the tests depend - - -def sql_for_table(model): - return '\n'.join(connection.creation.sql_create_model(model, no_style())[0]) - - -def sql_for_index(model): - return '\n'.join(connection.creation.sql_indexes_for_model(model, no_style())) - - class TablespacesTests(TestCase): def setUp(self): # The unmanaged models need to be removed after the test in order to # prevent bad interactions with the flush operation in other tests. - self._old_models = apps.app_configs['tablespaces'].models.copy() + self._old_models = apps.app_configs['model_options'].models.copy() for model in Article, Authors, Reviewers, Scientist: model._meta.managed = True @@ -35,8 +37,8 @@ class TablespacesTests(TestCase): for model in Article, Authors, Reviewers, Scientist: model._meta.managed = False - apps.app_configs['tablespaces'].models = self._old_models - apps.all_models['tablespaces'] = self._old_models + apps.app_configs['model_options'].models = self._old_models + apps.all_models['model_options'] = self._old_models apps.clear_cache() def assertNumContains(self, haystack, needle, count):