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.
This commit is contained in:
parent
68efbfde5e
commit
5a3ae7e260
|
@ -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'
|
|
@ -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):
|
Loading…
Reference in New Issue