Kaydet (Commit) 5a3ae7e2 authored tarafından Moayad Mardini's avatar Moayad Mardini Kaydeden (comit) Tim Graham

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.
üst 68efbfde
...@@ -23,7 +23,7 @@ class Scientist(models.Model): ...@@ -23,7 +23,7 @@ class Scientist(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
class Meta: class Meta:
db_table = 'tablespaces_scientistref' db_table = 'model_options_scientistref'
db_tablespace = 'tbl_tbsp' db_tablespace = 'tbl_tbsp'
managed = False managed = False
...@@ -35,14 +35,14 @@ class Article(models.Model): ...@@ -35,14 +35,14 @@ class Article(models.Model):
reviewers = models.ManyToManyField(Scientist, related_name='articles_reviewed_set', db_tablespace='idx_tbsp') reviewers = models.ManyToManyField(Scientist, related_name='articles_reviewed_set', db_tablespace='idx_tbsp')
class Meta: class Meta:
db_table = 'tablespaces_articleref' db_table = 'model_options_articleref'
db_tablespace = 'tbl_tbsp' db_tablespace = 'tbl_tbsp'
managed = False managed = False
# Also set the tables for automatically created models # Also set the tables for automatically created models
Authors = Article._meta.get_field('authors').rel.through 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 = 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 ...@@ -6,27 +6,29 @@ from django.db import connection
from django.core.management.color import no_style from django.core.management.color import no_style
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature 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)
# 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): def sql_for_table(model):
return '\n'.join(connection.creation.sql_create_model(model, no_style())[0]) return '\n'.join(connection.creation.sql_create_model(model,
no_style())[0])
def sql_for_index(model): def sql_for_index(model):
return '\n'.join(connection.creation.sql_indexes_for_model(model, no_style())) 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
class TablespacesTests(TestCase): class TablespacesTests(TestCase):
def setUp(self): def setUp(self):
# The unmanaged models need to be removed after the test in order to # The unmanaged models need to be removed after the test in order to
# prevent bad interactions with the flush operation in other tests. # 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: for model in Article, Authors, Reviewers, Scientist:
model._meta.managed = True model._meta.managed = True
...@@ -35,8 +37,8 @@ class TablespacesTests(TestCase): ...@@ -35,8 +37,8 @@ class TablespacesTests(TestCase):
for model in Article, Authors, Reviewers, Scientist: for model in Article, Authors, Reviewers, Scientist:
model._meta.managed = False model._meta.managed = False
apps.app_configs['tablespaces'].models = self._old_models apps.app_configs['model_options'].models = self._old_models
apps.all_models['tablespaces'] = self._old_models apps.all_models['model_options'] = self._old_models
apps.clear_cache() apps.clear_cache()
def assertNumContains(self, haystack, needle, count): def assertNumContains(self, haystack, needle, count):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment